Skip to content

Commit b39155c

Browse files
committed
Merge branch 'remove_depreciated_functionality' into merge_all
2 parents 072e507 + 672a250 commit b39155c

4 files changed

Lines changed: 4 additions & 76 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -271,44 +271,6 @@ def definition(self) -> OMCSessionRunData:
271271

272272
return omc_run_data_updated
273273

274-
@staticmethod
275-
def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, Any] | numbers.Number]]:
276-
"""
277-
Parse a simflag definition; this is deprecated!
278-
279-
The return data can be used as input for self.args_set().
280-
"""
281-
warnings.warn("The argument 'simflags' is depreciated and will be removed in future versions; "
282-
"please use 'simargs' instead", DeprecationWarning, stacklevel=2)
283-
284-
simargs: dict[str, Optional[str | dict[str, Any] | numbers.Number]] = {}
285-
286-
args = [s for s in simflags.split(' ') if s]
287-
for arg in args:
288-
if arg[0] != '-':
289-
raise ModelicaSystemError(f"Invalid simulation flag: {arg}")
290-
arg = arg[1:]
291-
parts = arg.split('=')
292-
if len(parts) == 1:
293-
simargs[parts[0]] = None
294-
elif parts[0] == 'override':
295-
override = '='.join(parts[1:])
296-
297-
override_dict = {}
298-
for item in override.split(','):
299-
kv = item.split('=')
300-
if not 0 < len(kv) < 3:
301-
raise ModelicaSystemError(f"Invalid value for '-override': {override}")
302-
if kv[0]:
303-
try:
304-
override_dict[kv[0]] = kv[1]
305-
except (KeyError, IndexError) as ex:
306-
raise ModelicaSystemError(f"Invalid value for '-override': {override}") from ex
307-
308-
simargs[parts[0]] = override_dict
309-
310-
return simargs
311-
312274

313275
class ModelicaSystem:
314276
def __init__(
@@ -979,7 +941,6 @@ def getOptimizationOptions(self, names: Optional[str | list[str]] = None) -> dic
979941
def simulate_cmd(
980942
self,
981943
result_file: OMCPath,
982-
simflags: Optional[str] = None,
983944
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
984945
timeout: Optional[float] = None,
985946
) -> ModelicaSystemCmd:
@@ -993,13 +954,6 @@ def simulate_cmd(
993954
However, if only non-structural parameters are used, it is possible to reuse an existing instance of
994955
ModelicaSystem to create several version ModelicaSystemCmd to run the model using different settings.
995956
996-
Parameters
997-
----------
998-
result_file
999-
simflags
1000-
simargs
1001-
timeout
1002-
1003957
Returns
1004958
-------
1005959
An instance if ModelicaSystemCmd to run the requested simulation.
@@ -1015,11 +969,7 @@ def simulate_cmd(
1015969
# always define the result file to use
1016970
om_cmd.arg_set(key="r", val=result_file.as_posix())
1017971

1018-
# allow runtime simulation flags from user input
1019-
if simflags is not None:
1020-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
1021-
1022-
if simargs:
972+
if simargs is not None:
1023973
om_cmd.args_set(args=simargs)
1024974

1025975
if self._override_variables or self._simulate_options_override:
@@ -1058,7 +1008,6 @@ def simulate_cmd(
10581008
def simulate(
10591009
self,
10601010
resultfile: Optional[str] = None,
1061-
simflags: Optional[str] = None,
10621011
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
10631012
timeout: Optional[float] = None,
10641013
) -> None:
@@ -1068,8 +1017,6 @@ def simulate(
10681017
10691018
Args:
10701019
resultfile: Path to a custom result file
1071-
simflags: String of extra command line flags for the model binary.
1072-
This argument is deprecated, use simargs instead.
10731020
simargs: Dict with simulation runtime flags.
10741021
timeout: Maximum execution time in seconds.
10751022
@@ -1095,7 +1042,6 @@ def simulate(
10951042

10961043
om_cmd = self.simulate_cmd(
10971044
result_file=self._result_file,
1098-
simflags=simflags,
10991045
simargs=simargs,
11001046
timeout=timeout,
11011047
)
@@ -1623,7 +1569,6 @@ def optimize(self) -> dict[str, Any]:
16231569
def linearize(
16241570
self,
16251571
lintime: Optional[float] = None,
1626-
simflags: Optional[str] = None,
16271572
simargs: Optional[dict[str, Optional[str | dict[str, Any] | numbers.Number]]] = None,
16281573
timeout: Optional[float] = None,
16291574
) -> LinearizationResult:
@@ -1633,8 +1578,6 @@ def linearize(
16331578
16341579
Args:
16351580
lintime: Override "stopTime" value.
1636-
simflags: String of extra command line flags for the model binary.
1637-
This argument is deprecated, use simargs instead.
16381581
simargs: A dict with command line flags and possible options; example: "simargs={'csvInput': 'a.csv'}"
16391582
timeout: Maximum execution time in seconds.
16401583
@@ -1683,11 +1626,7 @@ def linearize(
16831626

16841627
om_cmd.arg_set(key="l", val=str(lintime or self._linearization_options["stopTime"]))
16851628

1686-
# allow runtime simulation flags from user input
1687-
if simflags is not None:
1688-
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
1689-
1690-
if simargs:
1629+
if simargs is not None:
16911630
om_cmd.args_set(args=simargs)
16921631

16931632
# the file create by the model executable which contains the matrix and linear inputs, outputs and states

OMPython/OMCSession.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import time
5252
from typing import Any, Optional, Tuple
5353
import uuid
54-
import warnings
5554
import zmq
5655

5756
import psutil
@@ -595,18 +594,12 @@ def run_model_executable(cmd_run_data: OMCSessionRunData) -> int:
595594

596595
return returncode
597596

598-
def execute(self, command: str):
599-
warnings.warn("This function is depreciated and will be removed in future versions; "
600-
"please use sendExpression() instead", DeprecationWarning, stacklevel=2)
601-
602-
return self.sendExpression(command, parsed=False)
603-
604597
def sendExpression(self, command: str, parsed: bool = True) -> Any:
605598
"""
606599
Send an expression to the OMC server and return the result.
607600
"""
608601
if self.omc_zmq is None:
609-
raise OMCSessionException("No OMC running. Create a new instance of OMCProcess!")
602+
raise OMCSessionException("No OMC running. Create a new instance of OMCSessionZMQ!")
610603

611604
logger.debug("sendExpression(%r, parsed=%r)", command, parsed)
612605

tests/test_ModelicaSystemCmd.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ def test_simflags(mscmd_firstorder):
3333
"noEventEmit": None,
3434
"override": {'b': 2}
3535
})
36-
with pytest.deprecated_call():
37-
mscmd.args_set(args=mscmd.parse_simflags(simflags="-noEventEmit -noRestart -override=a=1,x=3"))
3836

3937
assert mscmd.get_cmd_args() == [
4038
'-noEventEmit',

tests/test_ZMQ.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ def test_Simulate(om, model_time_str):
3636
assert om.sendExpression('res.resultFile')
3737

3838

39-
def test_execute(om):
40-
with pytest.deprecated_call():
41-
assert om.execute('"HelloWorld!"') == '"HelloWorld!"\n'
39+
def test_sendExpression(om):
4240
assert om.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
4341
assert om.sendExpression('"HelloWorld!"', parsed=True) == 'HelloWorld!'
4442

0 commit comments

Comments
 (0)