Skip to content

Commit 44e188f

Browse files
MateusStanoclaude
andcommitted
BUG: match a 13-value atol to a phase's states by name
A phase integrating 13 states of its own took the Flight's per-state atol by position, since its length matched the phase's width. The quaternion's tight tolerances then landed on whatever states sat in those positions. Read a 13-value atol as one tolerance per canonical state first. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent dd0d9ed commit 44e188f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎rocketpy/simulation/helpers/dynamics.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ def select_atol(self, atol):
307307
-------
308308
float or list of float
309309
A single number is returned unchanged. A 13-value canonical vector is
310-
reduced to this phase's states (states that are not canonical use the
311-
largest supplied tolerance).
310+
matched to this phase's states by name (states that are not
311+
canonical use the largest supplied tolerance), even when the phase
312+
also integrates 13 states.
312313
313314
Raises
314315
------
@@ -319,14 +320,16 @@ def select_atol(self, atol):
319320
if not np.iterable(atol):
320321
return atol
321322
atol = list(atol)
322-
if self.is_canonical or len(atol) == self.width:
323+
if self.is_canonical:
323324
return atol
324325
if len(atol) == len(CANONICAL_STATE_NAMES):
325326
fallback = max(atol)
326327
return [
327328
atol[CANONICAL_INDEX[name]] if name in CANONICAL_INDEX else fallback
328329
for name in self.states
329330
]
331+
if len(atol) == self.width:
332+
return atol
330333
raise ValueError(
331334
f"atol vector has length {len(atol)}, which matches neither the "
332335
f"canonical state (13) nor this flight phase ({self.width})."

‎tests/unit/simulation/test_dynamics.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ def test_non_canonical_states_use_the_largest_atol():
277277
assert heading.select_atol(atol) == [1e-3] * 6 + [1e-2]
278278

279279

280+
def test_a_canonical_atol_is_matched_by_name_for_13_other_states():
281+
"""Thirteen states of its own do not take the canonical atol by position."""
282+
other = _PhaseDynamics("other", stub_derivative, [f"s{i}" for i in range(13)])
283+
atol = 6 * [1e-3] + 4 * [1e-6] + 3 * [1e-2]
284+
assert other.select_atol(atol) == [1e-2] * 13
285+
286+
280287
def test_bad_atol_length_raises():
281288
with pytest.raises(ValueError, match="matches neither"):
282289
TRANSLATION_DYNAMICS.select_atol([1e-3, 1e-3, 1e-3])

0 commit comments

Comments
 (0)