Repository navigation
fix(optimizer): make backtest first actions causal - #891
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9e7a98100
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if decision_ms > start_ms: | ||
| exclusions["diagnostic after decision cutoff"] += 1 | ||
| continue |
There was a problem hiding this comment.
Select an action that can exist before the cutoff
For normal persisted diagnostics, this condition excludes essentially every record: buildSlots retains the slot containing the replan time, so the first slot has already started, while ComputedAtMs is the plan generation timestamp recorded during that replan. Consequently decision_ms is normally greater than slots[0].slot_start_ms; with --realized-csv, replay_records becomes empty and the report produces no horizon or first-action comparisons. To obtain a causal interval, select the matching future action from a diagnostic generated before that action's slot start rather than requiring the diagnostic's first action to satisfy this cutoff.
Useful? React with 👍 / 👎.
What
first_action_counterfactualWhy
The old report could use a plan produced after the measured bucket began and could add the same future hours many times. It also called planned battery power "realized" without command or measured delivery data.
This PR makes the remaining result narrow and explicit: it reprices independent first actions against measured exogenous interval averages. Its scope is
grid_boundary_energy_only; it is not delivered optimizer savings.Part of #885.
Tests
optimizer/.venv/bin/python -m pytest optimizer/tests/test_backtest.py -q— 11 passedmake verifymake verify-all, including linux/arm64, linux/amd64 and windows/amd64 buildsLimits
Each comparison starts from its persisted SoC. Closed-loop policy ranking still needs both policies rerun from the same propagated state, plus command results, measured battery delivery, wear and end-energy value.