Skip to content

Commit cb181d7

Browse files
feat: added support to send modelica resource uri's as modifiers
1 parent bbd72d3 commit cb181d7

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

modelon/impact/client/experiment_definition/modifiers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import enum
33
from typing import Any, Union
44

5+
from modelon.impact.client.entities.file_uri import FileURI
6+
57
Scalar = Union[bool, int, float, str]
68

79

@@ -11,6 +13,7 @@ class DataType(enum.Enum):
1113
REAL = "REAL"
1214
STRING = "STRING"
1315
ENUMERATION = "ENUMERATION"
16+
FILEURI = "FILEURI"
1417

1518

1619
class Modifier(abc.ABC):
@@ -33,7 +36,9 @@ def to_dict(self, name: str) -> dict[str, Any]:
3336
return {
3437
"kind": "value",
3538
"name": name,
36-
"value": self.value,
39+
"value": str(self.value)
40+
if self.data_type == DataType.FILEURI
41+
else self.value,
3742
"dataType": self.data_type.value,
3843
}
3944

@@ -55,6 +60,8 @@ def data_type_from_value(value: Scalar) -> DataType:
5560
return DataType.REAL
5661
elif isinstance(value, str):
5762
return DataType.STRING
63+
elif isinstance(value, FileURI):
64+
return DataType.FILEURI
5865

5966
raise ValueError(f"Unsupported type for modifier value {value}")
6067

modelon/impact/client/experiment_definition/operators.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dataclasses import dataclass
66
from typing import Any, Optional, Union
77

8+
from modelon.impact.client.entities.file_uri import ModelicaResourceURI, URI
89
from modelon.impact.client.experiment_definition.modifiers import (
910
DataType,
1011
Enumeration,
@@ -143,16 +144,28 @@ def __str__(self) -> str:
143144
return f"choices({', '.join(map(str, self.values))})"
144145

145146
def to_dict(self, name: str) -> dict[str, Any]:
147+
values = (
148+
list(map(str, self.values))
149+
if self.data_type == DataType.FILEURI
150+
else list(self.values)
151+
)
146152
return {
147153
"kind": "choices",
148154
"name": name,
149-
"values": list(self.values),
155+
"values": values,
150156
"dataType": self.data_type.value,
151157
}
152158

153159
@classmethod
154160
def from_dict(cls, data: dict[str, Any]) -> Choices:
155-
return Choices(*data["values"], data_type=DataType(data["dataType"]))
161+
data_type = DataType(data["dataType"])
162+
values = [
163+
ModelicaResourceURI.from_uri(URI.from_str(value))
164+
if data_type == DataType.FILEURI
165+
else value
166+
for value in data["values"]
167+
]
168+
return Choices(*values, data_type=data_type)
156169

157170

158171
@dataclass

0 commit comments

Comments
 (0)