Skip to content

Remove depreciated functionality #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cda6d1c
[ModelicaSystem] add type hints for set*() functions and rename argum…
syntron Jun 23, 2025
c21c58f
[ModelicaSystem] add _prepare_inputdata()
syntron Jun 23, 2025
bf3a1a4
[ModelicaSystem] update _set_method_helper()
syntron Jun 23, 2025
0301043
[ModelicaSystem] improve definition of _prepare_inputdata()
syntron Jun 23, 2025
341e429
[ModelicaSystem] rename _prepare_inputdata() => _prepare_input_data()
syntron Jun 23, 2025
1cbd1f7
[ModelicaSystem] update setInput()
syntron Jun 23, 2025
2c87f4e
update tests - use new dict based input for set*() methods
syntron Jun 23, 2025
c498498
[ModelicaSystem] add type hint for return value of isParameterChangea…
syntron Jun 23, 2025
3b0c9d9
[ModelicaSystem] fix type hint for _prepare_input_data() - use dict[s…
syntron Jun 23, 2025
241615d
[ModelicaSystem] setInput() - handly input data as list of tuples
syntron Jun 23, 2025
f8c742b
update tests - use new dict based input for setInput() method
syntron Jun 23, 2025
9ec7edd
[test_linearization] fix setInput() call
syntron Jun 24, 2025
36ca683
[ModelicaSystem] simplify _set_method_helper()
syntron Jun 26, 2025
817f20d
[ModelicaSystem] improve setInputs() - reduce spaces / cleanup
syntron Jun 26, 2025
d8c2d71
[OMCSessionZMQ] remove depreciated function execute()
syntron Jun 17, 2025
f7c04b5
[ModelicaSystemCmd] remove depreciated simflags
syntron Jun 17, 2025
6c5d62f
Merge branch 'ModelicaSystem_rewrite_set_functions' into remove_depre…
syntron Jul 2, 2025
144fa10
[ModelicaSystem] remove obsolete inputs for set*() methods
syntron Jun 23, 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
353 changes: 174 additions & 179 deletions OMPython/ModelicaSystem.py

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import time
from typing import Any, Optional, Tuple
import uuid
import warnings
import zmq

# TODO: replace this with the new parser
Expand Down Expand Up @@ -322,12 +321,6 @@ def __del__(self):

self.omc_zmq = None

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

return self.sendExpression(command, parsed=False)

def sendExpression(self, command: str, parsed: bool = True) -> Any:
if self.omc_zmq is None:
raise OMCSessionException("No OMC running. Create a new instance of OMCSessionZMQ!")
Expand Down
34 changes: 16 additions & 18 deletions tests/test_ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def test_setParameters():
mod = OMPython.ModelicaSystem(model_path + "BouncingBall.mo", "BouncingBall")

# method 1
mod.setParameters("e=1.234")
mod.setParameters("g=321.0")
mod.setParameters(pvals={"e": 1.234})
mod.setParameters(pvals={"g": 321.0})
assert mod.getParameters("e") == ["1.234"]
assert mod.getParameters("g") == ["321.0"]
assert mod.getParameters() == {
Expand All @@ -47,7 +47,7 @@ def test_setParameters():
mod.getParameters("thisParameterDoesNotExist")

# method 2
mod.setParameters(["e=21.3", "g=0.12"])
mod.setParameters(pvals={"e": 21.3, "g": 0.12})
assert mod.getParameters() == {
"e": "21.3",
"g": "0.12",
Expand All @@ -64,8 +64,8 @@ def test_setSimulationOptions():
mod = OMPython.ModelicaSystem(fileName=model_path + "BouncingBall.mo", modelName="BouncingBall")

# method 1
mod.setSimulationOptions("stopTime=1.234")
mod.setSimulationOptions("tolerance=1.1e-08")
mod.setSimulationOptions(simOptions={"stopTime": 1.234})
mod.setSimulationOptions(simOptions={"tolerance": 1.1e-08})
assert mod.getSimulationOptions("stopTime") == ["1.234"]
assert mod.getSimulationOptions("tolerance") == ["1.1e-08"]
assert mod.getSimulationOptions(["tolerance", "stopTime"]) == ["1.1e-08", "1.234"]
Expand All @@ -77,7 +77,7 @@ def test_setSimulationOptions():
mod.getSimulationOptions("thisOptionDoesNotExist")

# method 2
mod.setSimulationOptions(["stopTime=2.1", "tolerance=1.2e-08"])
mod.setSimulationOptions(simOptions={"stopTime": 2.1, "tolerance": "1.2e-08"})
d = mod.getSimulationOptions()
assert d["stopTime"] == "2.1"
assert d["tolerance"] == "1.2e-08"
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_getSolutions(model_firstorder):
a = -1
tau = -1 / a
stopTime = 5*tau
mod.setSimulationOptions([f"stopTime={stopTime}", "stepSize=0.1", "tolerance=1e-8"])
mod.setSimulationOptions(simOptions={"stopTime": stopTime, "stepSize": 0.1, "tolerance": 1e-8})
mod.simulate()

x = mod.getSolutions("x")
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_getters(tmp_path):
x0 = 1.0
x_analytical = -b/a + (x0 + b/a) * np.exp(a * stopTime)
dx_analytical = (x0 + b/a) * a * np.exp(a * stopTime)
mod.setSimulationOptions(f"stopTime={stopTime}")
mod.setSimulationOptions(simOptions={"stopTime": stopTime})
mod.simulate()

# getOutputs after simulate()
Expand Down Expand Up @@ -327,7 +327,7 @@ def test_getters(tmp_path):
mod.getContinuous("a") # a is a parameter

with pytest.raises(OMPython.ModelicaSystemError):
mod.setSimulationOptions("thisOptionDoesNotExist=3")
mod.setSimulationOptions(simOptions={"thisOptionDoesNotExist": 3})


def test_simulate_inputs(tmp_path):
Expand All @@ -345,7 +345,7 @@ def test_simulate_inputs(tmp_path):
""")
mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="M_input")

mod.setSimulationOptions("stopTime=1.0")
mod.setSimulationOptions(simOptions={"stopTime": 1.0})

# integrate zero (no setInputs call) - it should default to None -> 0
assert mod.getInputs() == {
Expand All @@ -357,7 +357,7 @@ def test_simulate_inputs(tmp_path):
assert np.isclose(y[-1], 0.0)

# integrate a constant
mod.setInputs("u1=2.5")
mod.setInputs(name={"u1": 2.5})
assert mod.getInputs() == {
"u1": [
(0.0, 2.5),
Expand All @@ -370,7 +370,7 @@ def test_simulate_inputs(tmp_path):
assert np.isclose(y[-1], 2.5)

# now let's integrate the sum of two ramps
mod.setInputs("u1=[(0.0, 0.0), (0.5, 2), (1.0, 0)]")
mod.setInputs(name={"u1": [(0.0, 0.0), (0.5, 2), (1.0, 0)]})
assert mod.getInputs("u1") == [[
(0.0, 0.0),
(0.5, 2.0),
Expand All @@ -383,19 +383,17 @@ def test_simulate_inputs(tmp_path):
# let's try some edge cases
# unmatched startTime
with pytest.raises(OMPython.ModelicaSystemError):
mod.setInputs("u1=[(-0.5, 0.0), (1.0, 1)]")
mod.setInputs(name={"u1": [(-0.5, 0.0), (1.0, 1)]})
mod.simulate()
# unmatched stopTime
with pytest.raises(OMPython.ModelicaSystemError):
mod.setInputs("u1=[(0.0, 0.0), (0.5, 1)]")
mod.setInputs(name={"u1": [(0.0, 0.0), (0.5, 1)]})
mod.simulate()

# Let's use both inputs, but each one with different number of of
# samples. This has an effect when generating the csv file.
mod.setInputs([
"u1=[(0.0, 0), (1.0, 1)]",
"u2=[(0.0, 0), (0.25, 0.5), (0.5, 1.0), (1.0, 0)]",
])
mod.setInputs(name={"u1": [(0.0, 0), (1.0, 1)],
"u2": [(0.0, 0), (0.25, 0.5), (0.5, 1.0), (1.0, 0)]})
mod.simulate()
assert pathlib.Path(mod.csvFile).read_text() == """time,u1,u2,end
0.0,0.0,0.0,0
Expand Down
7 changes: 3 additions & 4 deletions tests/test_ModelicaSystemCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ def test_simflags(model_firstorder):
"noRestart": None,
"override": {'b': 2}
})
with pytest.deprecated_call():
mscmd.args_set(args=mscmd.parse_simflags(simflags="-noEventEmit -noRestart -override=a=1,x=3"))

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


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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_linearization.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def test_getters(tmp_path):
assert "startTime" in d
assert "stopTime" in d
assert mod.getLinearizationOptions(["stopTime", "startTime"]) == [d["stopTime"], d["startTime"]]
mod.setLinearizationOptions("stopTime=0.02")
mod.setLinearizationOptions(linearizationOptions={"stopTime": 0.02})
assert mod.getLinearizationOptions("stopTime") == ["0.02"]

mod.setInputs(["u1=10", "u2=0"])
mod.setInputs(name={"u1": 10, "u2": 0})
[A, B, C, D] = mod.linearize()
g = float(mod.getParameters("g")[0])
l = float(mod.getParameters("l")[0])
Expand Down
8 changes: 5 additions & 3 deletions tests/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ def test_optimization_example(tmp_path):

mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="BangBang2021")

mod.setOptimizationOptions(["numberOfIntervals=16", "stopTime=1",
"stepSize=0.001", "tolerance=1e-8"])
mod.setOptimizationOptions(optimizationOptions={"numberOfIntervals": 16,
"stopTime": 1,
"stepSize": 0.001,
"tolerance": 1e-8})

# test the getter
assert mod.getOptimizationOptions()["stopTime"] == "1"
assert mod.getOptimizationOptions("stopTime") == ["1"]
assert mod.getOptimizationOptions(["tolerance", "stopTime"]) == ["1e-8", "1"]
assert mod.getOptimizationOptions(["tolerance", "stopTime"]) == ["1e-08", "1"]

r = mod.optimize()
# it is necessary to specify resultfile, otherwise it wouldn't find it.
Expand Down
Loading