Repository navigation
Include the power of non-working components in pool bounds - #1477
Conversation
4b3c9c8 to
37ddd47
Compare
Tests start the streams before the code under test subscribes, so each stream's first sample was lost. The second sample then raced the test's fixed wait, and a 50 ms stall made the request arrive before any data. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Stopping a cache yields to the event loop, and a request being distributed meanwhile can change the dict, which raised a RuntimeError on shutdown. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
It measures the components of a set that aren't working with a power formula, and restarts the formula when that subset changes. Used in the following commits, by the power distributor and by the pools. A component that is controlled together with a working one, like a battery behind the inverter of a working battery, counts as working. A formula that can't be generated is logged once, and nothing is tracked until the subset changes, so callers don't fail on every update. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Each requested set now gets its own tracker, with its own formula pool. Before, one pool served every requested set, and a formula was only stopped once no set used it anymore. Nothing is tracked while none of the requested components is working, because the managers can't distribute power then. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The battery manager commands the inverters of the working batteries, so the other batteries behind those inverters aren't unreachable. It counted them as unreachable anyway. The component graph can't make a power formula for only some of the batteries behind an inverter, so the unreachable power of the whole request was left out. The subscription now runs after the request is checked, because the expansion needs valid battery IDs. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The test fixtures don't feed the unreachable-power formulas, so tests that need a measured power for components that aren't working patch the formula pool with this stub. Used in the following commits. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
37ddd47 to
f508179
Compare
Marenz
left a comment
There was a problem hiding this comment.
The fix is right, and the examples in the tests match what I get when I work through the numbers by hand. Two things I would like to change before merge.
-
_unreachable_power.py:202stores the sample even when its value is empty, andpowerthen returnsNone, so the bounds lose the shift. Formulas send an empty value whenever one of their inputs has a gap (formulas/_ast.py:149), and a component that is not working is the most likely one to have gaps. So the bounds will jump between shifted and not shifted every resampling period, and the target power will jump with them. Can we keep the last real value, maybe with a maximum age, instead of clearing it? The power distributor had the same problem before, so a fix here helps both. -
About the exclusion bounds: I think they need the same shift. The power the pool can reach is the working components' range moved by the measured power, so the whole range moves, the exclusion zone included. With 2 working batteries of +-10 kW, a +-2 kW dead band and 2 blocked batteries at -5 kW, the bounds become [-25 kW, +15 kW] but the exclusion zone stays at +-2 kW. Then a request for -1 kW is moved to -2 kW even though the working batteries would only need +3 kW, and a request for -4 kW is allowed even though the working batteries would need +1 kW, inside their dead band. Shifting both keeps 0 W allowed, so I don't see a downside.
One more thing, not a blocker: for PV and steam boilers the pool bounds count an uncertain component as usable (pv_pool/_system_bounds_tracker.py:105), but the power distributor does not (_pv_inverter_manager.py:124). A failed set-power gives UNCERTAIN, which is the case in the PR description, so for those two pools the power is still taken off the target twice. The battery pool is fine, because both sides use get_working_components(). Should that be part of this PR or a follow-up?
Small notes: please add an "Upgrading" entry for the new exclusion bounds meaning, since the old docs promised they are inside the inclusion bounds. The release notes line about sharing state between pools (line 22) is hard to read.
Thanks, nice work on the shared-inverter case and on the test that proves it.
The power distributor subtracts the measured power of non-working batteries from the target, but the bounds only covered the working batteries, so that power was taken off the target twice. The bounds measure it with the same formula as the distributor, with the same meter fallback, and count the batteries behind a working battery's inverter as working, as the distributor does. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Both trackers summed the bounds of their working components the same way. The next commit changes that sum in both. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Their power distributors subtract that power from the target too, as in "Include non-working batteries' power in the battery pool bounds". Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
The PV and steam boiler bounds trackers stop tracking unreachable power when they restart after an error. The status isn't sent again until it changes, so the bounds lost the shift until then. Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
f508179 to
5240655
Compare
You're right that the bounds and the target jump, but gaps aren't the main cause. The formulas have a fallback, like The bigger cause is the formula restart. Each change to the set of non-working components starts a new formula, and it has no value for up to 1 s. Keeping the last real value doesn't help there, because a new formula has no last value. Until it has one, the power distributor subtracts nothing, so total power can overshoot. If the bounds have no value either, the target also drops. This was there before this PR, and the PR is still a clear improvement. I tested it with 7 × 100 kW batteries and 1 s resampling, with -600 kW requested and 3 inverters failing commands while their telemetry stayed live:
So I'd leave this out of this PR and handle it in a follow-up. The idea, not tested yet, is to keep each component's power stream running, so that a change to the set doesn't restart a formula.
You're right that the working batteries' dead band moves with the measured power, but shifting the pool's exclusion bounds alone makes things worse. I ran your example through the real clamp, request check and distribution code, taking -5 kW as the total blocked power and ±1 kW as the dead band per battery:
The shifted zone also leaves out the request that idles the working batteries. With -1 kW blocked, the zone is -3 to +1 kW. A 0 W request only passes because of the special handling, and -1 kW is moved to -3 kW. The -4.5 kW row is a real problem, but it isn't new, because the distributor already subtracted that power before this PR. A proper fix needs
The mismatch is real, but it was there before this PR, and I don't think it takes the power off twice. The bounds keep the uncertain component's whole range, so the target isn't clamped too far. For example, A is working, B is uncertain at -10 kW, and each has a range of -30..0 kW. The bounds say -60..0 kW, but only -40..-10 kW is reachable. A -60 kW request gives A -30 kW, so the total is -40 kW, which is the most that's possible. The only wrong thing is the reported range. A double cut needs B's measured power to be outside its own reported bounds. Fixing it now has a cost. Each failed set-power would then start a formula on the bounds side too, so these two pools would get the same short dip as the battery pool, and they don't have that dip in this case today. I'd rather do this as a follow-up together with the per-component power streams, where it wouldn't cause a dip.
Added an "Upgrading" entry for this.
Reworded it. That line came in with #1476, but it isn't released yet, so I fixed it here. |
Marenz
left a comment
There was a problem hiding this comment.
Thanks, this is a good answer. I checked all three points and you are right on all of them.
On the empty samples: I generated the real formulas and ran the Coalesce node with scripted streams. With a meter I get one empty sample and then the meter value; without a meter I get 0 W and no empty sample. So my "jumps every resampling period" was wrong, and keeping the last value would only bridge that single sample. The restart is indeed the bigger cause. I also worked through the four combinations of "bounds shifted" and "distributor subtracts", and only one of them loses power, which is the one the code was always in before this PR. So the restart gap is what is left of the old bug, not a new one, and your numbers match that.
On the exclusion bounds: I reproduced your table with the real clamp and request check code and got the same four rows, including the OutOfBounds. So shifting them alone is worse, and my suggestion was wrong. A correct fix has to move the "0 W is always allowed" rule as well, in both algorithms and in _check_request.
On the uncertain components: agreed, it is not a double cut as long as the component's measured power is inside its own reported bounds. It can still happen when the component sits at an older setpoint while its reported bound has shrunk, so I wrote that condition into the follow-up issue.
I opened #1486, #1487 and #1488 for the three follow-ups, so this is good to merge from my side.
When some batteries stop working (for example, a set-power call fails and the battery is blocked), the battery pool's bounds cover only the working batteries. The power manager clamps the target to those bounds. Then the power distributor subtracts the power still measured on the non-working batteries from the target, so the target was cut twice. With many batteries blocked, the inverters stayed near 0 W.
This branch shifts the inclusion bounds of the battery, PV and steam boiler pools by the power measured on their components that aren't working.
Changes
UnreachablePowerTrackermeasures that power with the component graph formula, so it gets the same meter fallback as the distributor. It restarts its formula when the set of non-working components changes. The distributor's component managers now use it instead of their own code.run_foreverrestarts them.SystemBoundsdocs now say they can lie outside the inclusion bounds. The distributor and each pool run their own unreachable-power formula; they don't share one.tests/utils/unreachable_power.py), because formulas produce no values in the mock fixtures.num_namespaces=2.