Trace Schema Reference¶
Purpose¶
The exported trace is not just a debug log. It is the structured contract between Python and Lean.
Python writes it. Lean parses it and verifies it.
If the schema drifts, verification will fail.
Current Version¶
The current schema version is:
traceVersion = 3
The Lean verifier rejects mismatched versions.
Top-Level Shape¶
An EpisodeTrace contains:
traceVersionparamsinitialStatesteps
params¶
Current fields:
batteryCapacitychargeLimitdischargeLimitgridLimitdegradationPenalty
initialState¶
Current fields:
soc
Per-Step Shape¶
Each step contains:
statesignalproposedActionappliedActioninterventionReasonsinterventionContextnextState
state and nextState¶
Current fields:
soc
nextState must match the transition produced from appliedAction, not proposedAction.
signal¶
Current fields:
solarloadbuyPricesellPrice
All current signal values are expected to be non-negative.
proposedAction¶
Current fields:
batteryDelta
This is what the agent wanted to execute.
appliedAction¶
Current fields:
batteryDelta
This is what actually reached the environment after shield filtering.
If the proposed action was already valid, Lean expects proposedAction and appliedAction to match.
interventionReasons¶
This is a list of reason categories for why the shield intervened or why the action was already acceptable.
Current reason labels:
already_validcharge_limitdischarge_limitbattery_boundsgrid_limitunknown_invalid_action
interventionContext¶
This captures the numeric context for the proposed action.
Current fields:
proposedBatteryDeltaproposedNextSocproposedNetGridchargeLimitdischargeLimitbatteryCapacitygridLimitsocLowerMarginsocUpperMargingridLowerMargingridUpperMargin
Margin Semantics¶
The margin fields are signed distances to limits.
Examples:
socLowerMargin < 0means the proposed next SoC would fall below zerosocUpperMargin < 0means the proposed next SoC would exceed battery capacitygridUpperMargin < 0means the proposed net grid exchange would exceed the upper grid boundgridLowerMargin < 0means the proposed net grid exchange would exceed the lower grid bound
Negative margins are expected when the proposed action is invalid.
What Lean Verifies¶
The Lean verifier checks:
- the trace version matches the supported schema
- parameters are valid
- the initial state is valid
- each recorded state matches the expected running state
- each signal is valid
- the shield audit is consistent
- intervention reasons match the proposed action
- intervention context matches the proposed action
nextStatematches the applied transition
Compatibility Rules¶
If you change any trace field names or meanings:
- update
vpp_rl/model.py - update
VppLeanRl/Trace.lean - update any related shield logic in
VppLeanRl/Shield.lean - update the tests in
tests/test_vpp.py
Do not change one side only.
Relevant Files¶
vpp_rl/model.pyvpp_rl/env.pyvpp_rl/shield.pyVppLeanRl/Trace.leanVppLeanRl/Shield.leantests/test_vpp.py