Skip to content

Commit a692c6f

Browse files
Refine Site API, Upgrade Pydantic (#41)
* fix: update site api to use freq_mins the same as assets * chore: bump version to 1.0.0 * chore: enable python 3.12 * test: add missing site docs tests * docs: fix docs tests * build: update poetry lock check * test: update to python 3.11 * test: add more evs tests * test: more site testing * build: upgrade pydantic, numpy versions, make check, test, static, develop poetry groups optional * build: pydantic version upgrade * test: add pytest and hypothesis ignore stubs to mypy * test: add _pytest to mypy ignores * test: make mypy happy with _pytest
1 parent 8229cd9 commit a692c6f

File tree

26 files changed

+1489
-1501
lines changed

26 files changed

+1489
-1501
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-python@v4
1515
with:
16-
python-version: 3.10.6
16+
python-version: 3.11.5
1717
- run: make test QUIET=
1818
check:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- uses: actions/checkout@v3
2222
- uses: actions/setup-python@v4
2323
with:
24-
python-version: 3.10.6
24+
python-version: 3.11.5
2525
- run: make check QUIET=

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ QUIET := -q
1313

1414
setup-pip-poetry:
1515
pip install --upgrade pip $(QUIET)
16-
pip install poetry -c ./constraints.txt $(QUIET)
16+
pip install poetry==1.6.1 $(QUIET)
1717

1818
setup: setup-pip-poetry
1919
poetry install --with main $(QUIET)
@@ -58,6 +58,7 @@ create-test-docs: setup-test clean-test-docs
5858
python -m phmdoctest ./docs/docs/validation/renewable-generator.md --outfile tests/phmdoctest/test_validate_renewable_generator.py
5959
python -m phmdoctest ./docs/docs/how-to/dispatch-forecast.md --outfile tests/phmdoctest/test_forecast.py
6060
python -m phmdoctest ./docs/docs/how-to/price-carbon.md --outfile tests/phmdoctest/test_carbon.py
61+
python -m phmdoctest ./docs/docs/how-to/dispatch-site.md --outfile tests/phmdoctest/test_dispatch_site.py
6162
python -m phmdoctest ./docs/docs/assets/chp.md --outfile tests/phmdoctest/test_optimize_chp.py
6263
python -m phmdoctest ./docs/docs/assets/battery.md --outfile tests/phmdoctest/test_optimize_battery.py
6364
python -m phmdoctest ./docs/docs/assets/evs.md --outfile tests/phmdoctest/test_optimize_evs.py
@@ -92,7 +93,7 @@ lint: setup-check
9293
ruff check . --ignore E501 --extend-exclude=__init__.py,poc
9394
isort --check **/*.py --profile black
9495
black --check **/*.py
95-
poetry lock --check
96+
poetry check
9697

9798

9899
# ----- FORMATTING -----

constraints.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/docs/assets/battery.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ asset = epl.Battery(
2222
power_mw=1,
2323
capacity_mwh=3,
2424
efficiency_pct=0.9,
25-
electricity_carbon_intensities = [0.1, 0.2, 0.1, 0.15, 0.01, 0.7, 0.5, 0.01],
25+
electricity_carbon_intensities=[0.1, 0.2, 0.1, 0.15, 0.01, 0.7, 0.5, 0.01],
2626
freq_mins=60,
2727
initial_charge_mwh=0,
2828
final_charge_mwh=0,
@@ -40,6 +40,7 @@ assert all(
4040
"site-low_temperature_load_mwh",
4141
"site-low_temperature_generation_mwh",
4242
"site-gas_prices",
43+
"site-electric_load_mwh",
4344
"spill-electric_generation_mwh",
4445
"spill-electric_load_mwh",
4546
"spill-high_temperature_generation_mwh",

docs/docs/assets/chp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ assert all(
4848
"site-low_temperature_load_mwh",
4949
"site-low_temperature_generation_mwh",
5050
"site-gas_prices",
51+
"site-electric_load_mwh",
5152
"spill-electric_generation_mwh",
5253
"spill-electric_load_mwh",
5354
"spill-high_temperature_generation_mwh",

docs/docs/assets/evs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ assert all(
4343
"site-low_temperature_load_mwh",
4444
"site-low_temperature_generation_mwh",
4545
"site-gas_prices",
46+
"site-electric_load_mwh",
4647
"spill-electric_generation_mwh",
4748
"spill-electric_load_mwh",
4849
"spill-high_temperature_generation_mwh",

docs/docs/assets/heat-pump.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ assert all(
4545
"site-low_temperature_load_mwh",
4646
"site-low_temperature_generation_mwh",
4747
"site-gas_prices",
48+
"site-electric_load_mwh",
4849
"spill-electric_generation_mwh",
4950
"spill-electric_load_mwh",
5051
"spill-high_temperature_generation_mwh",

docs/docs/assets/renewable-generator.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ assert all(
2626
"site-low_temperature_load_mwh",
2727
"site-low_temperature_generation_mwh",
2828
"site-gas_prices",
29+
"site-electric_load_mwh",
2930
"wind-electric_generation_mwh",
3031
"total-electric_generation_mwh",
3132
"total-electric_load_mwh",

docs/docs/how-to/dispatch-assets.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/docs/how-to/dispatch-site.md

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,32 @@ Multiple assets can be optimized using a single `epl.Site`, which accepts a list
66

77
Below we give some examples of typical configurations of energy assets.
88

9-
## Battery & CHP Generator
9+
## Battery & CHP
1010

11-
We can use a site to optimize an electric battery alongside a gas fired generator:
11+
We can use a site to optimize an electric battery alongside a gas fired CHP:
1212

1313
```python
1414
import energypylinear as epl
1515

16-
site = epl.Site(assets=[
17-
epl.Battery(power_mw=2.0, capacity_mwh=4.0),
18-
epl.Generator(
19-
electric_power_max_mw=100,
20-
electric_power_min_mw=30,
21-
electric_efficiency_pct=0.4
22-
)
23-
])
24-
25-
simulation = site.optimize(
26-
electricity_prices=[100.0, 50, 200, -100, 0, 200, 100, -100],
27-
freq_mins=60,
28-
initial_charge_mwh=1,
29-
final_charge_mwh=3
16+
site = epl.Site(
17+
assets=[
18+
epl.Battery(
19+
power_mw=2.0,
20+
capacity_mwh=4.0,
21+
initial_charge_mwh=1,
22+
final_charge_mwh=3
23+
),
24+
epl.CHP(
25+
electric_power_max_mw=100,
26+
electric_power_min_mw=30,
27+
electric_efficiency_pct=0.4,
28+
),
29+
],
30+
electricity_prices=[100.0, 50, 200, -100, 0, 200, 100, -100],
31+
freq_mins=60,
3032
)
33+
34+
simulation = site.optimize()
3135
```
3236

3337
## Fast & Slow Battery
@@ -37,17 +41,27 @@ We can use a site to optimize a fast and slow battery alongside each other:
3741
```python
3842
import energypylinear as epl
3943

40-
site = epl.Site(assets=[
41-
epl.Battery(power_mw=4.0, capacity_mwh=1.0),
42-
epl.Battery(power_mw=2.0, capacity_mwh=4.0),
43-
])
44-
45-
simulation = site.optimize(
46-
electricity_prices=[100.0, 50, 200, -100, 0, 200, 100, -100],
47-
freq_mins=60,
48-
initial_charge_mwh=1,
49-
final_charge_mwh=3
44+
site = epl.Site(
45+
assets=[
46+
epl.Battery(
47+
power_mw=4.0,
48+
capacity_mwh=1.0,
49+
initial_charge_mwh=1,
50+
final_charge_mwh=1
51+
),
52+
epl.Battery(
53+
power_mw=2.0,
54+
capacity_mwh=4.0,
55+
initial_charge_mwh=4.0,
56+
final_charge_mwh=0.0,
57+
name="battery-2",
58+
),
59+
],
60+
electricity_prices=[100.0, 50, 200, -100, 0, 200, 100, -100],
61+
freq_mins=60,
5062
)
63+
64+
simulation = site.optimize()
5165
```
5266

5367
## Battery & EV Chargers
@@ -57,22 +71,29 @@ We can use a site to optimize a battery that sits alongside EV chargers:
5771
```python
5872
import energypylinear as epl
5973

60-
site = epl.Site(assets=[
61-
epl.Battery(power_mw=2.0, capacity_mwh=4.0),
62-
epl.EVs(charger_mws=[100, 100], charger_turndown=0.1)
63-
])
64-
65-
simulation = site.optimize(
66-
electricity_prices=[100.0, 50, 200, -100, 0, 200, 100, -100],
67-
freq_mins=60,
68-
initial_charge_mwh=1,
69-
final_charge_mwh=3,
70-
charge_events=[
71-
[1, 0, 0, 0, 0, 0, 0, 0],
72-
[0, 1, 1, 1, 0, 0, 0, 0],
73-
[0, 0, 0, 1, 1, 0, 0, 0],
74-
[0, 1, 0, 0, 0, 0, 0, 0],
74+
site = epl.Site(
75+
assets=[
76+
epl.Battery(
77+
power_mw=2.0,
78+
capacity_mwh=4.0,
79+
initial_charge_mwh=1,
80+
final_charge_mwh=3,
81+
),
82+
epl.EVs(
83+
chargers_power_mw=[100, 100],
84+
charger_turndown=0.1,
85+
charge_events=[
86+
[1, 0, 0, 0, 0, 0, 0, 0],
87+
[0, 1, 1, 1, 0, 0, 0, 0],
88+
[0, 0, 0, 1, 1, 0, 0, 0],
89+
[0, 1, 0, 0, 0, 0, 0, 0],
90+
],
91+
charge_events_capacity_mwh=[50, 100, 30, 40],
92+
),
7593
],
76-
charge_event_mwh=[50, 100, 30, 40]
94+
electricity_prices=[100.0, 50, 200, -100, 0, 200, 100, -100],
95+
freq_mins=60,
7796
)
97+
98+
simulation = site.optimize()
7899
```

0 commit comments

Comments
 (0)