ENH: unstable rocket error#764
Conversation
d64217b to
37c5505
Compare
2931c30 to
7864590
Compare
37c5505 to
e48a442
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #764 +/- ##
===========================================
+ Coverage 76.42% 80.11% +3.69%
===========================================
Files 95 96 +1
Lines 11090 11359 +269
===========================================
+ Hits 8475 9100 +625
+ Misses 2615 2259 -356 ☔ View full report in Codecov by Sentry. |
|
|
||
|
|
||
| class UnstableRocketError(RocketPyException): | ||
| """Raised when the rocket jas negative static margin.""" |
| def __validate_rocket_static_margin(self): | ||
| """ | ||
| Avoids running a flight simulation if the rocket stability margin is | ||
| negative. This is a common mistake that can lead to unstable flights, | ||
| which usually runs indefinitely. | ||
| """ | ||
| if (s := self.rocket.static_margin(0)) < 0: | ||
| raise UnstableRocketError(s) | ||
|
|
There was a problem hiding this comment.
I think this error check might not be suitable right now. I see a few points as to why:
-
If a user wants to simulate an unstable rocket, for any reason, we should not make that impossible. There could always be a rocket that has a negative static margin, but the stability margin could quickly become positive with fuel burn or other effects
-
When in monte carlo simulations, what would happen if one of the iterations has an unstable rocket? Will all the simulations break because of it?
-
The generic aerodynamic coefficients don't calculate static margin correctly. This essentially means that all rockets with custom coefficients will have a negative static margin.
Maybe raising a warning is the best we can do?
There was a problem hiding this comment.
I agree with the first point you raised: not all rockets that are instantaneously unstable are necessarily unsimulatable.
A possible compromise would be either a warning or letting the user set a variable, such as ALLOW_UNSTABLE.
There was a problem hiding this comment.
I like the Idea of having a flag with default to false (so current API is respected).
Then we can simply turn It on for infinity
There was a problem hiding this comment.
Would ALLOW_UNSTABLE be by default True or False?
And if the default is False would that be a breaking change? Since someone who has a sim with an unstable rocket might start getting an error with this SM check
And if the default is True is it really helping the user that does not know about the negative static margin problem?
There was a problem hiding this comment.
Sorry, I meant default true
There was a problem hiding this comment.
Converting from an error to a warning is the easiest option right now.
However, I think we should better understand the cases where an unstable rocket can fly.
Perhaps the problem/bug happens inside the u_dot function (after rail exit) ?
If setting ALLOW_UNSTABLE to false, we should describe this behavior in the error message.
Setting ALLOW_UNSTABLE to true would not make much help.
There was a problem hiding this comment.
I think setting It to true by default mantains current behavior while allowing clients to deliberatively switch.
IMHO a simple warning would not be easy to consume for safe guarding purposes
There was a problem hiding this comment.
I understand.
My point is that maybe we should not keep the current behavior at all.
There was a problem hiding this comment.
I will think more about this during the week
05ba950 to
2793a62
Compare
…ons in Flight class
2793a62 to
04d2354
Compare
|
Gotta think a better way of solving this problem. |
…rface black/ruff reformat the multi-name exception imports in rocketpy/__init__.py and rocketpy/rocket/rocket.py. evaluate_center_of_pressure ignores GenericSurface lift coefficients, so the computed static margin does not reflect rockets that rely on them. Skip the UnstableRocketWarning in that case to avoid false positives, echoing the concern raised in the review of RocketPy-Team#764 that blocked a similar check.
…rface black/ruff reformat the multi-name exception imports in rocketpy/__init__.py and rocketpy/rocket/rocket.py. evaluate_center_of_pressure ignores GenericSurface lift coefficients, so the computed static margin does not reflect rockets that rely on them. Skip the UnstableRocketWarning in that case to avoid false positives, echoing the concern raised in the review of RocketPy-Team#764 that blocked a similar check.
* ENH: Add custom exceptions and unstable rocket warning (#285) Introduces a dedicated `rocketpy/exceptions.py` module with three new types: `InvalidParameterError` (bad radius/mass values), `InvalidInertiaError` (wrong inertia tuple length), and `UnstableRocketWarning` (negative static margin at ignition). Validation is applied in `Rocket.__init__` and a warning is issued automatically after `evaluate_static_margin` when the rocket is aerodynamically unstable. All three new names are exported from the top-level `rocketpy` package. Closes #285 * test: add coverage for Rocket input validation exceptions * MNT: fix lint formatting and skip UnstableRocketWarning for GenericSurface black/ruff reformat the multi-name exception imports in rocketpy/__init__.py and rocketpy/rocket/rocket.py. evaluate_center_of_pressure ignores GenericSurface lift coefficients, so the computed static margin does not reflect rockets that rely on them. Skip the UnstableRocketWarning in that case to avoid false positives, echoing the concern raised in the review of #764 that blocked a similar check. * DOC: add changelog entry for PR #970 --------- Co-authored-by: Gui-FernandesBR <guilherme_fernandes@usp.br>
Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyCHANGELOG.mdhas been updated (if relevant)Current behavior
A common mistake on rocketpy is to try running a flight simulation when the rocket is unstable.
The simulation will likely fail or never stops.
It is true that not always it will fail, but I believe we should be more restricted in order to avoid these case scenarios;
New behavior
UnstableRocketExceptioneverytime a flight is instantiated using a rocket with static margin lower than 0.Breaking change
Additional information
Future PRs should add more custom exceptions if needed.
In this PR: