Skip to content

BUG: Prevent center-of-mass derivative spikes at ignition and burnout - #1214

Open
zakariyaghazzol wants to merge 4 commits into
RocketPy-Team:developfrom
zakariyaghazzol:tst/ignition-derivative-reproduction
Open

zakariyaghazzol wants to merge 4 commits into
RocketPy-Team:developfrom
zakariyaghazzol:tst/ignition-derivative-reproduction

Conversation

@zakariyaghazzol

@zakariyaghazzol zakariyaghazzol commented Nov 8, 2026 •

Copy link
Copy Markdown

Addresses #1185.

Current behavior

For a callable CM offset, taking a second difference across ignition or
burnout can produce an acceleration spike that grows as the difference
step gets smaller.

New behavior

Use the existing set_discrete(start, end, 1000, "linear", "constant")
inside evaluate_com_to_cdm_function. The range includes the motor burn
interval, available mass/position sample ranges, and declared tank-flux
intervals. This avoids freezing the offset while a tank continues flowing
after thrust ends.

The current diff changes one production method and adds no public methods.
The earlier derivative helpers and Motor APIs are no longer part of the
diff against develop. Their commits are kept in the branch history.

The public offset uses a 1,000-point uniform grid, so its .source and
.x_array can have different sample times from the inputs. Linear
interpolation gives zero second derivative between points. This removes
the divergence, but does not preserve the smooth curvature of the original
mass-fraction expression or model an impulse at a slope change.

Comparison

Native Windows 11, Python 3.14.3. Seven sequential runs per version after
warm-up, with rotating order and single-thread BLAS settings. All three
use develop b389b43c as common code; the previous-approach column uses
the production changes from 4e79d51c.

Inputs and solver settings match across versions:
rtol=1e-6, atol=1e-3, no maximum step-size limit, and termination at
apogee. Imports and result analysis are excluded from timing.

Apogee above ground, metres

Case Develop Previous PR approach This revision
Calisto solid fixture 3157.478 3157.144 3157.327
Hybrid fixture 4405.571 4405.545 4406.565
Delayed airborne ignition 6040.825 6041.273 6041.842
Defiance example 9248.589 9247.793 9249.184

Median setup plus flight time, milliseconds

This includes rocket/environment construction and the sampling cost, not
just the Flight calculation.

Case Develop Previous PR approach This revision
Calisto solid fixture 43.09 54.43 46.09
Hybrid fixture 59.94 71.72 54.20
Delayed airborne ignition 136.20 101.43 88.32
Defiance example 550.01 570.51 475.53

For the delayed-ignition fixture, a fixed airborne-state check at the
ignition instant gave vertical accelerations of -32525.592,
-9.847 and -9.843 m/s² respectively. At burnout they were
3807.149, -9.901 and -9.901 m/s². These are numerical
endpoint probes at the same state, not on-rail launch accelerations.

These are local measurements, not a guarantee of identical trajectories
or a speedup for every rocket. Sampling bounds matter when tank flow
extends beyond the burn interval.

Testing

On the published revision 428881df:

  • Broad native Windows unit/integration/acceptance run: 2,830 passed,
    66 skipped. Three rendering tests were separated from this run.
  • Selected slow solver, Monte Carlo and resimulation tests: 29 passed,
    2 skipped.
  • Doctests and changelog tests: 60 passed, 1 skipped.
  • Full Ruff, formatting and Pylint checks passed.
  • Three off-screen rendering tests failed at a VTK DLL import blocked by
    Windows Application Control. The same import fails on unchanged develop.
    Rendering coverage is not verified locally.

The tests include airborne ignition/burnout with near-equal tank/motor
times, bounds extending beyond burnout, empty/solid/liquid/hybrid motors,
and a common-time offset comparison retaining the existing 1 mm tolerance.
The roll-report test retains an exact-zero simulator check and allows
roundoff only in the interpolated report.

The new hosted checks require maintainer approval and have started zero
jobs. No hosted result is claimed for this revision yet.

@Gui-FernandesBR Gui-FernandesBR left a comment

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.

Two blocking points (a ValueError on near-equal knots and the Pylint step) and five smaller ones, each as an inline comment.

The three Pytest (*, 3.14) failures are test_set_elevation_open_elevation (Open-Elevation API), which this diff does not touch. The 3.10 jobs were still running when I checked.

Comment thread rocketpy/rocket/rocket.py Resolved
Comment thread rocketpy/rocket/rocket.py Resolved
Comment thread rocketpy/rocket/rocket.py Resolved
Comment thread rocketpy/simulation/flight.py Resolved
Comment thread rocketpy/rocket/rocket.py Resolved
Comment thread rocketpy/rocket/rocket.py Resolved
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.97980% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.00%. Comparing base (076cbe9) to head (4e79d51).

Files with missing lines Patch % Lines
rocketpy/rocket/rocket.py 97.22% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1214      +/-   ##
===========================================
+ Coverage    86.87%   87.00%   +0.13%     
===========================================
  Files          131      131              
  Lines        18326    18419      +93     
===========================================
+ Hits         15920    16026     +106     
+ Misses        2406     2393      -13     

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

@zakariyaghazzol

Copy link
Copy Markdown
Author

@Gui-FernandesBR, I went through your comments and pushed the revision. The offset paths use one helper now, motors report their own time knots, and the sampled Function interface is back. I also handled the near-equal boundaries and updated the description. The Windows and Linux tests passed locally. Could you approve the new CI run so we can check macOS?

@Gui-FernandesBR

Copy link
Copy Markdown
Member

@Gui-FernandesBR, I went through your comments and pushed the revision. The offset paths use one helper now, motors report their own time knots, and the sampled Function interface is back. I also handled the near-equal boundaries and updated the description. The Windows and Linux tests passed locally. Could you approve the new CI run so we can check macOS?

@zakariyaghazzol , could you kindly mark each comment as "resolved" please?

@zakariyaghazzol

Copy link
Copy Markdown
Author

@Gui-FernandesBR, I went through your comments and pushed the revision. The offset paths use one helper now, motors report their own time knots, and the sampled Function interface is back. I also handled the near-equal boundaries and updated the description. The Windows and Linux tests passed locally. Could you approve the new CI run so we can check macOS?

@zakariyaghazzol , could you kindly mark each comment as "resolved" please?

@Gui-FernandesBR Done

@MateusStano MateusStano left a comment

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.

Thank you for working on this! I think there's a much simpler fix here though.

We could just discretize com_to_cdm_function with:

self.com_to_cdm_function.set_discrete(start, end, 1000, "linear", "constant")

This should be inside evaluate_com_to_cdm_function.

These would be very few lines, and no new public methods. I believe it would not affect simulation results and might even make it faster... it would be nice to see some numbers though

Use the existing discretization method and include known mass and tank time ranges. See RocketPy-Team#1185.
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.

3 participants