fix: value stored energy against s_initial, not the first step's SOC - #129
Draft
andig wants to merge 1 commit into
Draft
fix: value stored energy against s_initial, not the first step's SOC#129andig wants to merge 1 commit into
andig wants to merge 1 commit into
Conversation
get_clean_objective_value subtracted s[i][0] from the final state of charge, but s[0] is the state after the first time step and already carries that step's charging (constraint at optimizer.py:555). The reported objective value was therefore short by the first step's net charge times p_a, while the objective the solver actually maximizes was unaffected. The distortion is not marginal: 15 of the 19 stored test cases move, by 0.01 % on 013 up to 154 % on 010, so any comparison of two strategies by their reported objective value could come out backwards. Case in point, a request where storing PV and exporting it are worth exactly the same reported 3.20 without a strategy and 2.80 with attenuate_feedin_peaks, suggesting the strategy costs 12.5 % where it is in fact economically neutral. The expectations of the affected test cases are updated by the exact amount the formula was off for the recorded schedule; no schedule changes. Co-Authored-By: Claude Opus 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
get_clean_objective_valuesubtractss[i][0]from the final state of charge:But
s[0]is the state after the first time step — it already carries that step's charging:So the reported
objective_valueis short by the first step's net charge ×p_a. The objective the solver maximizes usess[i][-1]outright and is unaffected, so no schedule changes — this is purely the reported number.Why it matters
15 of the 19 stored test cases move, from 0.01 % (013) to 154 % (010). Any comparison of two runs by reported objective value can come out backwards when they differ in what the battery does in the first step.
Concretely: constant 4 kW PV, no load, a battery whose stored energy is worth exactly what exporting pays (
p_a = p_E/η), so storing and exporting are an economic tie. Without a strategy the run reports 3.20; withattenuate_feedin_peaks, which stores everything, it reports 2.80 — a 12.5 % loss that does not exist.Change
bat.s_initialinstead ofs[0].Σ (s[0] − s_initial)·p_a. Nothing else in those files changes.tests/test_clean_objective.py, covering a charging and a discharging first step. Both fail against the old formula (-0.02vs0.36,-0.19vs-0.61) and pass with the fix.Verification
uvis not available on the machine this was written on and the CBC binary shipped with pulp is x86-64 with no Rosetta here, so the suite was run against HiGHS through a thin shim instead ofmake test. 18 of the 19 stored cases reproduce their updated objective value exactly. 013 differs by 0.06 % because HiGHS picks a different optimum among the ties in that case, which is unrelated to this change — with HiGHS's own schedule both the old and the new formula give the same value, since no battery charges in its first step there. Please confirm withmake teston CBC before merging.🤖 Generated with Claude Code