Skip to content

Commit 6cf429f

Browse files
committed
[ModelicaDoERunner/test_ModelicaDoERunner] fix definition
1 parent 1aa0990 commit 6cf429f

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,16 +2646,16 @@ class ModelicaDoERunner(ModelicaDoEABC):
26462646
def __init__(
26472647
self,
26482648
# ModelicaSystem definition to use
2649-
mod: ModelicaSystemOMC,
2649+
mod: ModelicaSystemABC,
26502650
# simulation specific input
26512651
# TODO: add more settings (simulation options, input options, ...)
26522652
simargs: Optional[dict[str, Optional[str | dict[str, str] | numbers.Number]]] = None,
26532653
# DoE specific inputs
26542654
resultpath: Optional[str | os.PathLike] = None,
26552655
parameters: Optional[dict[str, list[str] | list[int] | list[float]]] = None,
26562656
) -> None:
2657-
if not isinstance(mod, ModelicaSystemRunner):
2658-
raise ModelicaSystemError(f"Invalid definition for mod: {type(mod)} - expect ModelicaSystemOMC!")
2657+
if not isinstance(mod, ModelicaSystemABC):
2658+
raise ModelicaSystemError(f"Invalid definition for ModelicaSystem*: {type(mod)}!")
26592659

26602660
super().__init__(
26612661
mod=mod,
@@ -2670,5 +2670,8 @@ def _prepare_structure_parameters(
26702670
pc_structure: Tuple,
26712671
param_structure: dict[str, list[str] | list[int] | list[float]],
26722672
) -> dict[str, str | int | float]:
2673-
raise ModelicaSystemError(f"{self.__class__.__name__} can not handle structure parameters as it uses a "
2674-
"pre-compiled binary of model.")
2673+
if len(param_structure.keys()) > 0:
2674+
raise ModelicaSystemError(f"{self.__class__.__name__} can not handle structure parameters as it uses a "
2675+
"pre-compiled binary of model.")
2676+
2677+
return {}

tests/test_ModelicaDoERunner.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def param_doe() -> dict[str, list]:
4343
return param
4444

4545

46-
def test_ModelicaDoEOMC_local(tmp_path, model_doe, param_doe):
46+
def test_ModelicaDoERunner_ModelicaSystemOMC(tmp_path, model_doe, param_doe):
4747
tmpdir = tmp_path / 'DoE'
4848
tmpdir.mkdir(exist_ok=True)
4949

@@ -67,6 +67,41 @@ def test_ModelicaDoEOMC_local(tmp_path, model_doe, param_doe):
6767
_check_runner_result(mod=mod, doe_mod=doe_mod)
6868

6969

70+
def test_ModelicaDoERunner_ModelicaSystemRunner(tmp_path, model_doe, param_doe):
71+
tmpdir = tmp_path / 'DoE'
72+
tmpdir.mkdir(exist_ok=True)
73+
74+
mod = OMPython.ModelicaSystemOMC()
75+
mod.model(
76+
model_file=model_doe,
77+
model_name="M",
78+
)
79+
80+
resultfile_mod = mod.getWorkDirectory() / f"{mod.get_model_name()}_res_mod.mat"
81+
_run_simulation(mod=mod, resultfile=resultfile_mod, param=param_doe)
82+
83+
# run the model using only the runner class
84+
omcs = OMPython.OMSessionRunner(
85+
version=mod.get_session().get_version(),
86+
)
87+
modr = OMPython.ModelicaSystemRunner(
88+
session=omcs,
89+
work_directory=mod.getWorkDirectory(),
90+
)
91+
modr.setup(
92+
model_name="M",
93+
)
94+
doe_mod = OMPython.ModelicaDoERunner(
95+
mod=modr,
96+
parameters=param_doe,
97+
resultpath=tmpdir,
98+
)
99+
100+
_run_ModelicaDoERunner(doe_mod=doe_mod)
101+
102+
_check_runner_result(mod=mod, doe_mod=doe_mod)
103+
104+
70105
def _run_simulation(mod, resultfile, param):
71106
simOptions = {"stopTime": 1.0, "stepSize": 0.1, "tolerance": 1e-8}
72107
mod.setSimulationOptions(**simOptions)

0 commit comments

Comments
 (0)