ActivitySim / activitysim

An Open Platform for Activity-Based Travel Modeling
https://activitysim.github.io
BSD 3-Clause "New" or "Revised" License
190 stars 99 forks source link

Disaggregate Accessibility Sampling #835

Open dhensle opened 6 months ago

dhensle commented 6 months ago

Describe the bug Disaggregate accessibility crashes due to no allowed MAZs.

This came up while SANDAG tried testing a new scenario with modified data. The crash happens here when we are attempting to sample candidate MAZs, and the reason the crash is happening is that the maz_candidate df is empty.

The process here is to first sample a TAZ and then pick an MAZ from it. Now the reason maz_candidate ends up being empty, despite the length check, appears to be the discrepancy between the taz_candidate df and the resulting taz_sample_idx, and the mazs that remain in the maz_candidates df after we filter it based on taz_sample_idx.

After we sample the maz indices, we remove those mazs from the maz_candiate df so we do not resample them. This process does not happen for the taz_candiate df (removing TAZs associated with those MAZs, which makes sense, since a TAZ might have multiple MAZ in it), but we end up with a case where we sample a TAZ at line 391 of the code (with the taz sample universe not reflecting the narrowing sample universe according to the mazs), and there is no MAZ remaining in the maz_candiate df associated with that TAZ, resulting in an empty maz_candidate df.

To Reproduce Reproducibility is hard here -- need to get (un)lucky in the sampling.

Expected behavior To fix, we can simply filter the taz_candiates so that it only contains TAZs associated with remaining maz_candidates. This way, we always make sure we have an MAZ list to sample from.

dhensle commented 6 months ago

Fix in the BayDAG work here solved the issue. PR #836 is the analogous commit back to ActivitySim main repo.