Skip to content

Commit 4cdecb1

Browse files
Make FormulaEngine instances composable, instead of FormulaReceivers (#327)
This PR changes how formulas are composed - - receivers from formulas are no longer composable. - formula composition is now done by composing FormulaEngine instances. - Automatic formulas from the logical meter and *pools, are now properties, and return `FormulaEngine` instances, which can be composed further, or can provide a receiver to fetch values. ``` python grid_power_receiver = microgrid.logical_meter().grid_power.new_receiver() self._inverter_power = ( microgrid.logical_meter().pv_power + microgrid.logical_meter().battery_power ).build("inverter_power") inverter_power_receiver = self._inverter_power.new_receiver() ``` The type hint issues in the formula engine are also resolved.
2 parents d743d77 + 9563b4d commit 4cdecb1

21 files changed

+478
-525
lines changed

RELEASE_NOTES.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66

77
## Upgrading
88

9+
+ Formulas composition has changed (#327) -
10+
- receivers from formulas are no longer composable.
11+
- formula composition is now done by composing FormulaEngine instances.
12+
- Automatic formulas from the logical meter and *pools, are now
13+
properties, and return `FormulaEngine` instances, which can be
14+
composed further, or can provide a receiver to fetch values.
15+
16+
``` python
17+
grid_power_receiver = microgrid.logical_meter().grid_power.new_receiver()
18+
19+
self._inverter_power = (
20+
microgrid.logical_meter().pv_power
21+
+ microgrid.logical_meter().battery_power
22+
).build("inverter_power")
23+
24+
inverter_power_receiver = self._inverter_power.new_receiver()
25+
```
26+
927
* Update BatteryStatus to mark battery with unknown capacity as not working (#263)
1028
* The channels dependency was updated to v0.14.0 (#292)
1129
* Some properties for `PowerDistributingActor` results were renamed to be more consistent between `Success` and `PartialFailure`:

examples/power_distribution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ async def run() -> None:
230230

231231
client_actor = DataCollectingActor(
232232
request_channel=power_dist_req_chan.new_sender(),
233-
active_power_data=await logical_meter.grid_power(),
233+
active_power_data=logical_meter.grid_power.new_receiver(),
234234
)
235235

236236
await actor.run(service_actor, client_actor, power_distributor)

pyproject.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ src_paths = ["src", "examples", "tests"]
134134
asyncio_mode = "auto"
135135
required_plugins = [ "pytest-asyncio", "pytest-mock" ]
136136

137-
[tool.mypy]
138-
# This is a temporary hack, for details see:
139-
# * https://github.com/frequenz-floss/frequenz-sdk-python/pull/219
140-
# * https://github.com/frequenz-floss/frequenz-sdk-python/issues/226
141-
exclude = ["src/frequenz/sdk/timeseries/_formula_engine/"]
142-
143137
[[tool.mypy.overrides]]
144138
module = [
145139
"grpc.aio",

src/frequenz/sdk/timeseries/_formula_engine/__init__.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,13 @@
22
# Copyright © 2023 Frequenz Energy-as-a-Service GmbH
33

44
"""A formula engine for applying formulas."""
5-
from ._formula_engine import (
6-
FormulaEngine,
7-
FormulaEngine3Phase,
8-
FormulaReceiver,
9-
FormulaReceiver3Phase,
10-
_GenericEngine,
11-
_GenericFormulaReceiver,
12-
)
5+
from ._formula_engine import FormulaEngine, FormulaEngine3Phase
136
from ._formula_engine_pool import FormulaEnginePool
147
from ._resampled_formula_builder import ResampledFormulaBuilder
158

169
__all__ = [
1710
"FormulaEngine",
1811
"FormulaEngine3Phase",
19-
"FormulaReceiver",
20-
"FormulaReceiver3Phase",
2112
"FormulaEnginePool",
22-
"_GenericEngine",
23-
"_GenericFormulaReceiver",
2413
"ResampledFormulaBuilder",
2514
]

0 commit comments

Comments
 (0)