Skip to content

MNT: v1.14.0 final review fixes - #1243

Merged
MateusStano merged 8 commits into
developfrom
mnt/v1.14-review-fixes
Nov 29, 2026
Merged

MateusStano merged 8 commits into
developfrom
mnt/v1.14-review-fixes

Conversation

@MateusStano

@MateusStano MateusStano commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Small fixes found in the final review of #1194, before v1.14.0. One commit per group.

Pull request type

  • Code changes (bugfix, features)
  • Code maintenance (refactoring, formatting, tests)
  • ReadMe, Docs and GitHub updates

Checklist

  • Tests for the changes have been added (if needed)
  • Docs have been reviewed and added / updated
  • Lint (ruff check, ruff format --check, pylint) has passed locally
  • The rocket, sensor and stochastic unit tests pass locally. The flight tests (tests/unit/simulation/test_udot_rail2_feature.py and the energy tests in tests/unit/simulation/test_flight.py) are left to CI.
  • CHANGELOG.md: not edited here; the line below goes in after the merge.

Changes

  1. Simpler sensor seed check. The SeedLike type alias, its two helpers and the type hints are replaced by one check that rejects random generator objects (Generator, BitGenerator, RandomState), which cannot be saved. NumPy itself rejects any other invalid seed; the tests match NumPy's message. Comments, the error message and the seed docstrings are shortened.
  2. Flight tip-off and energy code.
    • The out_of_rail_* docstrings now say "when the upper rail button leaves the rail"; the rocket is fully off the rail at tip_off_end_time.
    • Flight.attitude_unit is removed. It was public, undocumented and read in one place; udot_rail2 now computes the rail direction itself.
    • Flight._gravitational_potential_per_mass is removed. potential_energy integrates Environment.gravity with Function.integral; on a Calisto flight the values are identical. A test checks that a NaN altitude still gives a NaN potential energy, with array and callable gravity.
  3. One definition of a valid parachute trigger. The height check is inlined in Parachute, and StochasticParachute builds a Parachute for each trigger member instead of restating the rules, so a bad member is still reported when the model is created.
  4. Installation page. The required packages and their minimum versions match requirements.txt (Numpy 1.23, Scipy 1.8, Matplotlib 3.9, dill added).
  5. contextily on Python 3.14. rasterio, which contextily needs, now ships Python 3.14 wheels for Linux, macOS and Windows, so the python_version < '3.14' marker and the notebook note are removed. CI now also runs the background map tests on 3.14.

The removal of the Rocket.static_margin setter was reverted after review: the deprecated setter from #1225 stays for one more release.

Breaking change

  • No

Changelog lines for after the merge

  • Fixed: "Install contextily with the monte-carlo extra on Python 3.14 too, so the background map of the Monte Carlo plots is available there."

🤖 Generated with Claude Code

MateusStano and others added 6 commits November 28, 2026 20:14
The static margin is computed from the rocket, and assigning it was never
documented. Assigning it raises AttributeError again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the seed type alias, its two helpers and the type hints with one check
that rejects random generator objects, and shorten the comments, the error
message and the seed docstrings. NumPy rejects any other invalid seed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The out_of_rail_* docstrings say the upper rail button leaves the rail.
- Remove Flight.attitude_unit; udot_rail2 computes the rail direction.
- Remove _gravitational_potential_per_mass; potential_energy integrates
  Environment.gravity with Function.integral.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Inline the height trigger check in Parachute, and have StochasticParachute
build a Parachute for each trigger member instead of restating the rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rasterio, which contextily needs, now ships Python 3.14 wheels for Linux,
macOS and Windows, so the background map of the Monte Carlo plots no longer
needs to be skipped there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@MateusStano
MateusStano requested a review from a team as a code owner November 28, 2026 23:15
@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.03%. Comparing base (6f81394) to head (c9b99e9).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1243      +/-   ##
===========================================
- Coverage    87.04%   87.03%   -0.02%     
===========================================
  Files          130      130              
  Lines        18131    18096      -35     
===========================================
- Hits         15783    15750      -33     
+ Misses        2348     2346       -2     

☔ 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.

Comment thread rocketpy/rocket/rocket.py
"""
if self._static_margin_dirty:
self.evaluate_static_margin()
return self._static_margin

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Important: Removing the static_margin setter makes rocket.static_margin = ... raise AttributeError in 1.14.0, although it worked as a plain attribute in 1.13.0 and #1225 restored it (with a DeprecationWarning) for exactly that reason. CHANGELOG.md line 87 still says the assignment is accepted again, and no entry announces the removal. Fix: keep the deprecated setter for one more release, or, if the removal is intended, drop the #1225 line and add a breaking "Removed" entry.

Scenario: a script that does rocket.static_margin = Function(...) runs on 1.13.0 and fails on 1.14.0 with property 'static_margin' of 'Rocket' object has no setter, with no deprecation period.

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.

Agreed. Reverted in 86366b9: the deprecated setter from #1225 is back with its tests, so the assignment works with a DeprecationWarning and the changelog line stays as it is.

total_mass.set_discrete_based_on_model(self.z)
potential_per_mass = self._gravitational_potential_per_mass(self.z.y_array)
gravity = self.env.gravity
potential_per_mass = [gravity.integral(0, z) for z in self.z.y_array]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): potential_energy now calls Function.integral once per node in a Python loop, where the removed helper did one vectorized definite_integral call. With a callable env.gravity, every node runs its own scipy.integrate.quad, and the test docstring at tests/unit/simulation/test_flight.py line 694 still says that case works "without falling back to a per-node numerical quadrature", which is now false. Fix: keep the vectorized call for array-sourced gravity, and reword that docstring.

Scenario: a flight with a few thousand nodes and a callable env.gravity runs thousands of adaptive quadratures when potential_energy, total_energy or all_info() is first accessed (the simulation-safety guide asks for a justification for new Python loops).

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.

The cost is small: with the default gravity, which is always a table, 3000 nodes take 0.024 s, and 0.035 s with a callable. Kept the loop. The test docstring is reworded in 86366b9.

assert np.isnan(flight._gravitational_potential_per_mass(np.nan))


@pytest.mark.parametrize(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): The NaN-altitude test was deleted with the helper, so nothing now covers a NaN node in Flight.z. The old code returned NaN explicitly; the new code relies on Function.integral(0, nan), which has no NaN guard (np.sign(nan) is NaN, so neither early return fires). Fix: keep a small test with a NaN in z.y_array and, if the callable path does not return NaN, guard it in the loop.

Scenario: a diverged trajectory node is meant to show as a gap in potential_energy; with array gravity it still does, but for callable gravity the result depends on how quad treats a NaN limit, and a regression would go unnoticed (I did not run this, so treat the quad behavior as unchecked).

@MateusStano MateusStano Nov 29, 2026 •

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.

Added a test in c9b99e9: test_gravity_integral_is_nan_at_a_nan_altitude checks that integrating gravity up to a NaN altitude gives NaN, for array and callable gravity, which is what potential_energy does at each node. A test on potential_energy itself is not possible: a NaN in z makes the product with the mass raise ValueError ("array must not contain infs or NaNs") when its spline is fitted. That was already the case on develop, so the gap the old helper produced never reached potential_energy.

--------
TODO link to documentation on noise model
"""
if isinstance(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): Seed validation is now left to NumPy, so a bad seed fails with a message that does not name seed, and with different exception types: a nested list raises TypeError ("SeedSequence does not accept nested sequences."), a 2-D integer array raises ValueError ("all the input arrays must have same number of dimensions..."). The test for those two cases was deleted, so the behavior is now unspecified and follows the installed NumPy. Fix: restore a small flat-int check that raises one TypeError naming seed, or keep a test that pins NumPy's behavior.

Scenario: Barometer(sampling_rate=1, seed=np.array([[1, 2], [3, 4]])) raises a ValueError from inside default_rng, which a caller catching TypeError for a bad seed will miss.

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.

Leaving this to NumPy on purpose: keeping our own seed validation is what this change removed. The tests now match NumPy's message (see the next comment).

with pytest.raises(TypeError, match="seed"):
def test_non_integer_seeds_are_rejected(seed):
"""NumPy refuses a seed that is not made of integers."""
with pytest.raises(TypeError):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): Dropping match="seed" lets any TypeError raised while building the Barometer satisfy these tests, not only the one from the seed (same for test_float_ndarray_seed_is_rejected below). Fix: match NumPy's text instead, e.g. match="SeedSequence|integer", which covers the str, float, numpy bool, object and float-array cases here.

Scenario: an unrelated TypeError introduced in sensor construction would keep all of these green.

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.

Done in 86366b9: both tests use match="SeedSequence|integer". I checked that every seed they cover raises one of those two messages.

- Matrix([[shift, 0, 0], [0, shift, 0], [0, 0, 0]])
).inverse

# Unit vector along the rail, in the inertial frame

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): udot_rail2 rebuilds the rail unit vector (four trig calls and a Vector) on every derivative call, although inclination and heading are fixed for the flight, and the same formula now also lives in the test helper _rail_direction. The cost is small next to u_dot_generalized, but the two copies can drift. Fix: compute it once (a private method or cached property) and have the tests call that.

Scenario: a sign or axis change in one copy of the formula is not caught if the other copy is not changed too.

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.

Keeping it: the cost is small, as you say, and it avoids a cached attribute that is read in one place. The test helper is only there to check the result.

# otherwise make ("time", "3.0") work by accident.
if not _is_a_height_trigger(trigger[1]):
# A number, as for a height. A string delay is refused, not converted.
if not isinstance(trigger[1], Real) or isinstance(trigger[1], bool):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): The numeric test is now written twice with opposite polarity (isinstance(x, Real) and not isinstance(x, bool) for the height, its negation here for the delay) after the shared helper was removed; the helper's docstring said the two forms had already drifted apart once. Fix: keep a one-line private helper, or reuse one expression for both branches.

Scenario: someone widens one site (for example to accept another numeric type) and ("time", x) and a bare height disagree again.

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.

Keeping the inline checks: two one-line expressions are easier to follow than a helper, and the trigger rules now live in Parachute only.

# member, so a bad one would otherwise fail only when it is drawn.
for member in trigger:
try:
Parachute(self.parachute.name, 1.0, member, 100)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): _validate_trigger builds a throwaway Parachute per member with unnamed probe values (1.0, 100) and joins two messages, so the user reads "trigger must be a non-empty list whose members are callables, ... ('time', t_deploy). Unable to set the trigger function for parachute 'main'. Trigger must be a callable, ..." Fix: name the probe values, and raise either Parachute's message or the short one, not both.

Scenario: StochasticParachute(parachute, trigger=[("burnout", 3.0)]) prints the two overlapping messages back to back.

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.

Keeping both messages for now: the first says what a trigger member may be, the second which parachute and which member failed.

Comment thread pyproject.toml
"statsmodels",
"prettytable",
"contextily>=1.0.0; python_version < '3.14'",
"contextily>=1.0.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit (optional): Dropping the python_version < '3.14' marker turns the background map on for Python 3.14, but CHANGELOG.md has no entry for it. I checked that rasterio ships cp314 wheels and that CI already runs 3.14, so no packaging change is needed. Fix: add a changelog line for the 3.14 support of contextily.

Scenario: users on 3.14 who read the old notebook note (now removed) or the changelog have no record of when the feature became available.

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.

Yes, the line is in the PR description under "Changelog lines for after the merge". It goes into CHANGELOG.md after the merge.

MateusStano and others added 2 commits November 29, 2026 16:43
Put back the deprecated Rocket.static_margin setter from #1225, so the
assignment keeps working with a DeprecationWarning for one more release.
Reword the callable-gravity potential energy test, add a NaN altitude test
for potential_energy, and match NumPy's message in the sensor seed tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous test built potential_energy from a NaN altitude, which raises
in the mass product on develop as well. Test the per-node integral that
potential_energy relies on instead, for array and callable gravity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@MateusStano
MateusStano merged commit 4009778 into develop Nov 29, 2026
9 checks passed
@MateusStano
MateusStano deleted the mnt/v1.14-review-fixes branch November 29, 2026 20:35
@MateusStano MateusStano mentioned this pull request Nov 29, 2026
2 tasks done
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.

2 participants