-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2987: IndexError in batch_run with sparse data collection #2988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix #2987: IndexError in batch_run with sparse data collection #2988
Conversation
|
Performance benchmarks:
|
ee4f9b5 to
43b87aa
Compare
|
Hey, isn't it better to simply use |
|
@falloficarus22 Good point! But if data exists at steps [0, 5, 10] and we request step 3, wouldn't How would your approach handle different requested steps? |
Well I thought it was possible to do with Your pre-commit is failing (maybe you didn't |
e69551a to
dae37fe
Compare
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
I tried to resolve the conflicts with main, but failed. Tests are falling at the moment. Do you have time to investigate? |
Fixes #2987
This PR resolves an
IndexErrorthat occurs inbatch_run()when models use sparse data collection (collecting data only at specific steps rather than every step).Problem
The
_collect_data()function inbatchrunner.pyincorrectly used step numbers as list indices:When a model collects data sparsely (e.g., only at steps 0, 5, 10), the
model_varslist has only 3 items (indices 0, 1, 2). Attempting to accessvalues[5]orvalues[10]causes anIndexError.Solution
Changed the implementation to map step numbers to their corresponding collection indices:
Testing
Added
test_batch_run_sparse_collection()to verify the fix works with models that collect data every N steps.Test output:
Changes
mesa/batchrunner.py: Fixed the IndexError in_collect_data()tests/test_batch_run.py: Added regression test for sparse data collection