Optimizing energy assets is critical for maximizing profit and minimizing carbon emissions - but most energy asset operators rely on simple heuristics or manual dispatch decisions.
Linear programming offers a better solution - it can find optimal dispatch schedules for batteries, electric vehicles, combined heat and power generators, and renewable assets.
This post introduces energy-py-linear - a Python library that makes it easy to optimize energy assets using mixed-integer linear programming (MILP).
You can find the source code at ADGEfficiency/energy-py-linear and the documentation at energypylinear.adgefficiency.com.
Linear programming is the right tool for many energy optimization problems - energy systems often have linear characteristics that make them well-suited for linear solvers.
Advantages:
energypylinear optimizes the dispatch of various energy assets:
Assets can be optimized individually or together as a site, with customizable objectives (profit, carbon, or custom) and constraints.
Requires Python 3.11 or 3.12:
$ pip install energypylinear
The simplest use case is optimizing a single battery for price arbitrage:
import energypylinear as epl
asset = epl.Battery(
power_mw=2.0,
capacity_mwh=4.0,
efficiency_pct=0.9,
electricity_prices=[100.0, 50, 200, -100, 0, 200, 100, -100],
)
simulation = asset.optimize()
The battery will charge when prices are low (or negative) and discharge when prices are high.
The real power of energypylinear comes from optimizing multiple assets together:
import energypylinear as epl
assets = [
epl.Battery(power_mw=2.0, capacity_mwh=4.0),
epl.CHP(
electric_power_max_mw=100, electric_power_min_mw=30, electric_efficiency_pct=0.4
),
epl.Boiler(),
epl.Valve(),
]
site = epl.Site(
assets=assets,
electricity_prices=[100, 50, 200, -100, 0],
high_temperature_load_mwh=[105, 110, 120, 110, 105],
low_temperature_load_mwh=[105, 110, 120, 110, 105],
)
simulation = site.optimize()
The optimizer coordinates all assets to minimize cost while meeting thermal loads.
energypylinear can optimize for carbon emissions instead of profit:
import energypylinear as epl
assets = [
epl.Battery(power_mw=10, capacity_mwh=20, efficiency_pct=0.9),
epl.RenewableGenerator(
electric_generation_mwh=[10, 20, 30, 20, 10],
electric_generation_lower_bound_pct=0.5,
name="solar",
),
]
site = epl.Site(
assets=assets,
electricity_carbon_intensities=[0.5, -0.5, 0.5, 0.5, -0.5],
export_limit_mw=25,
)
simulation = site.optimize(objective="carbon")
The results show how the battery and solar generation coordinate to minimize carbon:
site-electricity_carbon_intensities site-export_limit_mw site-export_power_mwh solar-electric_generation_used_mwh battery-electric_charge_mwh battery-electric_discharge_mwh
0 0.5 25 10.00 10.0 0.00 0.00
1 -0.5 25 25.00 20.0 5.00 0.00
2 0.5 25 25.00 30.0 0.00 5.00
3 0.5 25 15.00 20.0 0.00 5.00
4 -0.5 25 10.00 10.0 0.00 0.00
Key observations:
energypylinear supports advanced use cases:
energypylinear is ideal for:
energypylinear is not suitable for:
energypylinear makes it easy to optimize energy assets using mixed-integer linear programming.
Key features:
Learn more:
pip install energypylinearThanks for reading!