Fix batch_run Data Collection to Ensure Accuracy and Capture All Steps#3109
Fix batch_run Data Collection to Ensure Accuracy and Capture All Steps#3109
Conversation
|
Performance benchmarks:
|
|
Can you ensure proper test code coverage? Also, any explanation for the performance change? |
ee4a6ea to
f63c4b5
Compare
f63c4b5 to
8a3e60d
Compare
|
The new code processes more data because it stops deleting "sub-steps" Old Implementation: The code used # Old Code
steps = list(range(0, model.steps, data_collection_period))If your model ran for 5 steps but collected data 3 times per step (15 total records), If the The new test results on old code :- |
|
Code coverage sits at less than 80%. Can you please ensure full coverage? You can click on codecov/patch to see which code paths are not yet covered by tests. |
a9af8a1 to
2522225
Compare
2522225 to
c765d88
Compare
|
Added tests to ensure 100% patch coverage |
|
Performance benchmarks:
|
Summary
This PR fixes a bug where
batch_runfailed to capture the final step of a simulation and incorrectly handled data in models with non-standard collection frequencies. It transitions theBatchRunnerfrom a "prediction-based" step calculation to an "observation-based" approach, ensuring 100% data integrity.Bug / Issue
Related Issue: Fixes #2514
When using
batch_run, theDataCollectorwould frequently miss the final step of the model. This was caused by the function_model_run_funcusing a hardcodedrange()based onmodel.steps - 1, which stopped the data extraction one step short of the actual final state.However #2514 wasn't clearly able to state the problem i.e, the previous implementation assumed a strict 1-to-1 relationship between model steps and data rows. This led to:
range()only generates one integer per step.batch_runwould try to fetch data for steps where none was collected, resulting in duplicated orNaNrows.Implementation
The logic in
_model_run_funchas been refactored to stop guessing the step indices and instead trust theDataCollector's recorded history.Key Changes:
range(0, model.steps, ...)with a direct lookup ofmodel.datacollector._collection_steps.Testing
range()only returned 6 rows for a 5-step TimeDilation run (Initial + 5 steps), losing nearly half the data(locally tested using TimeDilationModel in test_batch_run)len(results) == 11.Additional Notes
Performance vs. Accuracy Trade-off:
By moving away from
range(), we now handle the actual list of timestamps recorded by the model. While this ensures perfect accuracy for all model types (sparse, dilated, or standard), it introduces an overhead. So I think the point of debate is to decide whether this change is worth the performance tradeoffMRE