From 8f94b5f643d6acf824f3e6cb0e08970dd1b1343e Mon Sep 17 00:00:00 2001 From: Mike Turner Date: Tue, 27 Oct 2026 13:33:35 +0800 Subject: [PATCH] fixes #54 --- examples/attribute_tracking.py | 15 ++++++++------- examples/behind_the_meter_with_battery.py | 3 +-- examples/demand_tariff.py | 6 ++---- examples/demand_tariff_with_time_periods.py | 15 ++++++++++----- examples/electric_vehicles.py | 3 +-- examples/jupyter_examples/electric_vehicles.ipynb | 5 +++-- examples/neighbourhood_battery.py | 6 ++---- .../neighbourhood_battery_with_aggregate_load.py | 3 +-- examples/serialisable_graph.py | 3 +-- examples/simple_behind_the_meter_network.py | 3 +-- examples/simple_thermal_network.py | 3 +-- examples/stand_alone_power_system.py | 6 ++---- examples/using_dataframes.py | 3 +-- pyproject.toml | 3 +-- 14 files changed, 35 insertions(+), 42 deletions(-) diff --git a/examples/attribute_tracking.py b/examples/attribute_tracking.py index 3a5e24d5..f1ca4f6b 100644 --- a/examples/attribute_tracking.py +++ b/examples/attribute_tracking.py @@ -8,8 +8,7 @@ from echo.configuration import Units from echo.models.agnostic import FlexPort, Sink, TellegenNode from echo.models.base import Node, OptimisationGraph -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.models.thermal import ThermalStorage from echo.objectives.base import ObjectiveSet from echo.objectives.power import PeakPositivePower @@ -33,7 +32,7 @@ NUM_EXPANSION_PERIODS = 1 -def default_surface_area_of_cylinder(volume: float, include_bottom: bool = True): +def default_surface_area_of_cylinder(volume: float, include_bottom: bool = True) -> float: """Given volume of the cylinder in cubic meters, calculate surface area. Assuming height to diameter ration H/D=3. If include_bottom is False, do not include bottom surface. @@ -150,7 +149,7 @@ def default_surface_area_of_cylinder(volume: float, include_bottom: bool = True) print(tracker) -def to_html_string(attrs: dict[str, list[Any]]): +def to_html_string(attrs: dict[str, list[Any]]) -> str: attr_text = "" for attr_class in sorted(attrs.keys()): attr_text += "
" @@ -160,7 +159,7 @@ def to_html_string(attrs: dict[str, list[Any]]): return attr_text -def node_hover_text(node: Any, *_) -> str: +def node_hover_text(node: Node, *_: object) -> str: node_object = optimise_results.graph.node_obj[node] node_type = type(node_object).__name__ @@ -173,7 +172,7 @@ def node_hover_text(node: Any, *_) -> str: return "" -def edge_hover_text(edge: Any, *_) -> 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] @@ -185,9 +184,11 @@ def edge_hover_text(edge: Any, *_) -> str: return title + to_html_string(attrs) return "" -def node_size(*_) -> int: + +def node_size(*_: object) -> int: return 40 + # Use the new visualization function to plot the network/graph # This function takes callbacks for setting the node (colors, text/labels, hover text etc). fig = viz.PlotlyGraph.plot( diff --git a/examples/behind_the_meter_with_battery.py b/examples/behind_the_meter_with_battery.py index f4f72fb1..379a8a81 100644 --- a/examples/behind_the_meter_with_battery.py +++ b/examples/behind_the_meter_with_battery.py @@ -10,8 +10,7 @@ from echo.configuration import Units from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import Node, OptimisationGraph -from echo.models.electrical import (ElectricalDemand, ElectricalGeneration, - ElectricalStorage, Inverter) +from echo.models.electrical import ElectricalDemand, ElectricalGeneration, ElectricalStorage, Inverter from echo.models.scenario import EngineSettings, ScenarioSettings from echo.objectives.base import ObjectiveSet from echo.objectives.power import PeakNegativePower diff --git a/examples/demand_tariff.py b/examples/demand_tariff.py index c4d8f07f..c25a2de7 100644 --- a/examples/demand_tariff.py +++ b/examples/demand_tariff.py @@ -8,11 +8,9 @@ from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import OptimisationGraph from echo.models.prebuilt import Battery, FlexNode, Load -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.objectives.base import ObjectiveSet -from echo.objectives.tariff import (DemandTariffObjective, ImportDemandCharge, - ThroughputCost) +from echo.objectives.tariff import DemandTariffObjective, ImportDemandCharge, ThroughputCost from echo.optimiser import optimise SOLVER = os.environ.get("OPTIMISER_ENGINE", "cplex") diff --git a/examples/demand_tariff_with_time_periods.py b/examples/demand_tariff_with_time_periods.py index bfbc75b5..116050e3 100644 --- a/examples/demand_tariff_with_time_periods.py +++ b/examples/demand_tariff_with_time_periods.py @@ -6,12 +6,17 @@ from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import Node, OptimisationGraph from echo.models.electrical import ElectricalDemand, ElectricalStorage -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.objectives.base import ObjectiveSet -from echo.objectives.tariff import (Day, DemandTariffObjective, - ImportDemandCharge, ResetPeriod, - ThroughputCost, TimePeriod, Window) +from echo.objectives.tariff import ( + Day, + DemandTariffObjective, + ImportDemandCharge, + ResetPeriod, + ThroughputCost, + TimePeriod, + Window, +) from echo.optimiser import optimise expansion_periods = 1 diff --git a/examples/electric_vehicles.py b/examples/electric_vehicles.py index f5551560..acf46575 100644 --- a/examples/electric_vehicles.py +++ b/examples/electric_vehicles.py @@ -13,8 +13,7 @@ from echo.models.base import OptimisationGraph from echo.models.electrical import EVV0G, EVV1G, EVV2G, EVWithProfile from echo.models.prebuilt import FlexElectricalNode -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.objectives.base import ObjectiveSet from echo.objectives.tariff import ImportTariff, ThroughputCost from echo.optimiser import optimise diff --git a/examples/jupyter_examples/electric_vehicles.ipynb b/examples/jupyter_examples/electric_vehicles.ipynb index 70a06293..b244d155 100644 --- a/examples/jupyter_examples/electric_vehicles.ipynb +++ b/examples/jupyter_examples/electric_vehicles.ipynb @@ -497,8 +497,9 @@ "plt.xlim([0, 47])\n", "plt.show()\n", "\n", - "# Plot ev_with_profile input demand, output demand (which should be the same as input demand) and import tariff. There is no state\n", - "# of charge value for ev_with_profile\n", + "# Plot ev_with_profile input demand, output demand (which should\n", + "# be the same as input demand) and import tariff.\n", + "# There is no state of charge value for ev_with_profile\n", "plt.plot(ev_with_profile_demand)\n", "plt.plot(optimise_results.node_values(ev_with_profile, 0)[\"cp\"])\n", "plt.plot(import_tariff)\n", diff --git a/examples/neighbourhood_battery.py b/examples/neighbourhood_battery.py index d631a95b..218c786b 100644 --- a/examples/neighbourhood_battery.py +++ b/examples/neighbourhood_battery.py @@ -7,10 +7,8 @@ from echo.configuration import Units from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import Node, OptimisationGraph -from echo.models.electrical import (ElectricalDemand, ElectricalGeneration, - ElectricalStorage) -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.electrical import ElectricalDemand, ElectricalGeneration, ElectricalStorage +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.objectives.base import ObjectiveSet from echo.objectives.tariff import PathTariff, ThroughputCost from echo.optimiser import optimise diff --git a/examples/neighbourhood_battery_with_aggregate_load.py b/examples/neighbourhood_battery_with_aggregate_load.py index 40fc7999..f30e504d 100644 --- a/examples/neighbourhood_battery_with_aggregate_load.py +++ b/examples/neighbourhood_battery_with_aggregate_load.py @@ -8,8 +8,7 @@ from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import Node, OptimisationGraph from echo.models.electrical import ElectricalStorage, FixedElectricalPort -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.objectives.base import ObjectiveSet from echo.objectives.tariff import PathTariff, ThroughputCost from echo.optimiser import optimise diff --git a/examples/serialisable_graph.py b/examples/serialisable_graph.py index 8dc2f092..b9ad3129 100644 --- a/examples/serialisable_graph.py +++ b/examples/serialisable_graph.py @@ -8,8 +8,7 @@ from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import Node, OptimisationGraph from echo.models.electrical import ElectricalStorage, FixedElectricalPort -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.objectives.base import ObjectiveSet from echo.objectives.tariff import ThroughputCost from echo.optimiser import optimise diff --git a/examples/simple_behind_the_meter_network.py b/examples/simple_behind_the_meter_network.py index 6b327b41..b13044f3 100644 --- a/examples/simple_behind_the_meter_network.py +++ b/examples/simple_behind_the_meter_network.py @@ -1,8 +1,7 @@ from echo.configuration import Units from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import Node, OptimisationGraph -from echo.models.electrical import (ElectricalDemand, ElectricalGeneration, - ElectricalStorage, Inverter) +from echo.models.electrical import ElectricalDemand, ElectricalGeneration, ElectricalStorage, Inverter """ A behind-the-meter battery network diff --git a/examples/simple_thermal_network.py b/examples/simple_thermal_network.py index 4b86431e..09bf76ff 100644 --- a/examples/simple_thermal_network.py +++ b/examples/simple_thermal_network.py @@ -4,8 +4,7 @@ from echo.configuration import Units from echo.models.agnostic import FlexPort, Sink, TellegenNode from echo.models.base import Node, OptimisationGraph -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.models.thermal import ThermalStorage from echo.objectives.base import ObjectiveSet from echo.objectives.power import PeakPositivePower diff --git a/examples/stand_alone_power_system.py b/examples/stand_alone_power_system.py index 787b32fb..9d5ad527 100644 --- a/examples/stand_alone_power_system.py +++ b/examples/stand_alone_power_system.py @@ -7,11 +7,9 @@ from echo.configuration import Units from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import Node, OptimisationGraph -from echo.models.electrical import (ElectricalDemand, ElectricalGeneration, - ElectricalStorage, Inverter) +from echo.models.electrical import ElectricalDemand, ElectricalGeneration, ElectricalStorage, Inverter from echo.models.prebuilt import DieselGenerator -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.objectives.base import ObjectiveSet from echo.objectives.tariff import ImportTariff from echo.optimiser import optimise diff --git a/examples/using_dataframes.py b/examples/using_dataframes.py index ccb75665..7af63e3c 100644 --- a/examples/using_dataframes.py +++ b/examples/using_dataframes.py @@ -4,8 +4,7 @@ from echo.models.agnostic import FlexPort, TellegenNode from echo.models.base import Node, OptimisationGraph from echo.models.electrical import ElectricalGeneration, FixedElectricalPort -from echo.models.scenario import (ScenarioSettings, - engine_settings_from_environment) +from echo.models.scenario import ScenarioSettings, engine_settings_from_environment from echo.optimiser import optimise time_periods = 48 diff --git a/pyproject.toml b/pyproject.toml index 65dd6f18..67a5979b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,6 @@ exclude_dirs = ["tests"] [tool.ruff] line-length = 120 -extend-exclude = ["examples"] [tool.ruff.lint] select = ["E", "W", "F", "I", "S", "C90", "B", "UP", "ANN", "N"] @@ -93,7 +92,7 @@ select = ["E", "W", "F", "I", "S", "C90", "B", "UP", "ANN", "N"] max-complexity = 15 [tool.ruff.lint.pep8-naming] -# Allow pydantic's @validator and @root_validator decorators to trigger class method treatment. +# Allow pydantic's @validator and @root_validator decorators to trigger class method treatment. classmethod-decorators = [ "classmethod", "pydantic.validator",