You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 78d8297
Browse filesBrowse the repository at this point in the historyBrowse files
Add global option to skip households on simulation failure (#1023)
* skip hh in simple simulate
* retain `household_id` by default in the drop_unused_columns()
we need it for debug tracing and skipping failed hh
* skip choice for interaction sample simulate
* don't log hh id when bad choice df is empy
* add hh id to user specified `chooser_columns` when `chooser_columns` exist
* blacken
* update test utils to probs raises
* [skip ci] shadow price calc without failed choices
* [skip ci] special case in trip mode choice
* [skip ci] adjust sample_rate
* [skip ci] add final logging of num hh skipped
* unit test
* update CI
* track and summarize failed households by component
* `skipped_household_ids` is now a dictionary
* print more loggings about trips missing modes
* adjust trip expansion factor using hh weight instead of count
* update state tables only when new households are skipped
* put a limit on num of households allowed to skip
* auto debug tracing newly failed choice
* update test
* Add documentation to user guide
* update doc
* increase sample rate decimals
* handle zero `sample_rate` when calculating weights
* black
* [skip ci] confirm trace files are generated for skipped hh
* Revert "increase sample rate decimals"
This reverts commit a734c16.
* add note for not rounding sample rate
* write trip matrices even when `sample_rate` is all zero
To pass this single hh test: https://github.com/ActivitySim/activitysim/actions/runs/23202170408/job/67427319813?pr=1023
# This block adjusts household sample rate column to account for skipped households.
94
+
# Note: the `HH_EXPANSION_WEIGHT_COL` is pointing to the `sample_rate` column in the households table.
95
+
# Based on the calculation in write_matrices() function, the sample_rate is used to calculate the expansion weight as 1 / sample_rate.
96
+
# A sample_rate of 0.01 means the sample household should be expanded 1/0.01 = 100 times in the actual population households.
97
+
# In simulation, the `sample_rate` is calculated and added to the synthetic households
98
+
# based on household_sample_size / total_household_count, and therefore is the same for all households.
99
+
# In estimation, the `sample_rate` may vary by household, but weights are not used in estimation, and write_trip_matrices is not called during estimation.
100
+
# But we still try to cover both cases (when rates are the same vs when they vary) here for consistency.
# Check if there are households with zero `sample_rate`, which will result in inf expansion weight.
106
+
# If all households have zero `sample_rate`, then all trips will have inf expansion weight, we will use household count instead of weight for adjustment factor calculation
107
+
# If some households have zero `sample_rate`, we will print a warning and skip trips from those households in the trip matrix generation.
108
+
ifzero_household_sample_rate.all():
109
+
logger.warning(
110
+
f"All households have {hh_weight_col} of 0, which will result in inf expansion weight. "
111
+
f"Trip matrix generation will be based on household count instead of weight."
112
+
)
113
+
elifzero_household_sample_rate.any():
114
+
logger.warning(
115
+
f"Some households have {hh_weight_col} of 0, which will result in inf expansion weight. "
116
+
f"Trips from those households will be skipped in trip matrix generation."
117
+
)
118
+
trips_df=trips_df[trips_df[hh_weight_col] !=0]
119
+
# skip trip matrix generation if there are no trips left after filtering out zero sample_rate households
120
+
iftrips_df.empty:
121
+
logger.warning(
122
+
f"All trips have {hh_weight_col} of 0, which will result in inf expansion weight. "
123
+
f"Trip matrix generation will be skipped."
124
+
)
125
+
return
126
+
127
+
ifstate.get("num_skipped_households", 0) >0:
128
+
logger.info(
129
+
f"Adjusting household sample rate in {hh_weight_col} to account for {state.get('num_skipped_households', 0)} skipped households."
0 commit comments