Repository navigation
MNT: v1.14.0 final review fixes - #1243
Conversation
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]>
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]>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
| """ | ||
| if self._static_margin_dirty: | ||
| self.evaluate_static_margin() | ||
| return self._static_margin |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Keeping both messages for now: the first says what a trigger member may be, the second which parachute and which member failed.
| "statsmodels", | ||
| "prettytable", | ||
| "contextily>=1.0.0; python_version < '3.14'", | ||
| "contextily>=1.0.0", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, the line is in the PR description under "Changelog lines for after the merge". It goes into CHANGELOG.md after the merge.
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]>
Small fixes found in the final review of #1194, before v1.14.0. One commit per group.
Pull request type
Checklist
ruff check,ruff format --check,pylint) has passed locallytests/unit/simulation/test_udot_rail2_feature.pyand the energy tests intests/unit/simulation/test_flight.py) are left to CI.CHANGELOG.md: not edited here; the line below goes in after the merge.Changes
SeedLiketype 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 theseeddocstrings are shortened.Flighttip-off and energy code.out_of_rail_*docstrings now say "when the upper rail button leaves the rail"; the rocket is fully off the rail attip_off_end_time.Flight.attitude_unitis removed. It was public, undocumented and read in one place;udot_rail2now computes the rail direction itself.Flight._gravitational_potential_per_massis removed.potential_energyintegratesEnvironment.gravitywithFunction.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.Parachute, andStochasticParachutebuilds aParachutefor each trigger member instead of restating the rules, so a bad member is still reported when the model is created.requirements.txt(Numpy 1.23, Scipy 1.8, Matplotlib 3.9,dilladded).contextilyon Python 3.14. rasterio, whichcontextilyneeds, now ships Python 3.14 wheels for Linux, macOS and Windows, so thepython_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_marginsetter was reverted after review: the deprecated setter from #1225 stays for one more release.Breaking change
Changelog lines for after the merge
contextilywith themonte-carloextra on Python 3.14 too, so the background map of the Monte Carlo plots is available there."🤖 Generated with Claude Code