Repository navigation
BUG: let a batch_size=1 convergence study reach a second result - #1233
umutKaracelebi wants to merge 2 commits into
Conversation
Gui-FernandesBR
left a comment
There was a problem hiding this comment.
The skip fixes #1229 through the issue's first option, and the new test fails without it (checked against develop). Inline: one behavior change to fix, plus a docstring and a test note.
simulate_convergence returned an empty history without a word when no batch left two results, so a caller could not tell a converged study from one that was never evaluated. max_simulations below 2 now raises ValueError next to the existing input checks, the Returns section says which batches contribute a width, and a unit test with ConvergenceMockMonteCarlo asserts the estimator is never called with a single observation.
|
All three review points are addressed in 3961883:
|
|
thanks @umutKaracelebi ! Good work! I will review @MateusStano 's review first, and then approve this one later |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1233 +/- ##
===========================================
+ Coverage 86.55% 86.67% +0.11%
===========================================
Files 131 131
Lines 18255 18277 +22
===========================================
+ Hits 15801 15841 +40
+ Misses 2454 2436 -18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Gui-FernandesBR
left a comment
There was a problem hiding this comment.
Two more points on the latest version: an early stop at two simulations and a missing boundary test.
| # scipy.stats.bootstrap needs two or more observations, so the first | ||
| # batch of a fresh study with batch_size=1 cannot be summarised yet. | ||
| # Keep simulating until the logs hold two rows. | ||
| if self.num_of_loaded_sims < 2: |
There was a problem hiding this comment.
With batch_size=1, the study can now stop as converged after only two simulations.
The first width is computed at n=2, and a bootstrap interval on two draws is roughly the gap between them. With tolerance=0.5, two flights whose apogee_time lands 0.3 s apart pass width <= tolerance at line 1061, and the loop returns after 2 flights. batch_size=2 already behaved like this, but this PR opens the same path for batch_size=1. Could the tolerance check wait for a minimum number of results (a small floor, separate from the bootstrap minimum of 2), or the docstring at least warn that small batches can stop this early?
|
|
||
| assert mc.simulate_calls == 4 | ||
| assert mc.estimate_calls == [2, 3, 4] # never a lone observation | ||
| assert len(history) == 3 |
There was a problem hiding this comment.
No test covers max_simulations=2, the smallest valid budget, so a regression of the check to <= 2 would not fail any test.
| assert len(history) == 3 | |
| assert len(history) == 3 | |
| def test_simulate_convergence_accepts_the_smallest_budget(): | |
| """max_simulations=2 is the smallest budget that yields one width.""" | |
| mc = ConvergenceMockMonteCarlo(width_model=lambda n: 10.0) | |
| history = mc.simulate_convergence( | |
| target_attribute="apogee_time", | |
| tolerance=0.5, | |
| max_simulations=2, | |
| batch_size=1, | |
| ) | |
| assert mc.simulate_calls == 2 | |
| assert mc.estimate_calls == [2] | |
| assert len(history) == 1 |
Fixes #1229
On a fresh study,
simulate_convergence(..., batch_size=1)ran one flight and then raisedValueError: each sample in 'data' must contain two or more observations along 'axis'.. The loop calledestimate_confidence_intervalright after that first batch, andscipy.stats.bootstrapcannot summarise a single observation.simulate_convergencenow skips the interval estimate while the logs hold fewer than two rows and keeps simulating, sobatch_size=1stays usable on a fresh study. Batches that already reach two or more results are untouched, and a study resumed from a one-row log still summarises its first batch, astest_convergence_reads_the_checkpoint_oncerequires.From review: a study that could never estimate an interval no longer returns
[]silently.max_simulations < 2is refused up front next to the other input checks, the Returns section says which batches contribute a width, and a unit test intests/unit/simulation/test_monte_carlo.pydrivesConvergenceMockMonteCarlowithbatch_size=1and asserts the estimator is never called with a single observation.Also:
test_convergence_with_a_batch_size_of_one_waits_for_a_second_resultintests/integration/simulation/test_monte_carlo_release.pyfails without the change with the sameValueErrorand passes with it.pytest tests -q: 2718 passed, 71 skipped.ruff check,ruff format --checkandpylint(10.00/10) are clean on the two edited files.🤖 Authored by an AI agent (Hermes Agent); no human review was involved.