Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions modelon/impact/client/experiment_definition/modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import enum
from typing import Any, Union

Scalar = Union[bool, int, float, str]
from modelon.impact.client.entities.file_uri import FileURI

Scalar = Union[bool, int, float, str, FileURI]


class DataType(enum.Enum):
Expand All @@ -11,6 +13,7 @@ class DataType(enum.Enum):
REAL = "REAL"
STRING = "STRING"
ENUMERATION = "ENUMERATION"
FILEURI = "FILEURI"


class Modifier(abc.ABC):
Expand All @@ -33,7 +36,9 @@ def to_dict(self, name: str) -> dict[str, Any]:
return {
"kind": "value",
"name": name,
"value": self.value,
"value": str(self.value)
if self.data_type == DataType.FILEURI
else self.value,
"dataType": self.data_type.value,
}

Expand All @@ -55,6 +60,8 @@ def data_type_from_value(value: Scalar) -> DataType:
return DataType.REAL
elif isinstance(value, str):
return DataType.STRING
elif isinstance(value, FileURI):
return DataType.FILEURI

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

Expand Down
36 changes: 33 additions & 3 deletions modelon/impact/client/experiment_definition/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from dataclasses import dataclass
from typing import Any, Optional, Union

from modelon.impact.client.entities.file_uri import (
CustomArtifactURI,
ModelicaResourceURI,
get_resource_URI_from_str,
)
from modelon.impact.client.experiment_definition.modifiers import (
DataType,
Enumeration,
Expand Down Expand Up @@ -143,16 +148,26 @@ def __str__(self) -> str:
return f"choices({', '.join(map(str, self.values))})"

def to_dict(self, name: str) -> dict[str, Any]:
values = (
list(map(str, self.values))
if self.data_type == DataType.FILEURI
else list(self.values)
)
return {
"kind": "choices",
"name": name,
"values": list(self.values),
"values": values,
"dataType": self.data_type.value,
}

@classmethod
def from_dict(cls, data: dict[str, Any]) -> Choices:
return Choices(*data["values"], data_type=DataType(data["dataType"]))
data_type = DataType(data["dataType"])
values = [
get_resource_URI_from_str(value) if data_type == DataType.FILEURI else value
for value in data["values"]
]
return Choices(*values, data_type=data_type)


@dataclass
Expand Down Expand Up @@ -294,7 +309,20 @@ def from_dict(cls, data: dict[str, Any]) -> Normal:

def get_operator_from_dict(
data: dict[str, Any]
) -> Union[Range, Choices, Uniform, Beta, Normal, Enumeration, int, float, bool, str]:
) -> Union[
Range,
Choices,
Uniform,
Beta,
Normal,
Enumeration,
int,
float,
bool,
str,
ModelicaResourceURI,
CustomArtifactURI,
]:
kind = data["kind"]
if kind == "range":
return Range.from_dict(data)
Expand All @@ -310,6 +338,8 @@ def get_operator_from_dict(
data_type = DataType(data["dataType"])
if data_type == DataType.ENUMERATION:
return Enumeration(data["value"])
elif data_type == DataType.FILEURI:
return get_resource_URI_from_str(data["value"])
else:
return data["value"]
raise ValueError(f"Unsupported operator kind: {kind}!")
1 change: 0 additions & 1 deletion tests/impact/client/entities/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def test_get_custom_artifact(self, experiment):
artifact_stream = artifact.get_data()
assert artifact_stream == b"\x00\x00\x00\x00"

@pytest.mark.experimental
def test_get_custom_artifact_uri(self, experiment):
case = experiment.entity.get_case(IDs.CASE_ID_PRIMARY)
artifact = case.get_artifact(IDs.CUSTOM_ARTIFACT_ID)
Expand Down
1 change: 0 additions & 1 deletion tests/impact/client/entities/test_custom_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def _get_dynamic_cf(self, client_helper):
dynamic = workspace.get_custom_function("dynamic")
return dynamic

@pytest.mark.experimental
def test_custom_function_with_parameters_ok(self, custom_function):
workspace = create_workspace_entity(IDs.WORKSPACE_ID_PRIMARY)
experiment = create_experiment_entity(
Expand Down
1 change: 0 additions & 1 deletion tests/impact/client/entities/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def test_revoke_group_access_for_published_workspace(self):
IDs.PUBLISHED_WORKSPACE_ID, IDs.GROUP_NAME
)

@pytest.mark.experimental
def test_get_modelica_resource_uri(self):
service = mock.MagicMock()
workspace = create_workspace_entity(IDs.WORKSPACE_ID_PRIMARY, service=service)
Expand Down
2 changes: 0 additions & 2 deletions tests/impact/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def test_get_me(self, client_helper: ClientHelper):
assert user.last_name is None
assert user.email == IDs.MOCK_EMAIL

@pytest.mark.experimental
@pytest.mark.vcr()
def test_get_case_by_reference(self, client_helper: ClientHelper):
case_ref = create_case_reference(
Expand All @@ -244,7 +243,6 @@ def test_get_case_by_reference(self, client_helper: ClientHelper):
case = client_helper.client.get_case_by_reference(case_ref)
assert isinstance(case, Case)

@pytest.mark.experimental
@pytest.mark.vcr()
def test_get_experiment_by_reference(self, client_helper: ClientHelper):
experiment_ref = create_experiment_reference(
Expand Down