fix: lazy + crash-safe epoch formatting in eclipse-check debug log#215
Open
TobiasEdman wants to merge 1 commit into
Open
fix: lazy + crash-safe epoch formatting in eclipse-check debug log#215TobiasEdman wants to merge 1 commit into
TobiasEdman 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.