Skip to content

Commit 271c53e

Browse files
BUG: fix Monte Carlo release blockers
Addresses the Monte Carlo fixes in #1209. Simplifies study seeds and checkpoint recovery, preserves stochastic configurations, and adds regression coverage and migration notes.
1 parent e752873 commit 271c53e

16 files changed

Lines changed: 602 additions & 753 deletions

‎CHANGELOG.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3030
<!-- These are the changes that were not released yet, please add them correctly.
3131
Attention: The newest changes should be on top -->
3232

33+
### Breaking changes
34+
35+
- New serial Monte Carlo studies use indices `0..n-1` instead of `1..n`, matching parallel studies. Legacy logs retain their existing numbering when extended. [#1187](https://github.com/RocketPy-Team/RocketPy/pull/1187)
36+
- Monte Carlo reseeds stochastic objects for every simulation in both execution modes. Pass a non-negative integer `random_seed` to reproduce a study; individual object seeds are overridden, and fixed-seed results from v1.13 change. New input rows record one integer `seed`, while output rows contain only the index and requested results. Metadata is excluded from statistical results and plots. [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
37+
3338
### Added
3439

40+
- ENH: Accept `random_seed` in `MonteCarlo.simulate_convergence`, including across batches. [#1198](https://github.com/RocketPy-Team/RocketPy/pull/1198) [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
3541
- ENH: Reproducible Monte Carlo seeding, and an append that continues the same study [#1187](https://github.com/RocketPy-Team/RocketPy/pull/1187) [#1053](https://github.com/RocketPy-Team/RocketPy/issues/1053) [#1075](https://github.com/RocketPy-Team/RocketPy/issues/1075)
3642
- ENH: 3-DOF single rail button flight phase (tip-off analysis), enabled with the opt-in `Flight(use_udot_rail2=True)`. Between the upper rail button leaving the rail and the lower one following it, the rocket pivots about the lower button under a solved constraint wrench instead of jumping straight to free 6-DOF flight. The window is reported as `between_rails_time`, `between_rails_velocity` and `tip_off_duration`, printed by `Flight.info()` and shaded in the attitude plots. Requires `simulation_mode="6 DOF"` and `equations_of_motion="standard"`. [#920](https://github.com/RocketPy-Team/RocketPy/pull/920)
3743
- ENH: Support fixed-time parachute deployment triggers [#1133](https://github.com/RocketPy-Team/RocketPy/pull/1133) [#437](https://github.com/RocketPy-Team/RocketPy/issues/437)
@@ -50,7 +56,7 @@ Attention: The newest changes should be on top -->
5056

5157
### Changed
5258

53-
- ENH: Number the simulations of a serial Monte Carlo run from zero, as the parallel path already did — the two used to name the same simulation `1, 2, 3` and `0, 1, 2`. The `index` field written into the inputs and outputs rows shifts by one for serial runs, so code reading indices off those files has to expect a run of `n` simulations to be numbered `0` to `n - 1`. An append onto a study written before this release is refused rather than continued, since its rows do not record which root drew them. [#1187](https://github.com/RocketPy-Team/RocketPy/pull/1187)
59+
- ENH: Number new serial and parallel Monte Carlo runs from zero. Legacy checkpoints retain their numbering when extended, with a warning that their original random draws cannot be reproduced. [#1187](https://github.com/RocketPy-Team/RocketPy/pull/1187) [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
5460
- ENH: Compute the rocket static margin lazily [#1135](https://github.com/RocketPy-Team/RocketPy/pull/1135) [#780](https://github.com/RocketPy-Team/RocketPy/issues/780)
5561
- DOC: Tighten the comments that came with the sampler seed groups [#1154](https://github.com/RocketPy-Team/RocketPy/pull/1154)
5662
- CI: make the Gemini PR reviewer actually review [#1140](https://github.com/RocketPy-Team/RocketPy/pull/1140)
@@ -61,6 +67,7 @@ Attention: The newest changes should be on top -->
6167

6268
### Fixed
6369

70+
- BUG: Keep checkpoint metadata out of Monte Carlo plots and statistics, recover missing simulation indices without repeating completed flights, and warn when appending v1.13 logs. Preserve explicit initial flight states and solid-motor grain bonding in stochastic models. [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
6471
- BUG: A `Flight` continued from another `Flight` object now records `t_initial`, so a rocket carrying sensors or controllers no longer raises `AttributeError` on that path. [#920](https://github.com/RocketPy-Team/RocketPy/pull/920)
6572
- BUG: Correct the gravity sign an `Accelerometer` applies when `consider_gravity=True`. The gravitational field was added to the inertial acceleration instead of subtracted from it, so the sensor reported the negative of the proper acceleration along the vertical: one at rest read -g rather than +g. Recorded accelerometer data taken with `consider_gravity=True` changes sign in that term. [#1175](https://github.com/RocketPy-Team/RocketPy/pull/1175)
6673
- BUG: Report a Monte Carlo worker that fails instead of hanging or passing for a finished run [#1182](https://github.com/RocketPy-Team/RocketPy/pull/1182)
@@ -84,7 +91,7 @@ Attention: The newest changes should be on top -->
8491
- BUG: Restore the UTC fallback without timezonefinder [#1143](https://github.com/RocketPy-Team/RocketPy/pull/1143)
8592
- BUG: Pick between the candidate values of a list input with the stochastic model's own seeded generator. `random.choice` was used, which draws from the interpreter-wide stream that `_set_stochastic` does not reseed, so a fixed seed did not reproduce the values chosen from a list, and Monte Carlo workers forked from one process walked a single shared stream instead of sampling independently. Fixed-seed baselines that vary a list input change. [#953](https://github.com/RocketPy-Team/RocketPy/issues/953)
8693
- BUG: Report the atmospheric model time period and ensemble member count for lower-case model types. `set_atmospheric_model` documents `type` as case-insensitive, but `Environment.info()` and `all_info()` compared against capitalised literals, so `type="ensemble"` printed no time period and no member count, and skipped the ensemble comparison plot. [#520](https://github.com/RocketPy-Team/RocketPy/issues/520)
87-
- BUG: Give each `CustomSampler` input its own deterministic stream, and seed samplers sharing one generator once as a group. Existing fixed-seed `CustomSampler` baselines change, and samplers built on the legacy `RandomState` must move to `default_rng` because seeds now carry the full 128 bits. [#1102](https://github.com/RocketPy-Team/RocketPy/pull/1102)
94+
- BUG: Give each `CustomSampler` input its own deterministic stream, and seed samplers sharing one generator once as a group. Reset callbacks receive a 32-bit integer compatible with both `RandomState` and `default_rng`; existing fixed-seed baselines change. [#1102](https://github.com/RocketPy-Team/RocketPy/pull/1102) [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
8895
- BUG: Accept the callable parachute triggers `StochasticParachute` documents, and reject the ones it cannot mean. An invalid string, an empty list or a boolean now fails during validation instead of reaching `Parachute` or becoming a one-metre height trigger. [#1103](https://github.com/RocketPy-Team/RocketPy/pull/1103)
8996
- BUG: Accept a deterministic aerodynamic surface in `StochasticRocket.add_nose`, `add_trapezoidal_fins`, `add_elliptical_fins` and `add_tail`. Each wrapped the surface with a `component=` keyword none of the stochastic classes accept, so passing anything other than an already-stochastic surface raised a `TypeError`. [#953](https://github.com/RocketPy-Team/RocketPy/issues/953)
9097
- BUG: rocket with a late-starting thrust curve never leaves the rail [#1085](https://github.com/RocketPy-Team/RocketPy/pull/1085)

‎docs/TODO.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Monte Carlo follow-ups
2+
3+
The v1.14 fixes tracked in [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
4+
retain the current worker orchestration. A pool rewrite and validation once per
5+
study remain deferred to v1.15, as agreed in the release review.

‎docs/user/stochastic.rst‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,9 @@ on equal values, and a specification with no spread always will.
316316
The reset is what builds the tree, not ``add_parachute`` or ``add_nose``. A
317317
rocket resets itself once while being constructed, when it has no components
318318
yet, so anything attached afterwards keeps the generator it was built with until
319-
something resets it again. A serial ``MonteCarlo`` run does not reset it at
320-
all. A parallel one tries to, once per worker, but hands the model a
321-
``SeedSequence`` where an integer is wanted, so that path does not get as far
322-
as building the tree either. Resetting per simulation, from an integer seed the
323-
caller chooses, is what the Monte Carlo seeding work adds.
319+
something resets it again. ``MonteCarlo`` resets the tree before every
320+
simulation in both serial and parallel runs, using the study seed and the
321+
simulation index to derive independent streams.
324322

325323
Each collection is spawned separately, so adding an aerodynamic surface does not
326324
move what the parachutes draw. Within a collection the stream follows insertion
@@ -348,10 +346,33 @@ draws under a fixed seed. The rocket's own inputs, such as ``mass`` and
348346
split over any number of workers, and whether it was reached first or last.
349347
A run of ``n`` simulations numbers them 0 to ``n - 1`` either way, which is
350348
what makes one index name one simulation.
351-
Every input row records the root it came from, so appending carries that
349+
Every input row records one integer ``seed``, so appending carries that
352350
study on whether or not the seed is given again, and a different one is
353-
refused rather than mixed in. Without a seed a run draws fresh entropy and
354-
reproduces nothing.
351+
refused rather than mixed in. Without a seed, a new run generates and prints
352+
one. Pass that integer as ``random_seed`` to reproduce the study. Seeds on
353+
individual stochastic models are overridden; a new study without
354+
``random_seed`` warns when these models have already been seeded.
355+
356+
``simulate_convergence(random_seed=...)`` uses the same study seed for every
357+
batch. Changing the batch size does not change the inputs of a given index.
358+
359+
Resuming a study
360+
----------------
361+
362+
Use ``simulate(number_of_simulations=100, append=True)`` to reach a total of
363+
100 simulations. A completed index is kept; missing indices below the target
364+
are simulated, including gaps left by interrupted parallel workers. Keep the
365+
input and output logs together: they are checked for matching indices and
366+
duplicate records before any new rows are written. The study's models must
367+
still describe the same rocket, flight and environment.
368+
369+
Logs from v1.13 have no study seed. Appending preserves their rows and emits a
370+
warning: the old random stream cannot be recovered. New rows record the reported
371+
seed. Existing one-based serial numbering is preserved; new studies start at
372+
zero. Checkpoint fields (``index``, ``seed`` and the earlier ``run_root`` field)
373+
are excluded from ``results``, summary statistics and plots.
374+
375+
.. note::
355376

356377
An index fixes the draw, not the object it is drawn around. Where the note
357378
above says a value follows its deterministic object, moving that object

0 commit comments

Comments
 (0)