Coverage for backend/common/models/idaes/unit_model_schema.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-11-06 23:27 +0000

1from __future__ import annotations 

2from pydantic import BaseModel, Field 

3from typing import Any, Dict, Union, Optional, Literal, NewType 

4 

5from typing_extensions import TypeAliasType 

6 

7from .id_types import UnitModelId, PortId, PropertyValueId 

8 

9class SolvedPropertyValueSchema(BaseModel): 

10 id: PropertyValueId 

11 name: str 

12 value: float | list[float] # Dynamics will have a list of values, rather than a single value. 

13 unit: str 

14 unknown_units: bool = False 

15 

16class PropertyValueSchema(BaseModel): 

17 id: PropertyValueId 

18 discrete_indexes: Optional[list[str]] = None 

19 value: Optional[float | list[float]] = None 

20 controlled: Optional[int] = None 

21 guess: bool = False 

22 constraint: Optional[str] = None 

23 

24class PropertySchema(BaseModel): 

25 data: list[PropertyValueSchema] 

26 unit: Optional[str] = "" 

27 

28 

29PropertiesSchema = Dict[str, "PropertySchema"] 

30 

31 

32class PortSchema(BaseModel): 

33 id: PortId 

34 properties: PropertiesSchema 

35 

36 

37PortsSchema = Dict[str, PortSchema] 

38 

39 

40class UnitModelSchema(BaseModel): 

41 id: UnitModelId 

42 type: str # eg. "pump", "heater", "mixer" 

43 name: str 

44 args: dict[str, Any] 

45 properties: PropertiesSchema 

46 ports: PortsSchema 

47 initial_values: Optional[dict[str, dict]] = Field(default_factory=dict) # IDAES initial values from their to_json method