Fix: simulation result does not get saved#166
Draft
Dhiyaahaq33 wants to merge 1 commit into
Draft
Conversation
_save_calculation_results wrote asset_record, unrealized_changes, scribbles, and account_state, but never virtual_state.pickle, despite a comment claiming it was intentionally skipped. _load_or_create_previous_state unconditionally tries to read all five pickle files inside one try block, so the missing virtual_state file raised FileNotFoundError on every subsequent run, which discarded the other four successfully-saved pieces of state too and reset the calculation to start from scratch. Fixes cunarist#146 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJ386AEgV8Z796N4TSJtPn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SimulationCalculator._save_calculation_resultswrote 4 of the 5 state pickles (asset_record,unrealized_changes,scribbles,account_state) but nevervirtual_state.pickle, despite a comment claiming this was intentional._load_or_create_previous_stateunconditionally tries to read all 5 pickle files inside a singletryblock. Sincevirtual_state.picklenever existed, every load raisedFileNotFoundError, which was caught and treated as "no previous state" — discarding the other 4 correctly-saved pieces of state too and resettingcalculate_fromback to the start of the year.virtual_stateis now threaded throughCalculationResult/_merge_calculation_resultsand written to disk in_save_calculation_results, restoring parity with_load_or_create_previous_state's expectations (and with the pre-refactor implementation, which did save it).Fixes #146
Test plan
ruff check package/solie/logic/simulation_calculator.pypassespython -m py_compileon the changed file passes🤖 Generated with Claude Code
https://claude.ai/code/session_01WJ386AEgV8Z796N4TSJtPn