Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Adds support for `ECHO_DISABLE_PATH_WARNING` environment variable. This is enabled by default when running pytest.
- Adds [attrs](https://www.attrs.org/en/stable/index.html) as a project dependency.
- Adds support for Python 3.15 (drop support for Python 3.11)
- Adds `add_nodes` method to OptimisationGraph

#### Changes

Expand All @@ -27,6 +28,11 @@
- Pydantic project dependency.
- Removes support for Python 3.11 (adds support for Python 3.15)

#### Deprecates

- The following attributes of Optimisationgraph: `node_obj` and `edge_obj`.
- The following methods from OptimisationGraph: `delete_node`, `delete_edge`, `add_node_obj`, `add_nodes_from`, `add_edge_obj`, `add_edges_from`, `connect_ports_and_create_edge`, `rebuild_all_edges`, `print_port_names`, `get_port_names_from_nodes`, `get_port_names_from_edges`, `update_node` and `inject_data_into_ev`.


## Releases

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ Please log any issues in the [issue tracker](https://github.com/bsgip/echo/issue
| Documentation update | Underway | | Sep 2026 |
| Examples update | Underway | | Sep 2026 |
| Standardise data injection process | Planning | <https://github.com/bsgip/echo/issues/103> | Sep 2026 |
| Upgrade to pydantic v2 | Not Started | <https://github.com/bsgip/echo/issues/101> | Oct 2026 |
| Migrate from Pydantic to Attrs | Complete | <https://github.com/bsgip/echo/issues/101> | Oct 2026 |
| Add linopy as parser option | Planning | <https://github.com/bsgip/echo/issues/102> | Dec 2026 |
2 changes: 1 addition & 1 deletion docs/source/constraints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ An example of how this might be done in code is shown below. First, we define an
site = TellegenNode()
site.add_electrical_ports_from_list(['cp', 'load', 'battery'])

system.add_node_obj([grid, battery, load, site])
system.add_nodes([grid, battery, load, site])

system.connect_ports_and_create_edge(grid.ports['grid'], site.ports['cp'])
system.connect_ports_and_create_edge(battery.ports['battery'], site.ports['battery'])
Expand Down
4 changes: 2 additions & 2 deletions docs/source/echo_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Once the graph has been created, we can create some nodes and add them to the gr
port_unit=Units.KW,
profile=[2]*24) # creates a node with one fixed demand port called 'load'

system.add_node_obj([grid, battery])
system.add_nodes([grid, battery])


To connect nodes together via ports, we need to retrieve the port objects as well as the node names. We can then create an edge using the ``.connect_ports_and_create_edge`` method, as shown below:
Expand All @@ -39,7 +39,7 @@ To connect nodes together via ports, we need to retrieve the port objects as wel

grid_port = grid.get_port('grid')
load_port = load.get_port('load')
system.connect_ports_and_create_edge(grid_port, load_port, nodes=('grid', 'load'))
system.connect_ports_and_create_edge(grid_port, load_port)

.. note::
Any nodes that are part of an edge must be added to the graph first, before edges can be created.
Expand Down
6 changes: 3 additions & 3 deletions examples/attribute_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def default_surface_area_of_cylinder(volume: float, include_bottom: bool = True)
# storage
#
system = OptimisationGraph()
system.add_node_obj([storage, thermal_demand, thermal_mains, cp])
system.add_nodes([storage, thermal_demand, thermal_mains, cp])
system.connect_ports_and_create_edge(cp.ports["to_supply_kwt"], thermal_mains.ports["supply_kwt"])
system.connect_ports_and_create_edge(cp.ports["to_storage_kwt"], storage.ports["input_output"])
system.connect_ports_and_create_edge(cp.ports["to_demand_kwt"], thermal_demand.ports["demand_kwt"])
Expand Down Expand Up @@ -160,7 +160,7 @@ def to_html_string(attrs: dict[str, list[Any]]) -> str:


def node_hover_text(node: Node, *_: object) -> str:
node_object = optimise_results.graph.node_obj[node]
node_object = optimise_results.graph.nodes[node]
node_type = type(node_object).__name__

tracker = optimise_results.model_attribute_tracker
Expand All @@ -174,7 +174,7 @@ def node_hover_text(node: Node, *_: object) -> str:

def edge_hover_text(edge: Node, *_: object) -> str:
edge_reversed = edge[::-1] # reverse the edge tuple (not sure why edges are defined in the opposite sense)
edge_object = optimise_results.graph.edge_obj[edge_reversed]
edge_object = optimise_results.graph.edges[edge_reversed]

tracker = optimise_results.model_attribute_tracker
if tracker is not None:
Expand Down
2 changes: 1 addition & 1 deletion examples/behind_the_meter_with_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
network = OptimisationGraph()

# Populate graph with assets (nodes)
network.add_node_obj([grid, battery, load, solar, connection_point, inverter])
network.add_nodes([grid, battery, load, solar, connection_point, inverter])

# Add edges to graph (i.e. connect up the graph structure how we want it)
network.connect_ports_and_create_edge(grid.ports["grid"], connection_point.ports["grid"])
Expand Down
2 changes: 1 addition & 1 deletion examples/demand_tariff.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
site = TellegenNode()
site.add_ports_from_list(["cp", "load", "battery"], FlexPort, units=Units.KW)

system.add_node_obj([grid, battery, load, site])
system.add_nodes([grid, battery, load, site])

system.connect_ports_and_create_edge(grid.ports["grid"], site.ports["cp"])
system.connect_ports_and_create_edge(battery.ports["battery"], site.ports["battery"])
Expand Down
2 changes: 1 addition & 1 deletion examples/demand_tariff_with_time_periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
site1.add_ports_from_list(["cp", "load", "bess"], FlexPort, units=Units.KW)
cp1 = site1.ports["cp"]

system.add_node_obj([grid, battery1, load1, site1])
system.add_nodes([grid, battery1, load1, site1])

system.connect_ports_and_create_edge(grid.ports["grid"], cp1)
system.connect_ports_and_create_edge(site1.ports["bess"], b1)
Expand Down
4 changes: 2 additions & 2 deletions examples/electric_vehicles.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
demand=ev_with_profile_demand,
)

# system.add_node_obj([grid, ev_v0g, ev_v1g, ev_v2g, ev_with_profile, connection_point])
system.add_node_obj(
# system.add_nodes([grid, ev_v0g, ev_v1g, ev_v2g, ev_with_profile, connection_point])
system.add_nodes(
[
grid,
connection_point,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@
"source": [
"network = OptimisationGraph()\n",
"\n",
"network.add_node_obj([grid, battery, load, solar, connection_point])\n",
"network.add_nodes([grid, battery, load, solar, connection_point])\n",
"\n",
"network.connect_ports_and_create_edge(grid.ports[\"grid\"], connection_point.ports[\"grid\"])\n",
"network.connect_ports_and_create_edge(connection_point.ports[\"load\"], load.ports[\"load\"])\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/jupyter_examples/electric_vehicles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
"system = OptimisationGraph()\n",
"\n",
"# Add nodes to the optimisation graph\n",
"system.add_node_obj(\n",
"system.add_nodes(\n",
" [\n",
" grid,\n",
" connection_point,\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/jupyter_examples/path_tracing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
"network = OptimisationGraph()\n",
"\n",
"# Populate graph with assets (nodes)\n",
"network.add_node_obj([grid, battery, load, solar, connection_point])\n",
"network.add_nodes([grid, battery, load, solar, connection_point])\n",
"\n",
"# Add edges to graph\n",
"network.connect_ports_and_create_edge(grid.ports[\"grid\"], connection_point.ports[\"grid\"])\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/jupyter_examples/slack_variables.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
"outputs": [],
"source": [
"network = OptimisationGraph()\n",
"network.add_node_obj([grid, inverter, solar])\n",
"network.add_nodes([grid, inverter, solar])\n",
"\n",
"network.connect_ports_and_create_edge(grid.ports[\"grid\"], inverter.ports[\"inv\"])\n",
"network.connect_ports_and_create_edge(inverter.ports[\"pv\"], solar.ports[\"pv\"])"
Expand Down
2 changes: 1 addition & 1 deletion examples/neighbourhood_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
solar.ports["pv"] = pv

# Populate graph with assets (nodes)
system.add_node_obj([grid, battery, load, solar, connection_point])
system.add_nodes([grid, battery, load, solar, connection_point])

# Add edges to graph
system.connect_ports_and_create_edge(grid.ports["grid"], connection_point.ports["grid"])
Expand Down
2 changes: 1 addition & 1 deletion examples/neighbourhood_battery_with_aggregate_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
battery.ports["bess"] = b

# Populate graph with assets (nodes)
system.add_node_obj([grid, battery, load, connection_point])
system.add_nodes([grid, battery, load, connection_point])

# Add edges to graph
system.connect_ports_and_create_edge(grid.ports["grid"], connection_point.ports["grid"])
Expand Down
5 changes: 1 addition & 4 deletions examples/serialisable_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,20 @@
battery.ports["bess"] = b

# Populate graph with assets (nodes)
system.add_nodes_from([grid, battery, load, connection_point])
system.add_nodes([grid, battery, load, connection_point])

# Add edges to graph
system.connect_ports_and_create_edge(
grid.ports["grid"],
connection_point.ports["grid"],
nodes=(grid.node_name, connection_point.node_name),
)
system.connect_ports_and_create_edge(
connection_point.ports["load"],
load.ports["load"],
nodes=(load.node_name, connection_point.node_name),
)
system.connect_ports_and_create_edge(
connection_point.ports["bess"],
battery.ports["bess"],
nodes=(battery.node_name, connection_point.node_name),
)

throughput_cost = ThroughputCost(component=b, rate=0.000001)
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_behind_the_meter_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
network = OptimisationGraph()

# Populate graph with assets (nodes)
network.add_node_obj([grid, battery, load, solar, connection_point, inverter])
network.add_nodes([grid, battery, load, solar, connection_point, inverter])

# Add edges to graph (i.e. connect up the graph structure how we want it)
network.connect_ports_and_create_edge(grid.ports["grid"], connection_point.ports["grid"])
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_thermal_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def default_surface_area_of_cylinder(volume: float, include_bottom: bool = True)
# storage
#
system = OptimisationGraph()
system.add_node_obj([storage, thermal_demand, thermal_mains, cp])
system.add_nodes([storage, thermal_demand, thermal_mains, cp])
system.connect_ports_and_create_edge(cp.ports["to_supply_kwt"], thermal_mains.ports["supply_kwt"])
system.connect_ports_and_create_edge(cp.ports["to_storage_kwt"], storage.ports["input_output"])
system.connect_ports_and_create_edge(cp.ports["to_demand_kwt"], thermal_demand.ports["demand_kwt"])
Expand Down Expand Up @@ -200,7 +200,7 @@ def default_surface_area_of_cylinder(volume: float, include_bottom: bool = True)
#

system = OptimisationGraph()
system.add_node_obj([storage_2p, thermal_demand, thermal_mains, cp_1, cp_2])
system.add_nodes([storage_2p, thermal_demand, thermal_mains, cp_1, cp_2])
system.connect_ports_and_create_edge(cp_1.ports["to_supply_kwt"], thermal_mains.ports["supply_kwt"])
system.connect_ports_and_create_edge(cp_1.ports["to_storage_input_kwt"], storage_2p.ports["input"])
system.connect_ports_and_create_edge(cp_1.ports["to_demand_cp_kwt"], cp_2.ports["to_supply_cp_kwt"])
Expand Down
2 changes: 1 addition & 1 deletion examples/stand_alone_power_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@


# Populate graph with assets (nodes)
system.add_node_obj([battery, load, solar, connection_point, inverter, diesel_gen])
system.add_nodes([battery, load, solar, connection_point, inverter, diesel_gen])

# Add edges to graph (i.e. connect up the graph structure how we want it)
# system.connect_ports_and_create_edge(grid.ports['grid'], connection_point.ports['grid'])
Expand Down
2 changes: 1 addition & 1 deletion examples/using_dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@


# Populate graph with assets (nodes)
system.add_nodes_from([grid, load, connection_point, solar])
system.add_nodes([grid, load, connection_point, solar])

system.connect_ports_and_create_edge(grid.get_port("grid"), connection_point.get_port("grid"))
system.connect_ports_and_create_edge(pv, connection_point.get_port("pv"))
Expand Down
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ description = "The Energy and Commodity Holistic Optimiser (ECHO)."
keywords = ["energy", "commodity", "modelling", "optimization"]
classifiers = [
"Development Status :: 4 - Beta",
"Framework :: Pydantic :: 1",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering",
Expand Down Expand Up @@ -89,14 +88,6 @@ select = ["E", "W", "F", "I", "S", "C90", "B", "UP", "ANN", "N"]
[tool.ruff.lint.mccabe]
max-complexity = 15

[tool.ruff.lint.pep8-naming]
# Allow pydantic's @validator and @root_validator decorators to trigger class method treatment.
classmethod-decorators = [
"classmethod",
"pydantic.validator",
"pydantic.root_validator",
]

[tool.ruff.lint.per-file-ignores]
"src/**" = ["ANN003"]
"tests/**" = ["S", "ANN", "N", "B017"]
Expand Down
1 change: 0 additions & 1 deletion src/echo/models/base/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Edge:
"""

vertices: tuple[Port, Port]
nodes: tuple[str, str] | None = None # tuple of node names - todo make this required
tariff: list | None = None

uid: str = field(factory=shortuuid.uuid)
Expand Down
Loading
Loading