Skip to content

Commit

Permalink
Bugfix for trip scheduling choice (ActivitySim#884)
Browse files Browse the repository at this point in the history
* remove problem code for sharrow tracing

* do not allow zero probs in trip schedule choice

* remove problem code for sharrow load

---------

Co-authored-by: Sijia Wang <[email protected]>
  • Loading branch information
jpn-- and i-am-sijia authored Aug 9, 2024
1 parent 9181390 commit c6aa6d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion activitysim/abm/models/trip_scheduling_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def run_trip_scheduling_choice(
alternatives=schedules,
spec=spec,
choice_column=SCHEDULE_ID,
allow_zero_probs=True,
allow_zero_probs=False,
zero_prob_choice_val=-999,
log_alt_losers=False,
want_logsums=False,
Expand Down
53 changes: 30 additions & 23 deletions activitysim/core/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,19 +722,22 @@ def eval_utilities(
offsets = np.nonzero(list(trace_targets))[0]

# trace sharrow
if sh_flow is not None:
try:
data_sh = sh_flow.load(
sh_tree.replace_datasets(
df=choosers.iloc[offsets],
),
dtype=np.float32,
)
expression_values_sh = pd.DataFrame(data=data_sh.T, index=spec.index)
except ValueError:
expression_values_sh = None
else:
expression_values_sh = None
# TODO: This block of code is sometimes extremely slow or hangs for no apparent
# reason. It is temporarily disabled until the cause can be identified, so
# that most tracing can be still be done with sharrow enabled.
# if sh_flow is not None:
# try:
# data_sh = sh_flow.load(
# sh_tree.replace_datasets(
# df=choosers.iloc[offsets],
# ),
# dtype=np.float32,
# )
# expression_values_sh = pd.DataFrame(data=data_sh.T, index=spec.index)
# except ValueError:
# expression_values_sh = None
# else:
expression_values_sh = None

# get array of expression_values
# expression_values.shape = (len(spec), len(choosers))
Expand Down Expand Up @@ -806,16 +809,20 @@ def eval_utilities(
)
print(f"{sh_util.shape=}")
print(misses)
_sh_flow_load = sh_flow.load(sh_tree)
print("possible problematic expressions:")
for expr_n, expr in enumerate(exprs):
closeness = np.isclose(
_sh_flow_load[:, expr_n], expression_values[expr_n, :]
)
if not closeness.all():
print(
f" {closeness.sum()/closeness.size:05.1%} [{expr_n:03d}] {expr}"
)
# load sharrow flow
# TODO: This block of code is sometimes extremely slow or hangs for no apparent
# reason. It is temporarily disabled until the cause can be identified, so
# that model does not hang with sharrow enabled.
# _sh_flow_load = sh_flow.load(sh_tree)
# print("possible problematic expressions:")
# for expr_n, expr in enumerate(exprs):
# closeness = np.isclose(
# _sh_flow_load[:, expr_n], expression_values[expr_n, :]
# )
# if not closeness.all():
# print(
# f" {closeness.sum()/closeness.size:05.1%} [{expr_n:03d}] {expr}"
# )
raise
except TypeError as err:
print(err)
Expand Down

0 comments on commit c6aa6d7

Please sign in to comment.