Repository navigation
fix: reset the SMCABC budget, kernel and simulator on every call - #2128
Conversation
SMCABC kept simulation_counter, kernel_variance and the SASS simulator of earlier calls. A second call on the same object therefore skipped all populations after the initial one, as its budget was already used up, and kept applying the SASS transform of an earlier call, even with sass=False. Count simulations in a method instead of a closure, and reset the counter, the kernel variance and the simulator at the start of __call__.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2128 +/- ##
==========================================
- Coverage 91.30% 91.28% -0.03%
==========================================
Files 148 148
Lines 14970 14972 +2
==========================================
- Hits 13669 13667 -2
- Misses 1301 1305 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
@aniketpandey05 thanks for the PR! I will review it after November 9. Until then, please keep it concise, with as few changed lines as possible. Thanks, Jan |
The SASS wrapper repeated the simulation counting of _count_and_simulate; it now calls that method, so the budget is counted in one place. The reset comment is shortened to one line.
janfb
left a comment
There was a problem hiding this comment.
@aniketpandey05 good catch, and thanks for the clear numbers in the description! The fix looks good. I will just add a small commit on top as review capacity is limited at the moment:
- I changed the SASS simulator to reuse your new budget counter, so the simulations are counted in one place.
- I shortened the comment on the reset to one line.
- I merged
maininto the branch.
Thanks for fixing this, Jan
What does this PR do?
SMCABCkept state from earlier calls on the same object:simulation_counterwas set to 0 only in__init__. Asecond call started with the budget of the first already used up, so it ran the
initial population and then stopped, without a warning.
sass=True, the call replacedself._simulate_with_budgetby a simulator that applies the SASS transform, and nothing restored it. Later calls
kept that transform even with
sass=False, and a second SASS call ran its pilotsimulations through the old transform.
The budget counter is now a method instead of a closure built in
__init__, and__call__resets the counter, the kernel variance and the simulator before it starts.Does this close any issues?
No issue was opened, as this is a clear bug fix.
Anything else we should know?
Same object, same call twice (
num_particles=100,num_initial_pop=500,num_simulations=3000,epsilon_decay=0.5, simulatortheta + 0.05 * noise):main, call 1main, call 2On
main, the second call returns the initial rejection-ABC population.MCABCdoes nothave this problem, because it keeps its simulator local to the call.
The new test checks a behaviour: a second call on the same object returns exactly the
samples of a fresh object with the same seed, after a first call with and without SASS.
PR #2123 also edits the start of
SMCABC.__call__, so whichever of the two is mergedsecond will need a small rebase.
Checklist
pytest -m "not slow and not gpu" tests/abc_test.pypasses (32 passed). Fullsuite not run locally.
uv run pyright sbipasses. My local environment could not resolvetorchforpyright; relying on CI.
test_smcabc_second_call_matches_a_fresh_instance(with and without SASSin the first call). Both cases fail on
mainand pass here.I used Claude Code to find this bug