Skip to content

Pin mir_history_ against rollback and load - #285

Merged
neuromechanist merged 3 commits into
devfrom
feature/issue-161-mir-history
Aug 23, 2026
Merged

neuromechanist merged 3 commits into
devfrom
feature/issue-161-mir-history

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Issue #161 asked for three things: a test that a keep_best rollback does not rewrite mir_history_, a test that a loaded model's mir_history_ comes back empty, and a docstring line on the one-update offset between mir_history_ and ll_history.

Investigation found the first two were already fully implemented and passing on dev (commit cec10fc), added by PR #213, whose commit message already noted "Folds in issue #161" (the issue stayed open because no closing keyword was used); #245 later fixed a waypoint assertion in the first test and added the offset notes while fixing a related waypoint-assertion bug, but issue #161 was never closed.

test_mir_history_survives_keep_best_restore (pamica/tests/torch_tests/test_ng_convergence.py) already uses the established rollback recipe (n_models=2, do_newton=True, newt_start=1, lrate=0.5, seed=0, use_min_dll=True, min_dll=1e-4, maxincs=2, shared with test_keep_best_restores_genuine_overshoot_under_min_dll_stop) with mir_step=1 added, forces a genuine restore, and asserts mir_history_ runs to the pre-restore final iteration with one entry per iteration (len(mir_history_) == final_it + 1), i.e. it is neither truncated nor rewritten.

test_mir_history_empty_after_save_load already fits with mir_step=3, round-trips through AMICA.save/AMICA.load, and asserts loaded.mir_history_ == []. I verified this against the code: AMICATorchNG.from_state_dict reconstructs via cls(device=device, **config) (i.e. __init__, which sets self.mir_history_ = []), and _load_params never touches mir_history_, so the empty-on-load contract is real, not incidental.

The docstring line existed on AMICA.mir_history_ (pamica/amica.py) and as an inline comment in AMICATorchNG.__init__ (pamica/torch_impl/core.py), both added by PR #213 (#245 later fixed a waypoint assertion and added the offset notes). It was missing from AMICATorchNG.fit's mir_step parameter docstring, the first place a reader passing mir_step would look, so I added it there.

What this PR actually changes

No test file changes — the two pin tests requested by #161 were already present and already pass.

Test plan

  • uv run pytest pamica/tests/torch_tests/test_ng_convergence.py -q --no-cov — 22 passed
  • uv run pytest -m "not slow" -n auto -q --no-cov — 412 passed, 25 skipped, 1 xfailed, 0 failed
  • uv run ruff check . / uv run ruff format --check . / uv run ty check — all clean, zero new diagnostics

Closes #161

Issue #161: the offset was already documented on AMICA.mir_history_
and in AMICATorchNG.__init__'s inline comment, but not on fit()'s
mir_step parameter, the first place a reader would look.
Both mir_history_ pin tests (keep_best rollback, save/load emptiness)
already existed from #245; this documents and closes the issue.
@neuromechanist
neuromechanist merged commit b5e78d6 into dev Aug 23, 2026
8 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-161-mir-history branch August 23, 2026 20:10
@neuromechanist neuromechanist mentioned this pull request Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test mir_history_ against the keep_best rollback and save/load

1 participant