Skip to content

state_schemas

State

Bases: BaseModel

Stores information about temperatures within cables at the final state.

The final state is reached at the end of the simulation. In addition, the relevant cable representations and their properties are stored.

Attributes:

Name Type Description
static_env_hash int

str: Deterministic hash of the static environment, used for validation and consistency checks.

temperature dict[CableKey, ndarray]

dict[CableKey, np.ndarray]: Combines the self-heating contribution with the ambient temperature profile and, for a StateSoil object, the mutual-heating contribution.

self_heating_contribution dict[CableKey, ndarray]

dict[CableKey, np.ndarray]: The temperature delta profile as a result of self-heating due to the load.

check_solution_consistency

check_solution_consistency()

Validate that temperature and self_heating_contribution share the same cable keys.

Source code in cable_thermal_model/model/schemas/state_schemas.py
57
58
59
60
61
62
63
64
65
66
67
68
@model_validator(mode="after")
def check_solution_consistency(self):
    """Validate that temperature and self_heating_contribution share the same cable keys."""
    keys_temperature = set(self.temperature.keys())
    keys_solution = set(self.self_heating_contribution.keys())
    if keys_temperature != keys_solution:
        raise ValueError(
            f"Inconsistent keys between temperature and self_heating_contribution. "
            f"Keys in temperature: {keys_temperature}, "
            f"keys in self_heating_contribution: {keys_solution}"
        )
    return self

serialize_temperature

serialize_temperature(arrays: dict[CableKey, ndarray]) -> dict[str, list[float]]

Serialize numpy arrays to lists for JSON compatibility.

Source code in cable_thermal_model/model/schemas/state_schemas.py
70
71
72
73
@field_serializer("temperature", "self_heating_contribution")
def serialize_temperature(self, arrays: dict[CableKey, np.ndarray]) -> dict[str, list[float]]:
    """Serialize numpy arrays to lists for JSON compatibility."""
    return _serialize_temperature_dict(arrays)

deserialize_temperature

deserialize_temperature(value: dict[str | CableKey, list[float] | ndarray]) -> dict[CableKey, ndarray]

Deserialize lists back to numpy arrays.

Source code in cable_thermal_model/model/schemas/state_schemas.py
75
76
77
78
79
80
@field_validator("temperature", "self_heating_contribution", mode="before")
def deserialize_temperature(
    cls, value: dict[str | CableKey, list[float] | np.ndarray]
) -> dict[CableKey, np.ndarray]:
    """Deserialize lists back to numpy arrays."""
    return _deserialize_temperature_dict(value)

StateSoil

Bases: State

Extends upon the base State class. Includes additional attribute mutual_heating_contribution and its validation.

Attributes:

Name Type Description
mutual_heating_contribution dict[CableKey, ndarray]

dict[CableKey, np.ndarray]: A dictionary containing the temperature increase inside a cable due to mutual heating from other cables in the environment. This is stored as a dict with CableKey as key and an array of temperature increases per grid point as value.

serialize_mutual_heating_contribution

serialize_mutual_heating_contribution(arrays: dict[CableKey, ndarray]) -> dict[str, list[float]]

Serialize mutual-heating arrays to lists for JSON compatibility.

Source code in cable_thermal_model/model/schemas/state_schemas.py
102
103
104
105
@field_serializer("mutual_heating_contribution")
def serialize_mutual_heating_contribution(self, arrays: dict[CableKey, np.ndarray]) -> dict[str, list[float]]:
    """Serialize mutual-heating arrays to lists for JSON compatibility."""
    return _serialize_temperature_dict(arrays)

deserialize_mutual_heating_contribution

deserialize_mutual_heating_contribution(value: dict[str | CableKey, list[float] | ndarray]) -> dict[CableKey, ndarray]

Deserialize lists back to numpy arrays for mutual-heating.

Source code in cable_thermal_model/model/schemas/state_schemas.py
107
108
109
110
111
112
@field_validator("mutual_heating_contribution", mode="before")
def deserialize_mutual_heating_contribution(
    cls, value: dict[str | CableKey, list[float] | np.ndarray]
) -> dict[CableKey, np.ndarray]:
    """Deserialize lists back to numpy arrays for mutual-heating."""
    return _deserialize_temperature_dict(value)

validate_mutual_heating_contribution

validate_mutual_heating_contribution()

Validate that mutual_heating_contribution keys match cable keys.

Source code in cable_thermal_model/model/schemas/state_schemas.py
114
115
116
117
118
119
120
121
122
123
124
@model_validator(mode="after")
def validate_mutual_heating_contribution(self):
    """Validate that mutual_heating_contribution keys match cable keys."""
    found_keys = set(self.mutual_heating_contribution.keys())
    expected_keys = set(self.temperature.keys())
    if found_keys != expected_keys:
        raise ValueError(
            "CableKeys of mutual_heating_contribution should match with cable_keys of temperature."
            f"Found keys: {found_keys}, expected keys: {expected_keys}"
        )
    return self

StateAir

Bases: State

StateAir has no added attributes on top of State.

However, we want to make sure there is only one circuit (check for a unique circuit_name).

validate_single_circuit

validate_single_circuit()

Ensure that all cable keys in StateAir belong to the same circuit.

Source code in cable_thermal_model/model/schemas/state_schemas.py
133
134
135
136
137
138
139
140
@model_validator(mode="after")
def validate_single_circuit(self):
    """Ensure that all cable keys in StateAir belong to the same circuit."""
    cable_keys = self.temperature.keys()
    circuit_names = {cable_key.circuit_name for cable_key in cable_keys}
    if len(circuit_names) > 1:
        raise ValueError(f"StateAir should only contain one circuit, but found multiple: {circuit_names}")
    return self