Skip to content

BUG: fix Monte Carlo release blockers - #1213

Open
Gui-FernandesBR wants to merge 1 commit into
developfrom
fix/v1.14-monte-carlo
Open

Gui-FernandesBR wants to merge 1 commit into
developfrom
fix/v1.14-monte-carlo

Conversation

@Gui-FernandesBR

Copy link
Copy Markdown
Member

Fixes the Monte Carlo blockers in #1209: study seeds, checkpoint recovery, plots and stochastic configuration. Includes simulate_convergence(random_seed=...) proposed in #1198 and documents the breaking changes. Local regression and serial/parallel replay tests, Ruff, pylint and the Sphinx build pass. The worker-pool and validate-once rewrites remain deferred to v1.15.

Addresses the Monte Carlo fixes in #1209. Simplifies study seeds and checkpoint recovery, preserves stochastic configurations, and adds regression coverage and migration notes.
@Gui-FernandesBR
Gui-FernandesBR requested a review from a team as a code owner November 4, 2026 16:07
@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.90110% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.67%. Comparing base (be2e155) to head (ee9e1ff).

Files with missing lines Patch % Lines
rocketpy/stochastic/stochastic_flight.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1213   +/-   ##
========================================
  Coverage    91.66%   91.67%           
========================================
  Files          131      131           
  Lines        18240    18240           
========================================
+ Hits         16720    16721    +1     
+ Misses        1520     1519    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Gui-FernandesBR Gui-FernandesBR left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review notes on the Monte Carlo release fixes.

seed : int, optional
Seed for the random number generator.
"""
self._seed = seed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_set_stochastic is also called internally by MonteCarlo.__seed_this_simulation (with a per-simulation integer) and by StochasticRocket._set_stochastic(None) (which spawns integer seeds for every child component even when seed=None). Recording self._seed = seed here causes a subsequent mc.simulate(..., append=False) without random_seed to emit a false object seeds are ignored warning, and makes StochasticParachute.create_object() reuse a fixed pressure-noise seed after stochastic_rocket._set_stochastic(None). Track user-configured seeds separately from internal reseeds.

initial_solution = list(initial_solution.solution[-1])
self._validate_initial_solution(initial_solution)
self.initial_solution = initial_solution
self.terminate_on_apogee = terminate_on_apogee

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StochasticFlight(flight) drops flight.terminate_on_apogee when terminate_on_apogee is omitted (None), and create_object() / MonteCarlo.__run_single_simulation() also drop flight.use_udot_rail2. Both should be preserved from the nominal flight like max_time and time_overshoot.

Suggested change
self.terminate_on_apogee = terminate_on_apogee
self.terminate_on_apogee = (
flight.terminate_on_apogee
if terminate_on_apogee is None
else terminate_on_apogee
)

initial_solution = list(flight.solution[0])
elif isinstance(initial_solution, Flight):
initial_solution = list(initial_solution.solution[-1])
self._validate_initial_solution(initial_solution)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_validate_initial_solution checks isinstance(i, (int, float)), which rejects NumPy scalars (np.int64, np.float32) copied from flight.solution[0] and accepts bool. Validate elements with isinstance(i, Real) and not isinstance(i, (bool, np.bool_)).

Comment on lines +84 to +87
if terminate_on_apogee is not None and not isinstance(
terminate_on_apogee, bool
):
raise AssertionError("`terminate_on_apogee` must be a boolean")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combining the nested if put line 87 into the patch diff without a test, which is the 1 missed line reported by Codecov (83.33% patch coverage on this file). Either keep the original if lines untouched or add a unit test with an invalid terminate_on_apogee.

Comment on lines +2154 to +2158
strays = sorted(
held
- set(range(index_offset, len(found) + index_offset))
- set(previous_indices)
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When previous_indices holds indices above target (e.g. {0, 10} with target=2), len(found) grows with len(previous_indices), so range(index_offset, len(found) + index_offset) hides stray indices between target and len(found).

Suggested change
strays = sorted(
held
- set(range(index_offset, len(found) + index_offset))
- set(previous_indices)
)
upper = target if previous_indices else max(target, len(found))
strays = sorted(
held
- set(range(index_offset, upper + index_offset))
- set(previous_indices)
)

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.

1 participant