eris-echo 2.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. echo/__init__.py +1 -0
  2. echo/configuration.py +178 -0
  3. echo/constants.py +8 -0
  4. echo/exceptions.py +16 -0
  5. echo/functional.py +83 -0
  6. echo/models/__init__.py +0 -0
  7. echo/models/agnostic/__init__.py +50 -0
  8. echo/models/agnostic/aggregation.py +64 -0
  9. echo/models/agnostic/base.py +84 -0
  10. echo/models/agnostic/bounded.py +43 -0
  11. echo/models/agnostic/controlled.py +97 -0
  12. echo/models/agnostic/flex.py +61 -0
  13. echo/models/agnostic/input_output.py +30 -0
  14. echo/models/agnostic/storage.py +307 -0
  15. echo/models/agnostic/tellegen/__init__.py +6 -0
  16. echo/models/agnostic/tellegen/base.py +62 -0
  17. echo/models/agnostic/tellegen/multi_commodity.py +50 -0
  18. echo/models/agnostic/tellegen/partitioned_multi_commodity.py +88 -0
  19. echo/models/agnostic/tellegen/three_way_valve.py +122 -0
  20. echo/models/agnostic/time_delay.py +34 -0
  21. echo/models/agnostic/time_varying.py +134 -0
  22. echo/models/base/__init__.py +21 -0
  23. echo/models/base/edge.py +128 -0
  24. echo/models/base/node.py +160 -0
  25. echo/models/base/optimisation_graph.py +546 -0
  26. echo/models/base/path.py +66 -0
  27. echo/models/base/port.py +564 -0
  28. echo/models/base/transform.py +186 -0
  29. echo/models/base/types.py +7 -0
  30. echo/models/carbon/__init__.py +4 -0
  31. echo/models/carbon/aggregation.py +33 -0
  32. echo/models/carbon/base.py +25 -0
  33. echo/models/electrical/__init__.py +35 -0
  34. echo/models/electrical/base.py +37 -0
  35. echo/models/electrical/ev/__init__.py +14 -0
  36. echo/models/electrical/ev/base.py +340 -0
  37. echo/models/electrical/ev/deprecated.py +273 -0
  38. echo/models/electrical/ev/ev_with_profile.py +137 -0
  39. echo/models/electrical/ev/v0g.py +264 -0
  40. echo/models/electrical/ev/v1g.py +85 -0
  41. echo/models/electrical/ev/v2g.py +84 -0
  42. echo/models/electrical/generation.py +49 -0
  43. echo/models/electrical/inverter.py +97 -0
  44. echo/models/gas/__init__.py +5 -0
  45. echo/models/gas/base.py +18 -0
  46. echo/models/gas/boiler_fixedcop.py +65 -0
  47. echo/models/gas/boiler_tempcontrolled.py +96 -0
  48. echo/models/prebuilt/__init__.py +17 -0
  49. echo/models/prebuilt/battery.py +36 -0
  50. echo/models/prebuilt/diesel_generator.py +57 -0
  51. echo/models/prebuilt/flex.py +36 -0
  52. echo/models/prebuilt/load.py +14 -0
  53. echo/models/prebuilt/scaled_solar.py +19 -0
  54. echo/models/prebuilt/solar.py +13 -0
  55. echo/models/scenario.py +63 -0
  56. echo/models/thermal/__init__.py +15 -0
  57. echo/models/thermal/base.py +117 -0
  58. echo/models/thermal/parameterised_chiller.py +228 -0
  59. echo/models/thermal/parameterised_heatpump.py +496 -0
  60. echo/models/thermal/simple_chiller.py +139 -0
  61. echo/models/thermal/simple_heatpump.py +291 -0
  62. echo/models/thermal/simple_heatpump_dualoutput.py +195 -0
  63. echo/models/thermal/storage.py +307 -0
  64. echo/objectives/__init__.py +0 -0
  65. echo/objectives/base.py +99 -0
  66. echo/objectives/contingency.py +158 -0
  67. echo/objectives/power.py +132 -0
  68. echo/objectives/tariff.py +694 -0
  69. echo/optimiser.py +460 -0
  70. echo/py.typed +0 -0
  71. echo/tracker.py +74 -0
  72. echo/utils.py +506 -0
  73. echo/validators.py +290 -0
  74. echo/visualization.py +229 -0
  75. eris_echo-2.3.0.dist-info/METADATA +127 -0
  76. eris_echo-2.3.0.dist-info/RECORD +79 -0
  77. eris_echo-2.3.0.dist-info/WHEEL +5 -0
  78. eris_echo-2.3.0.dist-info/licenses/LICENSE.txt +22 -0
  79. eris_echo-2.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,186 @@
1
+ from __future__ import annotations # Deprecating in python 3.15 in favour of lazy annotations (PEP 649 and 749)
2
+
3
+ from dataclasses import dataclass
4
+
5
+ import pyomo.environ as en
6
+ import shortuuid
7
+ from attrs import define, field
8
+ from pyomo.core.expr.relational_expr import EqualityExpression
9
+
10
+ from echo.configuration import TransformRule
11
+ from echo.exceptions import ConfigurationError
12
+ from echo.models.base.node import Node
13
+ from echo.models.base.port import Port
14
+ from echo.models.scenario import EchoConcreteModel
15
+ from echo.utils import (
16
+ TimeExpandableType,
17
+ TimeSeriesData,
18
+ expand_as_array,
19
+ )
20
+
21
+
22
+ @dataclass
23
+ class TransformTerm:
24
+ var: Port
25
+ rule: TransformRule
26
+ weight: TimeExpandableType
27
+
28
+
29
+ @define
30
+ class Transform:
31
+ """An object for carrying a generic linear node transformation."""
32
+
33
+ uid: str = field(factory=shortuuid.uuid)
34
+ lhs_terms: list[TransformTerm] = field(factory=list)
35
+ rhs: en.numeric_expr.NumericExpression | float = 0
36
+
37
+ @property
38
+ def lhs(self) -> list[TransformTerm]:
39
+ """lhs is an alias for lhs_terms"""
40
+ return self.lhs_terms
41
+
42
+ @property
43
+ def transform_name(self) -> str:
44
+ return "transform_" + str(self.uid)
45
+
46
+ def _add_transform_to_model(self, model: EchoConcreteModel) -> None:
47
+ # Check if we need to create pos/neg components
48
+ for term in self.lhs:
49
+ if term.rule is not TransformRule.Both:
50
+ var = term.var
51
+ var.constrain_pos_neg(model)
52
+
53
+
54
+ @define
55
+ class TransformNode(Node):
56
+ """Implements node constraints using Transforms"""
57
+
58
+ transformations: dict[str, Transform] = field(factory=dict)
59
+
60
+ def add_transformation(self, transformation_obj: Transform) -> None:
61
+ """Adds a transformation object to a node.
62
+
63
+ Args:
64
+ transformation_obj: The Transform to be added to the node.
65
+
66
+ Returns:
67
+ None
68
+ """
69
+
70
+ self.transformations[transformation_obj.uid] = transformation_obj
71
+
72
+ def add_input_output_transformation(self, input_port: Port, output_port: Port, input_weight: float) -> None:
73
+ """Adds an input/output transformation to this node.
74
+
75
+ Args:
76
+ input_port: The input port for the transformation
77
+ output_port: The output port for the transformation
78
+ input_weight: The weighting for the TransformTerm of the input port.
79
+
80
+ Returns:
81
+ None
82
+
83
+ """
84
+
85
+ lhs_terms = [
86
+ TransformTerm(var=output_port, rule=TransformRule.Both, weight=1),
87
+ TransformTerm(var=input_port, rule=TransformRule.Both, weight=-input_weight),
88
+ ]
89
+
90
+ t = Transform(lhs_terms=lhs_terms)
91
+
92
+ self.add_transformation(t)
93
+
94
+ def add_emission_transformation(self, emitting_port: Port, carbon_port: Port, emission_factor: float) -> None:
95
+ """Creates an emission transformation and adds to the node.
96
+
97
+ Args:
98
+ emitting_port: port object that generates emissions when exporting (when negative)
99
+ carbon_port: port object that represents carbon flows out of the node
100
+ emission_factor: a ratio = emissions generated/emitting unit generated (float), or an array of values
101
+
102
+ Returns:
103
+ None
104
+ """
105
+
106
+ lhs_terms = [
107
+ TransformTerm(var=carbon_port, rule=TransformRule.Neg, weight=1),
108
+ TransformTerm(var=emitting_port, rule=TransformRule.Neg, weight=-emission_factor),
109
+ ]
110
+
111
+ t = Transform(lhs_terms=lhs_terms)
112
+
113
+ self.add_transformation(t)
114
+
115
+ def verify_node(self) -> None:
116
+ """Checks if the node has ports (super), and if the node has transformations.
117
+
118
+ Returns:
119
+ None
120
+
121
+ Raises:
122
+ ConfigurationError: If no transformations are associated with this node.
123
+ """
124
+
125
+ super().verify_node()
126
+
127
+ if not self.transformations:
128
+ raise ConfigurationError("Node has Transform rule but Transformation object(s) has not been added to node.")
129
+
130
+ def apply_node_constraints(self, model: EchoConcreteModel) -> None:
131
+ """Add the constraints assoicated with this node to a concrete model.
132
+
133
+ Args:
134
+ model: The concrete model the constraints associated with this node will be added to.
135
+
136
+ """
137
+
138
+ def transform(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
139
+ """Generate a transform rule for a generic transformation node.
140
+
141
+ Args:
142
+ model: The concrete model from which to draw data.
143
+ p: Index representing capacity expansion
144
+ t: Index representing time.
145
+
146
+ Returns:
147
+ EqualityExpression: The transform rule.
148
+
149
+ Raises:
150
+ Exception: If an improper TransformRule is used.
151
+ """
152
+
153
+ lhs = 0
154
+
155
+ for term in current_transform.lhs:
156
+ weight = expand_as_array(
157
+ TimeSeriesData(
158
+ value=term.weight,
159
+ num_expansion_intervals=len(model.Expansion),
160
+ num_time_intervals=len(model.Time),
161
+ )
162
+ )
163
+
164
+ rule = term.rule
165
+
166
+ if rule is TransformRule.Both:
167
+ var_name = term.var.port_name
168
+ elif rule is TransformRule.Pos:
169
+ var_name = term.var.pos
170
+ elif rule is TransformRule.Neg:
171
+ var_name = term.var.neg
172
+ else:
173
+ raise Exception(f"Unsupported transform rule {rule} for term {term}")
174
+
175
+ lhs += getattr(model, var_name)[p, t] * weight[p, t]
176
+
177
+ return lhs == current_transform.rhs
178
+
179
+ for current_transform in self.transformations.values():
180
+ current_transform._add_transform_to_model(model) # make sure that all variables have been initialised
181
+ con_name = "transformation_con_" + self.node_name
182
+ setattr(
183
+ model,
184
+ con_name,
185
+ en.Constraint(model.Expansion, model.Time, rule=transform),
186
+ )
@@ -0,0 +1,7 @@
1
+ import numpy as np
2
+
3
+ from echo.validators import ArrayType
4
+
5
+ ConstraintValueType = ArrayType | list | float | int
6
+ InitialValue = dict[tuple[int, int], int | float]
7
+ InitialValueInput = InitialValue | list[int | float] | np.ndarray
@@ -0,0 +1,4 @@
1
+ from echo.models.carbon.aggregation import CarbonAggregation
2
+ from echo.models.carbon.base import CarbonPort, CarbonSink, CarbonSource
3
+
4
+ __all__ = ["CarbonAggregation", "CarbonPort", "CarbonSink", "CarbonSource"]
@@ -0,0 +1,33 @@
1
+ import pandas as pd
2
+ import pyomo.environ as en
3
+ from attrs import define
4
+ from pyomo.core.expr import EqualityExpression
5
+
6
+ from echo.models.base import Node
7
+ from echo.models.scenario import EchoConcreteModel
8
+
9
+
10
+ @define
11
+ class CarbonAggregation(Node):
12
+ """This node has an additional variable, 'total', which equals the sum of all ports defined on the node."""
13
+
14
+ @property
15
+ def total(self) -> str:
16
+ return "total_CO2_" + self.node_name
17
+
18
+ def verify_node(self) -> None:
19
+ super().verify_node()
20
+
21
+ def add_node_to_model(self, model: EchoConcreteModel, profile: pd.DataFrame) -> None:
22
+ super().add_node_to_model(model, profile)
23
+ # Create a variable for the total CO2
24
+ setattr(model, self.total, en.Var(model.Expansion, model.Time, initialize=0, domain=en.Reals))
25
+
26
+ def apply_node_constraints(self, model: EchoConcreteModel) -> None:
27
+ def sum_rule(model: EchoConcreteModel, p: int, t: int) -> EqualityExpression:
28
+ a = 0
29
+ for port in self.ports.values():
30
+ a += getattr(model, port.port_name)[p, t]
31
+ return getattr(model, self.total)[p, t] == a
32
+
33
+ setattr(model, "co2_sum_con_" + self.node_name, en.Constraint(model.Expansion, model.Time, rule=sum_rule))
@@ -0,0 +1,25 @@
1
+ from attrs import define
2
+
3
+ from echo.configuration import Flows, Units
4
+ from echo.models.agnostic import FlexPort
5
+
6
+
7
+ @define
8
+ class CarbonPort(FlexPort):
9
+ """A flexible carbon port"""
10
+
11
+ units: Units = Units.CO2
12
+
13
+
14
+ @define
15
+ class CarbonSource(CarbonPort):
16
+ """A variable source of CO2"""
17
+
18
+ flows: Flows = Flows.Export
19
+
20
+
21
+ @define
22
+ class CarbonSink(CarbonPort):
23
+ """A variable sink of CO2"""
24
+
25
+ flows: Flows = Flows.Import
@@ -0,0 +1,35 @@
1
+ from echo.models.electrical.base import (
2
+ BoundedElectricalLoad,
3
+ ElectricalDemand,
4
+ ElectricalPort,
5
+ ElectricalStorage,
6
+ FixedElectricalPort,
7
+ )
8
+ from echo.models.electrical.ev import (
9
+ EVV0G,
10
+ EVV1G,
11
+ EVV2G,
12
+ EVBase,
13
+ EVWithProfile,
14
+ MobileElectricalStorage,
15
+ )
16
+ from echo.models.electrical.ev.deprecated import EV
17
+ from echo.models.electrical.generation import ElectricalGeneration
18
+ from echo.models.electrical.inverter import Inverter
19
+
20
+ __all__ = [
21
+ "BoundedElectricalLoad",
22
+ "ElectricalDemand",
23
+ "ElectricalGeneration",
24
+ "ElectricalPort",
25
+ "ElectricalStorage",
26
+ "EV",
27
+ "EVBase",
28
+ "EVWithProfile",
29
+ "EVV0G",
30
+ "EVV1G",
31
+ "EVV2G",
32
+ "FixedElectricalPort",
33
+ "Inverter",
34
+ "MobileElectricalStorage",
35
+ ]
@@ -0,0 +1,37 @@
1
+ from attrs import define
2
+
3
+ from echo.configuration import (
4
+ Units,
5
+ )
6
+ from echo.models.agnostic import BoundedLoad, Demand, FixedPort, FlexPort, Storage
7
+
8
+
9
+ @define
10
+ class ElectricalDemand(Demand):
11
+ """Fixed electrical demand."""
12
+
13
+ units: Units = Units.KW
14
+
15
+
16
+ @define
17
+ class ElectricalPort(FlexPort):
18
+ """Flexible electrical port"""
19
+
20
+ units: Units = Units.KW
21
+
22
+
23
+ @define
24
+ class FixedElectricalPort(FixedPort):
25
+ """An electrical port with fixed values (parameters). No constraints on whether the port is importing/exporting."""
26
+
27
+ units: Units = Units.KW
28
+
29
+
30
+ @define
31
+ class ElectricalStorage(Storage):
32
+ units: Units = Units.KW
33
+
34
+
35
+ @define
36
+ class BoundedElectricalLoad(BoundedLoad):
37
+ units: Units = Units.KW
@@ -0,0 +1,14 @@
1
+ from echo.models.electrical.ev.base import EVBase, MobileElectricalStorage
2
+ from echo.models.electrical.ev.ev_with_profile import EVWithProfile
3
+ from echo.models.electrical.ev.v0g import EVV0G
4
+ from echo.models.electrical.ev.v1g import EVV1G
5
+ from echo.models.electrical.ev.v2g import EVV2G
6
+
7
+ __all__ = [
8
+ "EVBase",
9
+ "EVWithProfile",
10
+ "EVV0G",
11
+ "EVV1G",
12
+ "EVV2G",
13
+ "MobileElectricalStorage",
14
+ ]
@@ -0,0 +1,340 @@
1
+ import numpy as np
2
+ from attrs import define, field
3
+
4
+ from echo.configuration import (
5
+ EVChargeMode,
6
+ FlowConstraint,
7
+ Flows,
8
+ OptimisationType,
9
+ TransformRule,
10
+ Units,
11
+ )
12
+ from echo.exceptions import ConfigurationError, validate
13
+ from echo.models.agnostic import MobileStorage
14
+ from echo.models.base import Transform, TransformNode, TransformTerm
15
+ from echo.models.electrical.base import ElectricalDemand, ElectricalPort
16
+ from echo.utils import TimeExpandableType
17
+ from echo.validators import ArrayType
18
+
19
+
20
+ @define
21
+ class MobileElectricalStorage(MobileStorage):
22
+ units: Units = Units.KW
23
+
24
+
25
+ @define
26
+ class EVBase(TransformNode):
27
+ """Base class for EVV0G, EVV1G and EVV2G.
28
+
29
+ Args:
30
+ available (ArrayType | list | str | None): A List or ArrayType of bools representing the ability for the
31
+ EV to charge. The bools can have values of [False, True] or [0, 1]. 0 and False indicate the EV is not
32
+ available for charging, 1 and True indicate the EV is available for charging. If
33
+ set_state_attrs_at_init is True, this must be supplied. If set_stateful_attrs_at_init is False, this must
34
+ be provided later using set_stateful_attrs(). ArrayType | list represents data, while a str represents the
35
+ column name in a pandas dataframe.
36
+ charge_mode (EVChargeMode | None): Charge mode of the EV. This is set upon instantiation of EV child classes.
37
+ Defaults to None.
38
+ charging_efficiency (float | None): The efficiency of the battery charging process for the EV. Float as
39
+ a fraction between 0.0 and 1.0 inclusive. Unitless. Defaults to 1.0.
40
+ charging_power_limit (float): The maximum charging rate of the EV's battery. Positive float in power units.
41
+ connection_point_name (str | None): Name of connection point port. Defaults to "cp".
42
+ depth_of_discharge_limit (float, optional): The minimum value of the state of ElectricalStorage of the EV. Same
43
+ as min_soc but expressed as percentage, not energy. Float as a percentage (of max_capacity) between 0.0
44
+ and 100.0. Unitless. Defaults to 0.0.
45
+ discharging_efficiency (float | None): The efficiency of the battery discharging process for the EV. Float as
46
+ a fraction between 0.0 and 1.0 inclusive. Unitless. Defaults to 1.0.
47
+ discharging_power_limit (float): The maximum discharging rate of the EV's battery. This includes
48
+ discharging for travelling and V2G actions. If usage_power_limit is set then
49
+ discharging_power_limit represents maximum V2G generation power only. Negative float in power units.
50
+ enable_trip_slack (bool | None): Enabling trip slack allows the EV to meet usage requirements even if
51
+ other constraints/requirements are breached. That is, it allows the state of charge of the EV's battery
52
+ to go below min to avoid the optimisation failing due to infeasible EV trips. For example, an EV can
53
+ complete a journey requiring 20 kWh of energy if though there is only 15 kWh of energy in the EV
54
+ battery. Setting enable_trip_slack to True will introduce additional energy into the system, though
55
+ there is a cost to do so. This can cause issues when conducting analysis on systems with
56
+ enable_trip_slack=True, so use with caution. Defaults to False.
57
+ initial_state_of_charge (float | None): The initial charge present in the EV's battery. If
58
+ set_state_attrs_at_init is True, this must be supplied. If set_stateful_attrs_at_init is False, it must be
59
+ provided later using set_stateful_attrs(). Positive float with units of energy (not percentage).
60
+ interval_duration(int): Length of time interval between time series data points. Used mostly for conversion
61
+ between power and energy. If set_stateful_attrs_at_init is False, this can be set after EV object
62
+ instantiation using self.set_state_attrs(). Units of minutes.
63
+ max_capacity (float): The storage capacity of the EV's battery. Positive float in energy units.
64
+ port_dict_name_to_port_name_map (dict[str, str] | None): Defines port name to port object map. It is recommended
65
+ not to use this unless you know what you are doing. If None, it will defined once ports are built. Defaults
66
+ to None.
67
+ port_dict_name_to_port_uid_map (dict[str, str] | None): Defines port uid to port object map. It is recommended
68
+ not to use this unless you know what you are doing. If None, it will defined once ports are built. Defaults
69
+ to None.
70
+ set_stateful_attrs_at_init (bool | None): Set attributes with state at object instantiation (True) or
71
+ defer to later (False). If deferring to later, self.set_stateful_attrs() must be used to set these
72
+ attributes. Attributes with state are available and initial_state_of_charge. Defaults to True.
73
+ soc_conserv (TimeExpandableType | None): Conservative state of charge limit below which the EV should not
74
+ discharge to the grid. This reflects that an EV owner would want to ensure a certain amount of charge is
75
+ available impromptu trips. This lower bound only applies while the EV is available to charge. Defaults to
76
+ None.
77
+ soc_conserv_cost (float | None): The cost placed on going below the conservative state of charge limit. That
78
+ is, the conservative state of charge lower limit will be ignored if it would result in saving (or gaining)
79
+ more money than this cost. Units of $/kWh. Defaults to None.
80
+ tod_charging (ArrayType | list | str | None): Time of day charging allows the EV to charge only during certain
81
+ time windows (1=allowed, 0=not allowed). Most commonly used with V0G charging. Defaults to None.
82
+ usage (ArrayType | list | None): An array representing the average power consumption from driving of the EV
83
+ during a time interval. Units of power.
84
+ usage_power_limit (float | None): The maximum power that can be used during an EV trip. If not None, it allows
85
+ discharging_power_limit to represent only the maximum power flow from an EVV2G back into an electrical
86
+ network, and not the maximum power output during a trip. Negative float in power units. Defaults to None,
87
+ however if None, it will be set to discharging_power_limit.
88
+ """
89
+
90
+ charge_mode: EVChargeMode | None = None
91
+ connection_port_name: str = "cp"
92
+ ports: dict[str, ElectricalDemand | ElectricalPort | MobileElectricalStorage] = field(factory=dict)
93
+
94
+ # Battery attributes
95
+ charging_efficiency: float = 1
96
+ charging_power_limit: float = field(kw_only=True)
97
+ depth_of_discharge_limit: float = 0
98
+ discharging_efficiency: float = 1
99
+ discharging_power_limit: float = field(kw_only=True)
100
+ enable_trip_slack: bool = False
101
+ max_capacity: float = field(kw_only=True)
102
+ soc_conserv: TimeExpandableType | None = None
103
+ soc_conserv_cost: float | None = None
104
+ usage_power_limit: float | None = None
105
+
106
+ # Stateful attributes
107
+ available: ArrayType | list | None = None
108
+ initial_state_of_charge: float | None = None
109
+ interval_duration: int | None = None
110
+ set_stateful_attrs_at_init: bool = True
111
+ tod_charging: ArrayType | list | str | None = None
112
+ usage: ArrayType | list | None = None
113
+
114
+ # Helpful mappings for port names and uids
115
+ port_dict_name_to_port_name_map: dict[str, str] | None = None
116
+ port_dict_name_to_port_uid_map: dict[str, str] | None = None
117
+
118
+ def __attrs_post_init__(self) -> None:
119
+ # If usage_power_limit isn't specified, set it to discharging_power_limit. This is for backwards compatability
120
+ if self.usage_power_limit is None:
121
+ self.usage_power_limit = self.discharging_power_limit
122
+
123
+ def _check_stateful_attrs_are_not_none(self) -> None:
124
+ """Checks that the stateful attributes for EVBase and children are not None.
125
+
126
+ To be used node verifification before building a network.
127
+
128
+ Checks: self.available, self.usage, self.initial_state_of_charge, self.interval_duration.
129
+
130
+ Args:
131
+ None
132
+
133
+ Returns:
134
+ None
135
+
136
+ Raises:
137
+ ConfigurationError: if self.available is None.
138
+ ConfigurationError: if self.usage is None.
139
+ ConfigurationError: if self.initial_state_of_charge is None.
140
+ ConfigurationError: if self.interval_duration is None.
141
+ """
142
+
143
+ if self.available is None:
144
+ raise ConfigurationError(
145
+ f"The available attribute for {self.node_name} has not been set. Please use set_stateful_attrs()."
146
+ )
147
+
148
+ if self.usage is None:
149
+ raise ConfigurationError(
150
+ f"The usage attribute for {self.node_name} has not been set. Please use set_stateful_attrs()."
151
+ )
152
+
153
+ if self.initial_state_of_charge is None:
154
+ raise ConfigurationError(
155
+ f"The initial_state_of_charge attribute for {self.node_name} has not been set. "
156
+ f"Please use set_stateful_attrs()."
157
+ )
158
+
159
+ if self.interval_duration is None:
160
+ raise ConfigurationError(
161
+ f"The interval_duration attribute for {self.node_name} has not been set. "
162
+ f"Please use set_stateful_attrs()."
163
+ )
164
+
165
+ def _check_usage_less_than_max_usage(self) -> None:
166
+ """Check that the maximum value in usage is not larger than the maximum usage rate.
167
+
168
+ If a value of usage is larger than max_usage_rate for an ev, this will result in an infeasible solution.
169
+
170
+ Args:
171
+ None
172
+
173
+ Returns:
174
+ None
175
+
176
+ Raises:
177
+ TypeError: if self.usage is None
178
+ ValueError: if the maximum power usage is greater than max_discharge_rate.
179
+ """
180
+
181
+ if self.usage is None:
182
+ raise TypeError("self.usage has not been set, it is still None.")
183
+
184
+ # Get the maximum power usage
185
+ max_usage = np.max(np.array(self.usage))
186
+
187
+ # Check that self.usage_power_limit is not None
188
+ if self.usage_power_limit is None:
189
+ raise ValueError("A value has not been assigned for self.usage_power_limit.")
190
+
191
+ # If the maximum power usage is larger than the usage power limit, raise an error.
192
+ if max_usage > self.usage_power_limit * -1:
193
+ raise ValueError(
194
+ f"Usage requirement of {max_usage} exceeds battery discharge limit of {self.usage_power_limit}."
195
+ )
196
+
197
+ def _create_usage_port(self) -> None:
198
+ """Create a usage port and add it to the EV's ports list.
199
+
200
+ Args:
201
+ None
202
+
203
+ Returns:
204
+ None
205
+ """
206
+
207
+ # Create the usage port and assign it to the EV object
208
+ # Usage ports are not connected to other ports via edges so we set `allow_dangling_port` to True
209
+ self.ports["usage"] = ElectricalDemand(allow_dangling_port=True)
210
+
211
+ # TODO: Set demand here if set_stateful_attrs_at_init is True
212
+
213
+ def _create_vehicle_port(self) -> None:
214
+ """Create a vehicle port and add it to the EV's ports list.
215
+
216
+ Args:
217
+ None
218
+
219
+ Returns:
220
+ None
221
+ """
222
+
223
+ # Check that attributes with state are not None if set_state_attrs_at_init is True
224
+ if self.set_stateful_attrs_at_init:
225
+ self._check_stateful_attrs_are_not_none()
226
+
227
+ # Create the usage port and assign it to the EV object
228
+ self.ports["vehicle"] = MobileElectricalStorage(
229
+ charging_power_limit=self.charging_power_limit,
230
+ discharging_power_limit=self.usage_power_limit,
231
+ initial_state_of_charge=self.initial_state_of_charge,
232
+ max_capacity=self.max_capacity,
233
+ available=self.available,
234
+ charging_efficiency=self.charging_efficiency,
235
+ depth_of_discharge_limit=self.depth_of_discharge_limit,
236
+ discharging_efficiency=self.discharging_efficiency,
237
+ enable_trip_slack=self.enable_trip_slack,
238
+ soc_conserv=self.soc_conserv,
239
+ soc_conserv_cost=self.soc_conserv_cost,
240
+ allow_dangling_port=True, # vehicle port is not connect to another port
241
+ )
242
+
243
+ def _create_connection_point_port(self) -> None:
244
+ """Create a connection point port and add it to the EV's ports list.
245
+
246
+ Args:
247
+ None
248
+
249
+ Returns:
250
+ None
251
+
252
+ """
253
+
254
+ self.ports[self.connection_port_name] = ElectricalPort(
255
+ flows=Flows.Both,
256
+ import_constraint=FlowConstraint.NoConstraint,
257
+ flow_type=OptimisationType.Variable,
258
+ units=Units.KW,
259
+ export_constraint=FlowConstraint.Fixed,
260
+ export_constraint_value=self.discharging_power_limit,
261
+ )
262
+
263
+ def _create_ev_transformation(self) -> Transform:
264
+ """Creates the appropriate transformation for EV objects: vehicle = connection_point - usage.
265
+
266
+ Args:
267
+ None
268
+
269
+ Returns:
270
+ The left hand side of the equation of the linear node transformation. The right hand side is 0.
271
+ """
272
+
273
+ lhs_terms = [
274
+ TransformTerm(var=self.ports["vehicle"], rule=TransformRule.Both, weight=1),
275
+ TransformTerm(var=self.ports["usage"], rule=TransformRule.Both, weight=1),
276
+ TransformTerm(
277
+ var=self.ports[self.connection_port_name],
278
+ rule=TransformRule.Both,
279
+ weight=-1,
280
+ ),
281
+ ]
282
+ return Transform(lhs_terms=lhs_terms)
283
+
284
+ def verify_node(self) -> None:
285
+ """Checks data with state has been set for the node and each port.
286
+
287
+ Args:
288
+ None
289
+
290
+ Returns:
291
+ None
292
+ """
293
+
294
+ super().verify_node()
295
+
296
+ # Check node properties
297
+ self._check_stateful_attrs_are_not_none()
298
+ self._verify_ports()
299
+
300
+ def _verify_ports(self) -> None:
301
+ """Checks data with state has been set for each port.
302
+
303
+ Args:
304
+ None
305
+
306
+ Returns:
307
+ None
308
+ """
309
+
310
+ validate(
311
+ self.ports["usage"].initial_value != 0,
312
+ f"{self.node_name} usage port needs does not have a usage profile set.",
313
+ )
314
+ validate(
315
+ self.ports[self.connection_port_name].active_periods is not None,
316
+ f"{self.node_name} connection_point port does not have available set.",
317
+ )
318
+ validate(
319
+ (isinstance(self.ports["vehicle"], MobileElectricalStorage))
320
+ and (self.ports["vehicle"].initial_state_of_charge) is not None,
321
+ f"{self.node_name} vehicle port does not have a initial_state_of_charge set.",
322
+ )
323
+
324
+ def set_port_uid_maps(self) -> None:
325
+ """Sets the two maps for port names and port uids, if they aren't already set.
326
+
327
+ Args:
328
+ None
329
+
330
+ Returns:
331
+ None
332
+ """
333
+
334
+ # Set port_dict_name_to_port_uid_map
335
+ if self.port_dict_name_to_port_uid_map is None:
336
+ self.port_dict_name_to_port_uid_map = {port_name: port.uid for port_name, port in self.ports.items()}
337
+
338
+ # Set port_dict_name_to_port_name_map
339
+ if self.port_dict_name_to_port_name_map is None:
340
+ self.port_dict_name_to_port_name_map = {port_name: port.port_name for port_name, port in self.ports.items()}