Skip to content

fix: lazy + crash-safe epoch formatting in eclipse-check debug log#215

Open
TobiasEdman wants to merge 1 commit into
aidotse:mainfrom
TobiasEdman:fix/lazy-eclipse-epoch-logging
Open

fix: lazy + crash-safe epoch formatting in eclipse-check debug log#215
TobiasEdman wants to merge 1 commit into
aidotse:mainfrom
TobiasEdman:fix/lazy-eclipse-epoch-logging

Conversation

@TobiasEdman

Copy link
Copy Markdown
Contributor

Problem

CentralBody.blocks_sun() formats the actor and epoch into an f-string on every timestep:

logger.debug(f"Checking whether {actor} is in eclipse at {t}.")

On some pykep builds — observed with conda-forge pykep 2.6.4 (osx-arm64, Python 3.11)str(pk.epoch) raises RuntimeError: bad lexical cast for epochs at exact minute boundaries:

>>> str(pykep.epoch(60.0 / 86400.0))
RuntimeError: bad lexical cast: source type value could not be interpreted as target
# 59.999999 s and 60.000001 s both format fine — only the exact boundary fails

Since any simulation with power devices calls the eclipse check each advance_time(), every such simulation crashes at its first minute boundary regardless of log level — the f-string evaluates eagerly even when no DEBUG handler is active.

Fix

  • Use logger.opt(lazy=True) with callables, so formatting only happens when a DEBUG record is actually emitted (also removes per-timestep string formatting from the hot path).
  • Format the epoch through a _safe_epoch_str() fallback (mjd2000 representation) so logging can never crash the simulation even at DEBUG level.

The underlying pykep formatting bug is being reported upstream separately; this change makes PASEOS robust against it either way.

Verification

  • paseos/tests/: 32 passed, 1 failure in thermal_model_test.py which fails identically on clean master (pre-existing, unrelated — numeric assertion).
  • Before the fix, power_test.py::test_power_charging crashed with the lexical-cast error on the affected pykep build; it passes after.
  • 90-minute two-shell scenario (300 km actor, power devices, 60 s steps) runs clean without workarounds.

Environment: macOS arm64, Python 3.11, conda-forge pykep 2.6.4, paseos master.

Co-authored with Claude (Anthropic) during a constellation-design study that uses PASEOS for power/eclipse validation.

blocks_sun() formatted the actor and epoch into an f-string on every
timestep, even when no DEBUG handler was active. On some pykep builds
(observed: conda-forge pykep 2.6.4, osx-arm64) str(pk.epoch) raises
RuntimeError (boost bad_lexical_cast) for epochs at exact minute
boundaries, e.g. str(pk.epoch(60.0 / 86400.0)) — which crashed every
simulation using power devices at the first minute boundary.

Use loguru's lazy opt so formatting only happens when DEBUG is
emitted, and format the epoch through a fallback helper so logging
can never crash the simulation even at DEBUG level.

Verified: paseos/tests 32 passed, 1 pre-existing failure
(thermal_model_test, fails identically on clean master).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant