Automatically adds "simulation_day" to info_maps when added to OutputManager#2931
Automatically adds "simulation_day" to info_maps when added to OutputManager#2931
Conversation
8f3ca09 to
3860088
Compare
|
Current Coverage: % Mypy errors on add_infomap_simday branch: 1201 |
|
🚨 Please update the changelog. This PR cannot be merged until |
…omap_simday # Conflicts: # tests/test_output_manager.py
|
Current Coverage: % Mypy errors on add_infomap_simday branch: 1201 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: % Mypy errors on add_infomap_simday branch: 1196 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
I can't figure out why my tests are failing. I'm getting an error that "'NoneType' object has no attribute 'with_segments'", but I can't figure out what is causing it. pytest tests/test_output_manager.py
An example of one of the errors: @matthew7838, any thoughts? This feels like an issue mocking the OutputManager, but maybe it is a problem with the actual code. 🤷♂️ |
|
I was able to fix it with 875ea68 by mocking Now it seems like my failures are actually due to faulty tests - so I'll work on fixing those next. |
|
Current Coverage: % Mypy errors on add_infomap_simday branch: 1196 |
|
Current Coverage: 99% Mypy errors on add_infomap_simday branch: 1196 |
|
🚨 Flake8 linting errors were found. Please fix the linting issues. |
|
Current Coverage: 99% Mypy errors on add_infomap_simday branch: 1197 |
|
🚨 Flake8 linting errors were found. Please fix the linting issues. |
…uFaS into add_infomap_simday
|
Current Coverage: 99% Mypy errors on add_infomap_simday branch: 1197 |
|
🚨 Flake8 linting errors were found. Please fix the linting issues. |
ew3361zh
left a comment
There was a problem hiding this comment.
I think this looks good so far, I would want to test it out with some example filters to see the effect in action and make sure we're tracking potential side-effects of mutating the info_map like this. Maybe consider a separate small helper function to specifically mutate the info map (or create a copy) to be as transparent as possible with what's happening here?
Also curious if this is working to generate the outputs you're looking for?
| # add simulation day to input maps (needed for data padding to work) | ||
| needs_sim_day = overwrite_simulation_day or "simulation_day" not in info_map.keys() | ||
| if time_to_use is not None and needs_sim_day: | ||
| info_map["simulation_day"] = time_to_use.simulation_day |
There was a problem hiding this comment.
I think it would be helpful in the test section of the PR writeup to have some specific filters with variables you're looking at so we can see the intended effect in action.
There was a problem hiding this comment.
I've added this information to the write-up. The filter that I was targeting works now and the output is as expected, but it is probably too narrow for fully testing this functionality. So, I'm certainly open to some filter suggestions.
Could you elaborate on this a bit? I want to make sure I understand what you're going for. |
|
Current Coverage: 99% Mypy errors on add_infomap_simday branch: 1197 |
For sure! Right now, this version of
I think trying to simplify some of this where possible to keep this function focused on its main task would be helpful. We could do this by adding a function that takes one more more of these items and does them itself and returns the result to the With e.g. def _handle_info_map_sim_day(
self,
info_map: dict[str, Any],
overwrite_simulation_day: bool,
time: RufasTime | None = None,
) -> dict[str, Any]:
info_map_to_use = dict(info_map)
time_to_use = time if time is not None else self.time
should_set_simulation_day = overwrite_simulation_day or "simulation_day" not in info_map_to_use
if time_to_use is not None and should_set_simulation_day:
info_map_to_use["simulation_day"] = time_to_use.simulation_day
return info_map_to_use |


Because
simulation_dayis required for data padding (#2867, #2921) in theReportGenerator, automatically addsimulation_dayto everyinfo_mapwhen variables are added to theOutputManager(viaadd_variable()andadd_variable_bulk()) from the main simulation loop.Also allows for a manually provided time object to be used for recording
simulation_dayin this way, which allowsfor variables added outside of the simulation loop (e.g, herd initialization).
Context
Closes #2919
What
Test plan
two tests were added to test this feature:
test_add_variable_infomap_simulation_dayandtest_bulk_add_variable_infomap_simulation_day, which test that the info maps are updated properly within theOutputManager's pools.The testing filter file that I was originally targeting that led to this PR was:
{ "multiple": [ { "name": "FieldEvaluation", "filters": [ ".*RufasTime.*", ".*field=.*", ".*EmissionsEstimator.*" ], "expand_data": true } ] }In an ideal world, one would also be able to get all variables with padding (
".*"filter), but this is complicated by the herd initialization whose variables are created before the main simulation loop and, therefore, will not be properly aligned with the other variables after padding operations. In this case, then, a perfect filter would exclude all such variables. Or perhaps the data padder could updated to exclude any variables without thesimulation_dayinfo map value even if those values are included in the filter (i.e., compatibility with.*).Input Changes
No input changes.
Output Changes
Adds
simulation_dayto all info maps.