From c6aa6d71c2364747c2c3eabcc178d3d2a1a2d168 Mon Sep 17 00:00:00 2001 From: Jeffrey Newman Date: Fri, 9 Aug 2024 10:10:01 -0500 Subject: [PATCH] Bugfix for trip scheduling choice (#884) * 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 --- .../abm/models/trip_scheduling_choice.py | 2 +- activitysim/core/simulate.py | 53 +++++++++++-------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/activitysim/abm/models/trip_scheduling_choice.py b/activitysim/abm/models/trip_scheduling_choice.py index 90c4d02c9..a8ac46168 100644 --- a/activitysim/abm/models/trip_scheduling_choice.py +++ b/activitysim/abm/models/trip_scheduling_choice.py @@ -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, diff --git a/activitysim/core/simulate.py b/activitysim/core/simulate.py index 3ad4c640a..fcffcf606 100644 --- a/activitysim/core/simulate.py +++ b/activitysim/core/simulate.py @@ -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)) @@ -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)