Add opt-in checkpointing to run_MC and run_GA#37
Open
jarinfrench wants to merge 5 commits into
Open
Conversation
Collaborator
Author
|
This depends on #35 |
Collaborator
Author
|
|
2cbd362 to
16f991f
Compare
Collaborator
Author
|
I'll work on getting things checked in actual runs, but this should be ready for review now. |
Collaborator
Author
Manual testing shows that this works. |
…inimizer Adds tests_mcminimizer.py (9 tests) covering: no-checkpoint baseline, completion cleanup, JSON and pickle checkpoint content, resume from both formats, corrupted checkpoint error, invalid format error, and checkpoint_interval behavior. Adds TestGeneticAlgorithmMinimizerCheckpointing (7 tests) to test_gaminimizer.py covering the same scenarios for run_GA, using a mock _save_checkpoint to simulate mid-run crashes. Closes IdahoLabResearch#36
5917fef to
05b6819
Compare
Collaborator
Author
05b6819 to
05042c2
Compare
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
GBOpt/Checkpoint.pywithCheckpointStore(null-object pattern —disabled()absorbs all calls so minimizer loops need noNoneguards),CandidateCheckpoint(per-candidate result cache for GA iterations, with.iter{N}.jsonsidecars), and shared constantsCHECKPOINT_SCHEMA_VERSIONandENERGY_PENALTY. Replaces the earlierGenerationCheckpoint.py.checkpoint_file,checkpoint_format("json"|"pickle", default"json"), andcheckpoint_interval(default1) keyword-only parameters toMonteCarloMinimizer.run_MCandGeneticAlgorithmMinimizer.run_GA. Omittingcheckpoint_filepreserves existing behavior exactly (no files written).checkpoint_fileexists on entry, the run resumes from the saved state. The checkpoint is kept on normal completion so runs can be extended by calling the method again with the same file.min_stepsparameter torun_MCto prevent early convergence before a user-specified floor is reached.run_GAwhereunique_idwas assigned before the checkpoint was loaded, making the resume branch unreachable..tmp→shutil.move). JSON checkpoints recursively convert numpy types andPathobjects for safe serialization; RNG state serializes cleanly as a plain dict in both formats. A standardized envelope schema (schema_version,minimizer,progress_unit,progress_index,best_energy,rng_state,run_params,state) is shared by both minimizers.GBMinimizerError,GBMinimizerTypeError, andGBMinimizerValueErrorexception classes following the module exception hierarchy used elsewhere in GBOpt.tests/test_checkpoint.py(21 tests coveringCheckpointStoreandCandidateCheckpoint),tests/test_mcminimizer.py(9 tests), and updatestests/test_gaminimizer.py. Removestests/test_generation_checkpoint.py.Test Plan
pytest tests/test_checkpoint.py tests/test_mcminimizer.py tests/test_gaminimizer.py -v— all new and updated tests passpytest -m 'not known_bug and not slow'— no regressions in existing suiteMonteCarloMinimizer.run_MC(max_steps=10, checkpoint_file="cp.json"), interrupt after a few steps, confirmcp.jsonexists with correctprogress_indexand nested state, re-run with samecheckpoint_fileand confirm the run resumes from where it stopped