Skip to content

MNT: v1.14.0 final review fixes - #1243

Open
MateusStano wants to merge 6 commits into
developfrom
mnt/v1.14-review-fixes
Open

MateusStano wants to merge 6 commits into
developfrom
mnt/v1.14-review-fixes

Conversation

@MateusStano

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 (536). 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 two lines below go in after the merge.

Changes

  1. Rocket.static_margin can no longer be assigned. The deprecated setter added in BUG: accept static_margin assignment with a DeprecationWarning #1225 is removed, so assigning it raises AttributeError. The static margin is computed from the rocket, and assigning it was never documented.
  2. 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. Comments, the error message and the seed docstrings are shortened.
  3. 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.
  4. 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.
  5. Installation page. The required packages and their minimum versions match requirements.txt (Numpy 1.23, Scipy 1.8, Matplotlib 3.9, dill added).
  6. 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.

Breaking change

  • Yes: assigning Rocket.static_margin raises AttributeError (it raised a DeprecationWarning on develop, and was a plain attribute on v1.13.0).

Changelog lines for after the merge

  • Breaking changes: replace the static_margin line with "Rocket.static_margin can no longer be assigned; it is computed from the rocket's geometry, mass and surfaces."
  • 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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@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.02%. Comparing base (6f81394) to head (45f3508).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1243      +/-   ##
===========================================
- Coverage    87.04%   87.02%   -0.03%     
===========================================
  Files          130      130              
  Lines        18131    18089      -42     
===========================================
- Hits         15783    15742      -41     
+ Misses        2348     2347       -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.

Comment thread rocketpy/rocket/rocket.py
@@ -763,19 +763,6 @@ def static_margin(self):
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.

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

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

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

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.

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

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

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

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.

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