Skip to content
Draft
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
66 changes: 2 additions & 64 deletions OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,46 +255,6 @@ def definition(self) -> OMCSessionRunData:

return omc_run_data_updated

@staticmethod
def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, Any] | numbers.Number]]:
"""
Parse a simflag definition; this is deprecated!

The return data can be used as input for self.args_set().
"""
warnings.warn(message="The argument 'simflags' is depreciated and will be removed in future versions; "
"please use 'simargs' instead",
category=DeprecationWarning,
stacklevel=2)

simargs: dict[str, Optional[str | dict[str, Any] | numbers.Number]] = {}

args = [s for s in simflags.split(' ') if s]
for arg in args:
if arg[0] != '-':
raise ModelicaSystemError(f"Invalid simulation flag: {arg}")
arg = arg[1:]
parts = arg.split('=')
if len(parts) == 1:
simargs[parts[0]] = None
elif parts[0] == 'override':
override = '='.join(parts[1:])

override_dict = {}
for item in override.split(','):
kv = item.split('=')
if not 0 < len(kv) < 3:
raise ModelicaSystemError(f"Invalid value for '-override': {override}")
if kv[0]:
try:
override_dict[kv[0]] = kv[1]
except (KeyError, IndexError) as ex:
raise ModelicaSystemError(f"Invalid value for '-override': {override}") from ex

simargs[parts[0]] = override_dict

return simargs


class ModelicaSystem:
"""
Expand Down Expand Up @@ -1067,7 +1027,6 @@ def _process_override_data(
def simulate_cmd(
self,
result_file: OMCPath,
simflags: Optional[str] = None,
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
) -> ModelicaSystemCmd:
"""
Expand All @@ -1080,12 +1039,6 @@ def simulate_cmd(
However, if only non-structural parameters are used, it is possible to reuse an existing instance of
ModelicaSystem to create several version ModelicaSystemCmd to run the model using different settings.

Parameters
----------
result_file
simflags
simargs

Returns
-------
An instance if ModelicaSystemCmd to run the requested simulation.
Expand All @@ -1100,11 +1053,7 @@ def simulate_cmd(
# always define the result file to use
om_cmd.arg_set(key="r", val=result_file.as_posix())

# allow runtime simulation flags from user input
if simflags is not None:
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))

if simargs:
if simargs is not None:
om_cmd.args_set(args=simargs)

self._process_override_data(
Expand Down Expand Up @@ -1137,7 +1086,6 @@ def simulate_cmd(
def simulate(
self,
resultfile: Optional[str | os.PathLike] = None,
simflags: Optional[str] = None,
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
) -> None:
"""Simulate the model according to simulation options.
Expand All @@ -1146,8 +1094,6 @@ def simulate(

Args:
resultfile: Path to a custom result file
simflags: String of extra command line flags for the model binary.
This argument is deprecated, use simargs instead.
simargs: Dict with simulation runtime flags.

Examples:
Expand All @@ -1174,7 +1120,6 @@ def simulate(

om_cmd = self.simulate_cmd(
result_file=self._result_file,
simflags=simflags,
simargs=simargs,
)

Expand Down Expand Up @@ -1757,7 +1702,6 @@ def optimize(self) -> dict[str, Any]:
def linearize(
self,
lintime: Optional[float] = None,
simflags: Optional[str] = None,
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
) -> LinearizationResult:
"""Linearize the model according to linearization options.
Expand All @@ -1766,8 +1710,6 @@ def linearize(

Args:
lintime: Override "stopTime" value.
simflags: String of extra command line flags for the model binary.
This argument is deprecated, use simargs instead.
simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"

Returns:
Expand Down Expand Up @@ -1817,11 +1759,7 @@ def linearize(
f"<= lintime <= {self._linearization_options['stopTime']}")
om_cmd.arg_set(key="l", val=str(lintime))

# allow runtime simulation flags from user input
if simflags is not None:
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))

if simargs:
if simargs is not None:
om_cmd.args_set(args=simargs)

# the file create by the model executable which contains the matrix and linear inputs, outputs and states
Expand Down
11 changes: 0 additions & 11 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,6 @@ def run_model_executable(self, cmd_run_data: OMCSessionRunData) -> int:
"""
return self.omc_process.run_model_executable(cmd_run_data=cmd_run_data)

def execute(self, command: str):
return self.omc_process.execute(command=command)

def sendExpression(self, command: str, parsed: bool = True) -> Any:
"""
Send an expression to the OMC server and return the result.
Expand Down Expand Up @@ -847,14 +844,6 @@ def run_model_executable(self, cmd_run_data: OMCSessionRunData) -> int:

return returncode

def execute(self, command: str):
warnings.warn(message="This function is depreciated and will be removed in future versions; "
"please use sendExpression() instead",
category=DeprecationWarning,
stacklevel=2)

return self.sendExpression(command, parsed=False)

def sendExpression(self, command: str, parsed: bool = True) -> Any:
"""
Send an expression to the OMC server and return the result.
Expand Down
10 changes: 3 additions & 7 deletions tests/test_ModelicaSystemCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ def test_simflags(mscmd_firstorder):

mscmd.args_set({
"noEventEmit": None,
"override": {'b': 2}
"override": {'b': 2, 'a': 4},
})
with pytest.deprecated_call():
mscmd.args_set(args=mscmd.parse_simflags(simflags="-noEventEmit -noRestart -override=a=1,x=3"))

assert mscmd.get_cmd_args() == [
'-noEventEmit',
'-noRestart',
'-override=a=1,b=2,x=3',
'-override=a=4,b=2',
]

mscmd.args_set({
Expand All @@ -53,6 +50,5 @@ def test_simflags(mscmd_firstorder):

assert mscmd.get_cmd_args() == [
'-noEventEmit',
'-noRestart',
'-override=a=1,x=3',
'-override=a=4',
]
4 changes: 1 addition & 3 deletions tests/test_ZMQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def test_Simulate(omcs, model_time_str):
assert omcs.sendExpression('res.resultFile')


def test_execute(omcs):
with pytest.deprecated_call():
assert omcs.execute('"HelloWorld!"') == '"HelloWorld!"\n'
def test_sendExpression(omcs):
assert omcs.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
assert omcs.sendExpression('"HelloWorld!"', parsed=True) == 'HelloWorld!'

Expand Down