Skip to content

Commit 5b9d9c9

Browse files
committed
??? fix mypy
1 parent ddba638 commit 5b9d9c9

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __init__(
127127
self._args: dict[str, str | None] = {}
128128
self._arg_override: dict[str, str] = {}
129129

130-
def arg_set(self, key: str, val: Optional[str | dict[str, Any]] = None) -> None:
130+
def arg_set(self, key: str, val: Optional[str | dict[str, Any] | numbers.Number] = None) -> None:
131131
"""
132132
Set one argument for the executable model.
133133
@@ -170,13 +170,9 @@ def arg_get(self, key: str) -> Optional[str | dict]:
170170

171171
return None
172172

173-
def args_set(self, args: dict[str, Optional[str | dict[str, Any]]]) -> None:
173+
def args_set(self, args: dict[str, Optional[str | dict[str, Any] | numbers.Number]]) -> None:
174174
"""
175175
Define arguments for the model executable.
176-
177-
Parameters
178-
----------
179-
args : dict[str, Optional[str | dict[str, str]]]
180176
"""
181177
for arg in args:
182178
self.arg_set(key=arg, val=args[arg])
@@ -217,7 +213,7 @@ def definition(self) -> OMCSessionRunData:
217213
return omc_run_data_updated
218214

219215
@staticmethod
220-
def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, str]]]:
216+
def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, Any] | numbers.Number]]:
221217
"""
222218
Parse a simflag definition; this is deprecated!
223219
@@ -226,7 +222,7 @@ def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, str]]]:
226222
warnings.warn("The argument 'simflags' is depreciated and will be removed in future versions; "
227223
"please use 'simargs' instead", DeprecationWarning, stacklevel=2)
228224

229-
simargs: dict[str, Optional[str | dict[str, str]]] = {}
225+
simargs: dict[str, Optional[str | dict[str, Any] | numbers.Number]] = {}
230226

231227
args = [s for s in simflags.split(' ') if s]
232228
for arg in args:
@@ -915,7 +911,7 @@ def simulate_cmd(
915911
self,
916912
result_file: OMCPath,
917913
simflags: Optional[str] = None,
918-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
914+
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
919915
timeout: Optional[float] = None,
920916
) -> ModelicaSystemCmd:
921917
"""
@@ -995,7 +991,7 @@ def simulate(
995991
self,
996992
resultfile: Optional[str] = None,
997993
simflags: Optional[str] = None,
998-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
994+
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
999995
timeout: Optional[float] = None,
1000996
) -> None:
1001997
"""Simulate the model according to simulation options.
@@ -1522,9 +1518,13 @@ def optimize(self) -> dict[str, Any]:
15221518

15231519
return optimizeResult
15241520

1525-
def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = None,
1526-
simargs: Optional[dict[str, Optional[str | dict[str, str]]]] = None,
1527-
timeout: Optional[float] = None) -> LinearizationResult:
1521+
def linearize(
1522+
self,
1523+
lintime: Optional[float] = None,
1524+
simflags: Optional[str] = None,
1525+
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
1526+
timeout: Optional[float] = None,
1527+
) -> LinearizationResult:
15281528
"""Linearize the model according to linearization options.
15291529
15301530
See setLinearizationOptions.
@@ -1734,7 +1734,7 @@ def __init__(
17341734
omhome: Optional[str] = None,
17351735
omc_process: Optional[OMCProcessLocal] = None,
17361736

1737-
simargs: Optional[dict[str, Optional[str | dict[str, str] | numbers.Number]]] = None,
1737+
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
17381738
timeout: Optional[int] = None,
17391739

17401740
resultpath: Optional[pathlib.Path] = None,
@@ -1813,7 +1813,7 @@ def prepare(self) -> int:
18131813

18141814
build_dir = self._resultpath / f"DOE_{idx_pc_structure:09d}"
18151815
build_dir.mkdir()
1816-
self._mod.setTempDirectory(build_dir)
1816+
self._mod.setWorkDirectory(customBuildDirectory=build_dir)
18171817

18181818
sim_param_structure = {}
18191819
for idx_structure, pk_structure in enumerate(param_structure.keys()):
@@ -1919,16 +1919,17 @@ def simulate(
19191919
Returns True if all simulations were done successfully, else False.
19201920
"""
19211921

1922-
doe_cmd_total = len(self._doe_cmd)
1923-
doe_def_total = len(self._doe_def)
1922+
doe_cmd_total = len(self._doe_cmd) if self._doe_cmd is not None else 0
1923+
doe_def_total = len(self._doe_def) if self._doe_def is not None else 0
19241924

19251925
if doe_cmd_total != doe_def_total:
19261926
raise ModelicaSystemError(f"Mismatch between number simulation commands ({doe_cmd_total}) "
19271927
f"and simulation definitions ({doe_def_total}).")
19281928

19291929
doe_task_query: queue.Queue = queue.Queue()
1930-
for doe_cmd in self._doe_cmd.values():
1931-
doe_task_query.put(doe_cmd)
1930+
if self._doe_cmd is not None:
1931+
for doe_cmd in self._doe_cmd.values():
1932+
doe_task_query.put(doe_cmd)
19321933

19331934
if not isinstance(self._doe_def, dict) or len(self._doe_def) == 0:
19341935
raise ModelicaSystemError("Missing Doe Summary!")

0 commit comments

Comments
 (0)