Skip to content

Commit 96bfbb3

Browse files
Merge pull request #1213 from RocketPy-Team/fix/v1.14-monte-carlo
BUG: fix Monte Carlo release blockers
2 parents 65b9838 + 8d28669 commit 96bfbb3

18 files changed

Lines changed: 1015 additions & 823 deletions

‎CHANGELOG.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Attention: The newest changes should be on top -->
3232

3333
### Added
3434

35+
- 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)
3536
- 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)
3637
- 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)
3738
- 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)
@@ -51,7 +52,7 @@ Attention: The newest changes should be on top -->
5152
### Changed
5253

5354
- BUG: Negate `com_to_cdm_function` and `nozzle_to_cdm` where `u_dot_generalized` reads them. Both are defined pointing at the center of dry mass and the derivation measures from it, so the moment arm they formed had the wrong sign. Every result out of the generalized equations of motion changes, so a study built on the old numbers will not reproduce. On the measured 2024 Defiance flight the apogee error against 9308.32 m AGL goes from 0.6928 % to 0.6483 %. [#1186](https://github.com/RocketPy-Team/RocketPy/issues/1186)
54-
- 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)
55+
- ENH: Number new Monte Carlo runs from zero in both execution modes, as the parallel path already did; serial runs used `1..n`, so their `index` shifts by one. Every simulation is now reseeded from one study `random_seed` (a non-negative integer), so individual object seeds are ignored and fixed-seed results from v1.13 change. New input and output rows record that `seed`, and an append refuses logs whose seeds disagree; metadata is kept out of results, statistics and plots. Legacy checkpoints keep their rows when extended, filling index 0 like any other hole, with a warning that their original draws cannot be reproduced. [#1187](https://github.com/RocketPy-Team/RocketPy/pull/1187) [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
5556
- 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)
5657
- DOC: Tighten the comments that came with the sampler seed groups [#1154](https://github.com/RocketPy-Team/RocketPy/pull/1154)
5758
- CI: make the Gemini PR reviewer actually review [#1140](https://github.com/RocketPy-Team/RocketPy/pull/1140)
@@ -62,6 +63,7 @@ Attention: The newest changes should be on top -->
6263

6364
### Fixed
6465

66+
- 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, `terminate_on_apogee` (warning when an inherited `True` stops every sampled flight at apogee) and solid-motor grain bonding in stochastic models. [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
6567
- 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)
6668
- 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)
6769
- 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)
@@ -85,7 +87,7 @@ Attention: The newest changes should be on top -->
8587
- BUG: Restore the UTC fallback without timezonefinder [#1143](https://github.com/RocketPy-Team/RocketPy/pull/1143)
8688
- 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)
8789
- 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)
88-
- 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)
90+
- BUG: Give each `CustomSampler` input its own deterministic stream, and seed samplers sharing one generator once as a group. Reset callbacks receive a 128-bit integer, retried with its low 32 bits when they raise `ValueError` as `RandomState` does; existing fixed-seed baselines change. [#1102](https://github.com/RocketPy-Team/RocketPy/pull/1102) [#1209](https://github.com/RocketPy-Team/RocketPy/issues/1209)
8991
- 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)
9092
- 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)
9193
- BUG: rocket with a late-starting thrust curve never leaves the rail [#1085](https://github.com/RocketPy-Team/RocketPy/pull/1085)

‎docs/user/stochastic.rst‎

Lines changed: 25 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,12 @@ 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 and output 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.
355355

356356
An index fixes the draw, not the object it is drawn around. Where the note
357357
above says a value follows its deterministic object, moving that object
@@ -360,6 +360,23 @@ draws under a fixed seed. The rocket's own inputs, such as ``mass`` and
360360
rather than from the generator it is handed sits outside all of this, as
361361
:ref:`custom_sampler` warns.
362362

363+
``simulate_convergence(random_seed=...)`` uses the same study seed for every
364+
batch. Changing the batch size does not change the inputs of a given index.
365+
366+
Resuming a study
367+
----------------
368+
369+
Use ``simulate(number_of_simulations=100, append=True)`` to reach a total of
370+
100 simulations. A completed index is kept; missing indices below the target
371+
are simulated, including gaps left by interrupted parallel workers. Keep the
372+
input and output logs together: they are checked for matching indices, matching
373+
seeds and duplicate records before any new rows are written. The study's models must
374+
still describe the same rocket, flight and environment.
375+
376+
Logs from v1.13 have no study seed. Appending preserves their rows and emits a
377+
warning: the old random stream cannot be recovered. New rows record the reported
378+
seed. Indices start at zero, so a one-based v1.13 serial log gains index 0. Checkpoint fields (``index`` and ``seed``) are excluded from ``results``, summary statistics and plots.
379+
363380
Conclusion
364381
----------
365382

‎rocketpy/simulation/flight.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ def __init__( # pylint: disable=too-many-arguments,too-many-statements
640640
self.rtol = rtol
641641
self.atol = atol or 6 * [1e-3] + 4 * [1e-6] + 3 * [1e-3]
642642
self.initial_solution = initial_solution
643+
# Kept apart: the attribute is filled in with the rail launch state.
644+
self._initial_solution_given = initial_solution is not None
643645
self.time_overshoot = time_overshoot
644646
self.terminate_on_apogee = terminate_on_apogee
645647
self.name = name

0 commit comments

Comments
 (0)