Skip to content

odys.domain.conditions

Initial and final conditions of a run. Each condition references the asset it belongs to: GeneratorInitialState and GeneratorFinalState a generator, StorageInitialState and StorageFinalState a battery storage, and ElectricVehicleInitialState and ElectricVehicleFinalState an electric vehicle.

See Initial and final conditions in the User Guide.

Initial and final conditions of one optimization run.

An initial condition is the state of an asset just before the first timestep, such as the output of a generator or the state of charge of a battery. A final condition is a state the asset must reach at the last timestep. Conditions belong to one run, not to the asset or to a scenario: they are the same in every scenario and are passed to EnergySystem.

Each condition type references the kind of asset it belongs to, so it cannot be attached to the wrong kind of asset. An initial condition is required whenever the asset's results depend on it (required_for), so odys never guesses a starting state.

Condition

Bases: BaseModel, ABC

A state of one asset at the boundary of the optimization horizon.

Each condition type declares the asset types it applies to. Like entities, a condition is checked against the run through validate_horizon and validate_operating_conditions, which accept anything by default.

Source code in src/odys/domain/conditions.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class Condition(BaseModel, ABC):
    """A state of one asset at the boundary of the optimization horizon.

    Each condition type declares the asset types it applies to. Like entities,
    a condition is checked against the run through `validate_horizon` and
    `validate_operating_conditions`, which accept anything by default.
    """

    model_config = ConfigDict(frozen=True, extra="forbid")

    entity_types: ClassVar[tuple[type[Asset], ...]]

    @property
    @abstractmethod
    def entity(self) -> Asset:
        """Return the asset this condition belongs to."""

    def validate_horizon(self, horizon: Horizon) -> None:
        """Check that this condition fits the optimization horizon. The default accepts any horizon.

        Args:
            horizon: The time grid of the optimization.

        Raises:
            OdysValidationError: If the condition does not fit the horizon.
        """

    def validate_operating_conditions(self, conditions: OperatingConditions) -> None:
        """Check that this condition fits what its asset faces in one scenario. The default accepts anything.

        Args:
            conditions: The horizon and the asset's profile values in one scenario.

        Raises:
            OdysValidationError: If the condition cannot be met in that scenario.
        """

entity abstractmethod property

Return the asset this condition belongs to.

validate_horizon(horizon)

Check that this condition fits the optimization horizon. The default accepts any horizon.

Parameters:

Name Type Description Default
horizon Horizon

The time grid of the optimization.

required

Raises:

Type Description
OdysValidationError

If the condition does not fit the horizon.

Source code in src/odys/domain/conditions.py
54
55
56
57
58
59
60
61
62
def validate_horizon(self, horizon: Horizon) -> None:
    """Check that this condition fits the optimization horizon. The default accepts any horizon.

    Args:
        horizon: The time grid of the optimization.

    Raises:
        OdysValidationError: If the condition does not fit the horizon.
    """

validate_operating_conditions(conditions)

Check that this condition fits what its asset faces in one scenario. The default accepts anything.

Parameters:

Name Type Description Default
conditions OperatingConditions

The horizon and the asset's profile values in one scenario.

required

Raises:

Type Description
OdysValidationError

If the condition cannot be met in that scenario.

Source code in src/odys/domain/conditions.py
64
65
66
67
68
69
70
71
72
def validate_operating_conditions(self, conditions: OperatingConditions) -> None:
    """Check that this condition fits what its asset faces in one scenario. The default accepts anything.

    Args:
        conditions: The horizon and the asset's profile values in one scenario.

    Raises:
        OdysValidationError: If the condition cannot be met in that scenario.
    """

ConditionSet

Bases: BaseModel

The initial and final conditions of one optimization run.

Owns the rule that spans conditions: each asset has at most one condition of each type.

Source code in src/odys/domain/conditions.py
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
class ConditionSet(BaseModel):
    """The initial and final conditions of one optimization run.

    Owns the rule that spans conditions: each asset has at most one condition
    of each type.
    """

    model_config = ConfigDict(frozen=True, extra="forbid")

    initial: tuple[AnyInitialCondition, ...] = ()
    final: tuple[AnyFinalCondition, ...] = ()

    @model_validator(mode="after")
    def _validate_one_condition_per_asset_and_type(self) -> Self:
        counts = Counter((type(condition).__name__, condition.entity.name) for condition in self.conditions)
        duplicates = sorted(f"{kind} for '{name}'" for (kind, name), count in counts.items() if count > 1)
        if duplicates:
            msg = f"There is more than one condition: {', '.join(duplicates)}."
            raise OdysValidationError(msg)
        return self

    @property
    def conditions(self) -> tuple[Condition, ...]:
        """Return every initial condition, then every final condition."""
        return (*self.initial, *self.final)

    def get(self, kind: type[ConditionT], entity: Asset) -> ConditionT | None:
        """Return the condition of the given type for the asset, if there is one.

        Args:
            kind: The condition type, such as `GeneratorInitialState`.
            entity: The asset to look up.

        Returns:
            The asset's condition of that type, or None.
        """
        condition = self._by_type_and_asset_name.get((kind, entity.name))
        if not isinstance(condition, kind) or condition.entity != entity:
            return None
        return condition

    @cached_property
    def _by_type_and_asset_name(self) -> dict[tuple[type[Condition], str], Condition]:
        return {(type(condition), condition.entity.name): condition for condition in self.conditions}

conditions property

Return every initial condition, then every final condition.

get(kind, entity)

Return the condition of the given type for the asset, if there is one.

Parameters:

Name Type Description Default
kind type[ConditionT]

The condition type, such as GeneratorInitialState.

required
entity Asset

The asset to look up.

required

Returns:

Type Description
ConditionT | None

The asset's condition of that type, or None.

Source code in src/odys/domain/conditions.py
502
503
504
505
506
507
508
509
510
511
512
513
514
515
def get(self, kind: type[ConditionT], entity: Asset) -> ConditionT | None:
    """Return the condition of the given type for the asset, if there is one.

    Args:
        kind: The condition type, such as `GeneratorInitialState`.
        entity: The asset to look up.

    Returns:
        The asset's condition of that type, or None.
    """
    condition = self._by_type_and_asset_name.get((kind, entity.name))
    if not isinstance(condition, kind) or condition.entity != entity:
        return None
    return condition

ElectricVehicleFinalState

Bases: FinalCondition

State of charge an electric vehicle must have at the last timestep.

Source code in src/odys/domain/conditions.py
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
class ElectricVehicleFinalState(FinalCondition):
    """State of charge an electric vehicle must have at the last timestep."""

    entity_types: ClassVar[tuple[type[Asset], ...]] = (ElectricVehicle,)

    vehicle: ElectricVehicle
    soc: float = Field(strict=True, ge=0, le=1, description="State of charge as a fraction of capacity (0-1).")

    @model_validator(mode="after")
    def _validate_soc(self) -> Self:
        _validate_soc_within_battery_limits(self.vehicle.battery, self.soc, type(self).__name__, self.vehicle.name)
        return self

    @property
    def entity(self) -> ElectricVehicle:
        """Return the electric vehicle this state belongs to."""
        return self.vehicle

entity property

Return the electric vehicle this state belongs to.

ElectricVehicleInitialState

Bases: InitialCondition

State of charge of an electric vehicle just before the first timestep. Always required.

A trip departing at t=0 must not require more state of charge than soc, and its energy must fit in the starting charge above soc_min, since the vehicle cannot charge before or during it.

Source code in src/odys/domain/conditions.py
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
class ElectricVehicleInitialState(InitialCondition):
    """State of charge of an electric vehicle just before the first timestep. Always required.

    A trip departing at t=0 must not require more state of charge than `soc`,
    and its energy must fit in the starting charge above `soc_min`, since the
    vehicle cannot charge before or during it.
    """

    entity_types: ClassVar[tuple[type[Asset], ...]] = (ElectricVehicle,)

    vehicle: ElectricVehicle
    soc: float = Field(strict=True, ge=0, le=1, description="State of charge as a fraction of capacity (0-1).")

    @model_validator(mode="after")
    def _validate_soc(self) -> Self:
        _validate_soc_within_battery_limits(self.vehicle.battery, self.soc, type(self).__name__, self.vehicle.name)
        return self

    @model_validator(mode="after")
    def _validate_min_soc_at_departure_feasible(self) -> Self:
        for trip in self.vehicle.trips:
            if trip.start_time == timedelta(0) and trip.min_soc_at_departure > self.soc:
                msg = (
                    f"Trip '{trip.name}' for vehicle '{self.vehicle.name}' departs at t=0 with "
                    f"min_soc_at_departure={trip.min_soc_at_departure} > initial soc={self.soc}"
                )
                raise OdysValidationError(msg)
        return self

    @model_validator(mode="after")
    def _validate_starting_charge_covers_trip_at_t0(self) -> Self:
        battery = self.vehicle.battery
        available_energy = (self.soc - battery.soc_min) * battery.capacity
        for trip in self.vehicle.trips:
            if trip.start_time != timedelta(0):
                continue
            if trip.energy_consumption > available_energy and not math.isclose(
                trip.energy_consumption,
                available_energy,
            ):
                msg = (
                    f"Trip '{trip.name}' for vehicle '{self.vehicle.name}' departs at t=0 and consumes "
                    f"{trip.energy_consumption:.6g} MWh, but the battery holds only {available_energy:.6g} MWh "
                    f"above soc_min at the start (initial soc={self.soc}, soc_min={battery.soc_min}, "
                    f"capacity={battery.capacity} MWh); it cannot charge before or during the trip."
                )
                raise OdysValidationError(msg)
        return self

    @classmethod
    def required_for(cls, entity: Asset) -> str | None:
        """Return why an electric vehicle needs an initial state: its charge carries over between timesteps."""
        if not isinstance(entity, ElectricVehicle):
            return None
        return "its state of charge carries over from one timestep to the next"

    @property
    def entity(self) -> ElectricVehicle:
        """Return the electric vehicle this state belongs to."""
        return self.vehicle

entity property

Return the electric vehicle this state belongs to.

required_for(entity) classmethod

Return why an electric vehicle needs an initial state: its charge carries over between timesteps.

Source code in src/odys/domain/conditions.py
432
433
434
435
436
437
@classmethod
def required_for(cls, entity: Asset) -> str | None:
    """Return why an electric vehicle needs an initial state: its charge carries over between timesteps."""
    if not isinstance(entity, ElectricVehicle):
        return None
    return "its state of charge carries over from one timestep to the next"

FinalCondition

Bases: Condition, ABC

The state an asset must reach at the last timestep.

Source code in src/odys/domain/conditions.py
91
92
class FinalCondition(Condition, ABC):
    """The state an asset must reach at the last timestep."""

FlexibleLoadInitialState

Bases: InitialCondition

Consumption of a flexible load just before the first timestep, and how long it has been on or off.

A load with a commitment is off if power is 0 and running otherwise; a load without one is always running. A running power lies within the load's min_load and max_load. time_in_state is how long a load with a commitment has been in its state; it carries the minimum up or down time over from before the horizon, and is required when the matching minimum time is set.

Source code in src/odys/domain/conditions.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
class FlexibleLoadInitialState(InitialCondition):
    """Consumption of a flexible load just before the first timestep, and how long it has been on or off.

    A load with a commitment is off if `power` is 0 and running otherwise; a
    load without one is always running. A running `power` lies within the
    load's `min_load` and `max_load`. `time_in_state` is how long a load with a
    commitment has been in its state; it carries the minimum up or down time
    over from before the horizon, and is required when the matching minimum
    time is set.
    """

    entity_types: ClassVar[tuple[type[Asset], ...]] = (FlexibleLoad,)

    load: FlexibleLoad
    power: float = Field(strict=True, ge=0, description="Consumption just before the first timestep, in MW.")
    time_in_state: timedelta | None = Field(
        default=None,
        strict=True,
        gt=timedelta(0),
        description="How long the load has been running (power > 0) or off (power = 0). Only with a commitment.",
    )

    @model_validator(mode="after")
    def _validate_power_within_load_limits(self) -> Self:
        if not self.is_on:
            return self
        min_load, max_load = self.load.min_load, self.load.max_load
        if (min_load is not None and self.power < min_load) or (max_load is not None and self.power > max_load):
            off = "either off (0) or " if self.load.commitment is not None else ""
            msg = (
                f"FlexibleLoadInitialState for flexible load '{self.load.name}' has power={self.power}, but the "
                f"load is {off}between min_load ({min_load}) and max_load ({max_load})."
            )
            raise OdysValidationError(msg)
        return self

    @model_validator(mode="after")
    def _validate_time_in_state(self) -> Self:
        if self.load.commitment is None:
            if self.time_in_state is not None:
                msg = (
                    f"FlexibleLoadInitialState for flexible load '{self.load.name}' has time_in_state, but the load "
                    "has no commitment, so it is always running."
                )
                raise OdysValidationError(msg)
            return self
        _validate_time_in_state_given_with_min_time(
            self.load.commitment,
            is_on=self.is_on,
            time_in_state=self.time_in_state,
            subject=f"{type(self).__name__} for flexible load '{self.load.name}'",
            entity_kind="flexible load",
        )
        return self

    def validate_horizon(self, horizon: Horizon) -> None:
        """Check that the time in state spans a whole number of timesteps.

        Args:
            horizon: The time grid of the optimization.

        Raises:
            OdysValidationError: If the time in state is not a whole number of timesteps.
        """
        if self.time_in_state is not None and not horizon.is_whole_steps(self.time_in_state):
            msg = (
                f"FlexibleLoadInitialState for flexible load '{self.load.name}' has "
                f"time_in_state={self.time_in_state}, which is not a whole number of timesteps "
                f"({horizon.timestep})."
            )
            raise OdysValidationError(msg)

    @classmethod
    def required_for(cls, entity: Asset) -> str | None:
        """Return why a flexible load needs an initial state: a parameter linking one timestep to the next is set."""
        if not isinstance(entity, FlexibleLoad):
            return None
        return _time_coupling_reason(entity.ramp_up, entity.ramp_down, entity.commitment)

    @property
    def is_on(self) -> bool:
        """Return whether the load is running just before the first timestep: always without a commitment."""
        return self.load.commitment is None or self.power > 0

    @property
    def entity(self) -> FlexibleLoad:
        """Return the flexible load this state belongs to."""
        return self.load

entity property

Return the flexible load this state belongs to.

is_on property

Return whether the load is running just before the first timestep: always without a commitment.

required_for(entity) classmethod

Return why a flexible load needs an initial state: a parameter linking one timestep to the next is set.

Source code in src/odys/domain/conditions.py
320
321
322
323
324
325
@classmethod
def required_for(cls, entity: Asset) -> str | None:
    """Return why a flexible load needs an initial state: a parameter linking one timestep to the next is set."""
    if not isinstance(entity, FlexibleLoad):
        return None
    return _time_coupling_reason(entity.ramp_up, entity.ramp_down, entity.commitment)

validate_horizon(horizon)

Check that the time in state spans a whole number of timesteps.

Parameters:

Name Type Description Default
horizon Horizon

The time grid of the optimization.

required

Raises:

Type Description
OdysValidationError

If the time in state is not a whole number of timesteps.

Source code in src/odys/domain/conditions.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
def validate_horizon(self, horizon: Horizon) -> None:
    """Check that the time in state spans a whole number of timesteps.

    Args:
        horizon: The time grid of the optimization.

    Raises:
        OdysValidationError: If the time in state is not a whole number of timesteps.
    """
    if self.time_in_state is not None and not horizon.is_whole_steps(self.time_in_state):
        msg = (
            f"FlexibleLoadInitialState for flexible load '{self.load.name}' has "
            f"time_in_state={self.time_in_state}, which is not a whole number of timesteps "
            f"({horizon.timestep})."
        )
        raise OdysValidationError(msg)

GeneratorFinalState

Bases: FinalCondition

Output a generator must have at the last timestep. A power of 0 means it is off.

Source code in src/odys/domain/conditions.py
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
class GeneratorFinalState(FinalCondition):
    """Output a generator must have at the last timestep. A power of 0 means it is off."""

    entity_types: ClassVar[tuple[type[Asset], ...]] = (Generator,)

    generator: Generator
    power: float = Field(strict=True, ge=0, description="Output at the last timestep, in MW.")

    @model_validator(mode="after")
    def _validate_power(self) -> Self:
        _validate_generator_power(self.generator, self.power, type(self).__name__)
        return self

    def validate_operating_conditions(self, conditions: OperatingConditions) -> None:
        """Check that the final power fits the generator's available capacity at the last timestep.

        Args:
            conditions: The horizon and the generator's available capacity in one scenario.

        Raises:
            OdysValidationError: If the final power exceeds the available capacity at the last timestep.
        """
        last_capacity = self.generator.max_supply(conditions)[-1]
        if self.power > last_capacity:
            msg = (
                f"GeneratorFinalState for generator '{self.generator.name}' has power={self.power}, "
                f"above its available capacity ({last_capacity}) at the last timestep."
            )
            raise OdysValidationError(msg)

    @property
    def entity(self) -> Generator:
        """Return the generator this state belongs to."""
        return self.generator

entity property

Return the generator this state belongs to.

validate_operating_conditions(conditions)

Check that the final power fits the generator's available capacity at the last timestep.

Parameters:

Name Type Description Default
conditions OperatingConditions

The horizon and the generator's available capacity in one scenario.

required

Raises:

Type Description
OdysValidationError

If the final power exceeds the available capacity at the last timestep.

Source code in src/odys/domain/conditions.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
def validate_operating_conditions(self, conditions: OperatingConditions) -> None:
    """Check that the final power fits the generator's available capacity at the last timestep.

    Args:
        conditions: The horizon and the generator's available capacity in one scenario.

    Raises:
        OdysValidationError: If the final power exceeds the available capacity at the last timestep.
    """
    last_capacity = self.generator.max_supply(conditions)[-1]
    if self.power > last_capacity:
        msg = (
            f"GeneratorFinalState for generator '{self.generator.name}' has power={self.power}, "
            f"above its available capacity ({last_capacity}) at the last timestep."
        )
        raise OdysValidationError(msg)

GeneratorInitialState

Bases: InitialCondition

Output of a generator just before the first timestep, and how long it has been on or off.

The generator is on if power is above 0 and off if it is 0. time_in_state is how long it has been in that state; it carries the minimum up or down time over from before the horizon, and is required when the matching minimum time is set.

Source code in src/odys/domain/conditions.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
class GeneratorInitialState(InitialCondition):
    """Output of a generator just before the first timestep, and how long it has been on or off.

    The generator is on if `power` is above 0 and off if it is 0. `time_in_state`
    is how long it has been in that state; it carries the minimum up or down
    time over from before the horizon, and is required when the matching
    minimum time is set.
    """

    entity_types: ClassVar[tuple[type[Asset], ...]] = (Generator,)

    generator: Generator
    power: float = Field(strict=True, ge=0, description="Output just before the first timestep, in MW.")
    time_in_state: timedelta | None = Field(
        default=None,
        strict=True,
        gt=timedelta(0),
        description="How long the generator has been on (power > 0) or off (power = 0).",
    )

    @model_validator(mode="after")
    def _validate_power(self) -> Self:
        _validate_generator_power(self.generator, self.power, type(self).__name__)
        return self

    @model_validator(mode="after")
    def _validate_time_in_state_given_with_min_time(self) -> Self:
        _validate_time_in_state_given_with_min_time(
            self.generator.commitment,
            is_on=self.is_on,
            time_in_state=self.time_in_state,
            subject=f"{type(self).__name__} for generator '{self.generator.name}'",
            entity_kind="generator",
        )
        return self

    def validate_horizon(self, horizon: Horizon) -> None:
        """Check that the time in state spans a whole number of timesteps.

        Args:
            horizon: The time grid of the optimization.

        Raises:
            OdysValidationError: If the time in state is not a whole number of timesteps.
        """
        if self.time_in_state is not None and not horizon.is_whole_steps(self.time_in_state):
            msg = (
                f"GeneratorInitialState for generator '{self.generator.name}' has "
                f"time_in_state={self.time_in_state}, which is not a whole number of timesteps "
                f"({horizon.timestep})."
            )
            raise OdysValidationError(msg)

    @classmethod
    def required_for(cls, entity: Asset) -> str | None:
        """Return why a generator needs an initial state: a parameter linking one timestep to the next is set."""
        if not isinstance(entity, Generator):
            return None
        return _time_coupling_reason(entity.ramp_up, entity.ramp_down, entity.commitment)

    @property
    def is_on(self) -> bool:
        """Return whether the generator is on just before the first timestep."""
        return self.power > 0

    @property
    def entity(self) -> Generator:
        """Return the generator this state belongs to."""
        return self.generator

entity property

Return the generator this state belongs to.

is_on property

Return whether the generator is on just before the first timestep.

required_for(entity) classmethod

Return why a generator needs an initial state: a parameter linking one timestep to the next is set.

Source code in src/odys/domain/conditions.py
194
195
196
197
198
199
@classmethod
def required_for(cls, entity: Asset) -> str | None:
    """Return why a generator needs an initial state: a parameter linking one timestep to the next is set."""
    if not isinstance(entity, Generator):
        return None
    return _time_coupling_reason(entity.ramp_up, entity.ramp_down, entity.commitment)

validate_horizon(horizon)

Check that the time in state spans a whole number of timesteps.

Parameters:

Name Type Description Default
horizon Horizon

The time grid of the optimization.

required

Raises:

Type Description
OdysValidationError

If the time in state is not a whole number of timesteps.

Source code in src/odys/domain/conditions.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
def validate_horizon(self, horizon: Horizon) -> None:
    """Check that the time in state spans a whole number of timesteps.

    Args:
        horizon: The time grid of the optimization.

    Raises:
        OdysValidationError: If the time in state is not a whole number of timesteps.
    """
    if self.time_in_state is not None and not horizon.is_whole_steps(self.time_in_state):
        msg = (
            f"GeneratorInitialState for generator '{self.generator.name}' has "
            f"time_in_state={self.time_in_state}, which is not a whole number of timesteps "
            f"({horizon.timestep})."
        )
        raise OdysValidationError(msg)

InitialCondition

Bases: Condition, ABC

The state of an asset just before the first timestep.

Source code in src/odys/domain/conditions.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class InitialCondition(Condition, ABC):
    """The state of an asset just before the first timestep."""

    @classmethod
    @abstractmethod
    def required_for(cls, entity: Asset) -> str | None:
        """Return why the asset needs this initial condition, or None if it is optional.

        Args:
            entity: An asset of one of this condition's `entity_types`.

        Returns:
            The reason, completing "needs a <condition> because ...", or None.
        """

required_for(entity) abstractmethod classmethod

Return why the asset needs this initial condition, or None if it is optional.

Parameters:

Name Type Description Default
entity Asset

An asset of one of this condition's entity_types.

required

Returns:

Type Description
str | None

The reason, completing "needs a because ...", or None.

Source code in src/odys/domain/conditions.py
78
79
80
81
82
83
84
85
86
87
88
@classmethod
@abstractmethod
def required_for(cls, entity: Asset) -> str | None:
    """Return why the asset needs this initial condition, or None if it is optional.

    Args:
        entity: An asset of one of this condition's `entity_types`.

    Returns:
        The reason, completing "needs a <condition> because ...", or None.
    """

StorageFinalState

Bases: FinalCondition

State of charge a battery storage must have at the last timestep.

Source code in src/odys/domain/conditions.py
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
class StorageFinalState(FinalCondition):
    """State of charge a battery storage must have at the last timestep."""

    entity_types: ClassVar[tuple[type[Asset], ...]] = (BatteryStorage,)

    storage: BatteryStorage
    soc: float = Field(strict=True, ge=0, le=1, description="State of charge as a fraction of capacity (0-1).")

    @model_validator(mode="after")
    def _validate_soc(self) -> Self:
        _validate_soc_within_battery_limits(self.storage.battery, self.soc, type(self).__name__, self.storage.name)
        return self

    @property
    def entity(self) -> BatteryStorage:
        """Return the battery storage this state belongs to."""
        return self.storage

entity property

Return the battery storage this state belongs to.

StorageInitialState

Bases: InitialCondition

State of charge of a battery storage just before the first timestep. Always required.

Source code in src/odys/domain/conditions.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
class StorageInitialState(InitialCondition):
    """State of charge of a battery storage just before the first timestep. Always required."""

    entity_types: ClassVar[tuple[type[Asset], ...]] = (BatteryStorage,)

    storage: BatteryStorage
    soc: float = Field(strict=True, ge=0, le=1, description="State of charge as a fraction of capacity (0-1).")

    @model_validator(mode="after")
    def _validate_soc(self) -> Self:
        _validate_soc_within_battery_limits(self.storage.battery, self.soc, type(self).__name__, self.storage.name)
        return self

    @classmethod
    def required_for(cls, entity: Asset) -> str | None:
        """Return why a battery storage needs an initial state: its charge carries over between timesteps."""
        if not isinstance(entity, BatteryStorage):
            return None
        return "its state of charge carries over from one timestep to the next"

    @property
    def entity(self) -> BatteryStorage:
        """Return the battery storage this state belongs to."""
        return self.storage

entity property

Return the battery storage this state belongs to.

required_for(entity) classmethod

Return why a battery storage needs an initial state: its charge carries over between timesteps.

Source code in src/odys/domain/conditions.py
351
352
353
354
355
356
@classmethod
def required_for(cls, entity: Asset) -> str | None:
    """Return why a battery storage needs an initial state: its charge carries over between timesteps."""
    if not isinstance(entity, BatteryStorage):
        return None
    return "its state of charge carries over from one timestep to the next"