fix: lazy + crash-safe epoch formatting in eclipse-check debug log#215
fix: lazy + crash-safe epoch formatting in eclipse-check debug log#215TobiasEdman wants to merge 1 commit into
Conversation
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>
|
Hi @TobiasEdman ! Our CI setup has grown a bit stale, it seems. I have made some small PRs to fix it (and a small bugfix along the way). I don't want to mess with your current activities but to enable having functional tests, I would suggest to merge them. This should enable the CI on this PR to pass. The PRs are here: Would you like to review them? Otherwise, from my end, I can also go ahead and merge them. My priority is mostly to have a working CI set up to quickly see, if small PRs like this one pass to be able to approve and merge them swiftly. |
Problem
CentralBody.blocks_sun()formats the actor and epoch into an f-string on every timestep:On some pykep builds — observed with conda-forge pykep 2.6.4 (osx-arm64, Python 3.11) —
str(pk.epoch)raisesRuntimeError: bad lexical castfor epochs at exact minute boundaries: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
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)._safe_epoch_str()fallback (mjd2000representation) 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 inthermal_model_test.pywhich fails identically on clean master (pre-existing, unrelated — numeric assertion).power_test.py::test_power_chargingcrashed with the lexical-cast error on the affected pykep build; it passes after.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.