diff --git a/OMPython/ModelicaSystem.py b/OMPython/ModelicaSystem.py index dfc70fd6..9355ec4d 100644 --- a/OMPython/ModelicaSystem.py +++ b/OMPython/ModelicaSystem.py @@ -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: """ @@ -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: """ @@ -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. @@ -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( @@ -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. @@ -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: @@ -1174,7 +1120,6 @@ def simulate( om_cmd = self.simulate_cmd( result_file=self._result_file, - simflags=simflags, simargs=simargs, ) @@ -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. @@ -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: @@ -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 diff --git a/OMPython/OMCSession.py b/OMPython/OMCSession.py index cd1789c8..598b41a0 100644 --- a/OMPython/OMCSession.py +++ b/OMPython/OMCSession.py @@ -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. @@ -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. diff --git a/tests/test_ModelicaSystemCmd.py b/tests/test_ModelicaSystemCmd.py index 2480aad9..341fce42 100644 --- a/tests/test_ModelicaSystemCmd.py +++ b/tests/test_ModelicaSystemCmd.py @@ -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({ @@ -53,6 +50,5 @@ def test_simflags(mscmd_firstorder): assert mscmd.get_cmd_args() == [ '-noEventEmit', - '-noRestart', - '-override=a=1,x=3', + '-override=a=4', ] diff --git a/tests/test_ZMQ.py b/tests/test_ZMQ.py index 1302a79d..f4ebf105 100644 --- a/tests/test_ZMQ.py +++ b/tests/test_ZMQ.py @@ -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!'