Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8d19d26
[ModelicaSystem] add type hints for set*() functions and rename argum…
syntron Jun 23, 2025
9ac6a0e
[ModelicaSystem] add _prepare_inputdata()
syntron Jun 23, 2025
980ac33
[ModelicaSystem] update _set_method_helper()
syntron Jun 23, 2025
7c24f10
[ModelicaSystem] improve definition of _prepare_inputdata()
syntron Jun 23, 2025
b864a6c
[ModelicaSystem] rename _prepare_inputdata() => _prepare_input_data()
syntron Jun 23, 2025
3f180a6
[ModelicaSystem] update setInput()
syntron Jun 23, 2025
55051d9
update tests - use new dict based input for set*() methods
syntron Jun 23, 2025
3d8b83a
[ModelicaSystem] add type hint for return value of isParameterChangea…
syntron Jun 23, 2025
1b5917c
[ModelicaSystem] fix type hint for _prepare_input_data() - use dict[s…
syntron Jun 23, 2025
b5766f4
[ModelicaSystem] setInput() - handly input data as list of tuples
syntron Jun 23, 2025
9ef9d69
update tests - use new dict based input for setInput() method
syntron Jun 23, 2025
2fc67b9
[test_linearization] fix setInput() call
syntron Jun 24, 2025
bbd8740
[ModelicaSystem] simplify _set_method_helper()
syntron Jun 26, 2025
675a648
[ModelicaSystem] improve setInputs() - reduce spaces / cleanup
syntron Jun 26, 2025
9fcd39a
[ModelicaSystem] fix rebase fallout
syntron Jul 7, 2025
92651c5
[ModelicaSystem] fix rebase fallout 2
syntron Jul 7, 2025
d695899
[ModelicaSystem] remove _has_inputs - is defined by _inputs empty or not
syntron Jul 7, 2025
4fa05f1
[test_ModelicaSystem] cleanup
syntron Jul 7, 2025
30cb70e
[ModelicaSystem] simplify handling of inputs
syntron Jul 11, 2025
0a89151
[ModelicaSystem._set_method_helper] fail if parameter is *NOT* change…
syntron Jul 15, 2025
9a92c19
[ModelicaSystem] rename overwritedata => overridedata
syntron Aug 13, 2025
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
Prev Previous commit
Next Next commit
[ModelicaSystem] setInput() - handly input data as list of tuples
This method is used to set input values. It can be called with a sequence of input name and assigning
corresponding values as arguments as show in the example below. Compared to other set*() methods this is a
special case as value could be a list of tuples - these are converted to a string in _prepare_input_data()
and restored here via ast.literal_eval().
  • Loading branch information
syntron committed Jul 11, 2025
commit b5766f450f0a0ca27609ef564e9fbf721e48d89a
16 changes: 12 additions & 4 deletions OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,9 @@ def prepare_str(str_in: str) -> dict[str, str]:

if isinstance(raw_input, dict):
for key, val in raw_input.items():
str_val = str(val)
# convert all values to strings to align it on one type: dict[str, str]
# spaces have to be removed as setInput() could take list of tuples as input and spaces would
str_val = str(val).replace(' ', '')
if ' ' in key or ' ' in str_val:
raise ModelicaSystemError(f"Spaces not allowed in key/value pairs: {repr(key)} = {repr(val)}!")
input_data[key] = str_val
Expand Down Expand Up @@ -1334,9 +1336,11 @@ def setInputs(
name: str | list[str] | dict[str, Any],
) -> bool:
"""
This method is used to set input values. It can be called:
with a sequence of input name and assigning corresponding values as arguments as show in the example below:
usage
This method is used to set input values. It can be called with a sequence of input name and assigning
corresponding values as arguments as show in the example below. Compared to other set*() methods this is a
special case as value could be a list of tuples - these are converted to a string in _prepare_input_data()
and restored here via ast.literal_eval().

>>> setInputs("Name=value") # depreciated
>>> setInputs(["Name1=value1","Name2=value2"]) # depreciated
>>> setInputs(name={"Name1": "value1", "Name2": "value2"})
Expand All @@ -1345,7 +1349,11 @@ def setInputs(

for key, val in inputdata.items():
if key in self._inputs:
if not isinstance(val, str):
raise ModelicaSystemError(f"Invalid data in input for {repr(key)}: {repr(val)}")

val_evaluated = ast.literal_eval(val)

if isinstance(val_evaluated, (int, float)):
self._inputs[key] = [(float(self._simulate_options["startTime"]), float(val)),
(float(self._simulate_options["stopTime"]), float(val))]
Expand Down