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 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
f246ca4
[OMCSessionZMQ] remove depreciated function execute()
syntron Jun 17, 2025
eefb719
[ModelicaSystemCmd] remove depreciated simflags
syntron Jun 17, 2025
a39908a
[ModelicaSystem] remove obsolete inputs for set*() methods
syntron Jun 23, 2025
66a8d9b
[ModelicaSystemCmd] add missing empty line (rebase fallout)
syntron Jul 9, 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
397 changes: 199 additions & 198 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
42 changes: 22 additions & 20 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,20 +357,24 @@ 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),
(1.0, 2.5),
],
"u2": None,
# u2 is set due to the call to simulate() above
"u2": [
(0.0, 0.0),
(1.0, 0.0),
],
}
mod.simulate()
y = mod.getSolutions("y")[0]
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 +387,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
# Let's use both inputs, but each one with different number 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)]})
csv_file = mod._createCSVData()
assert pathlib.Path(csv_file).read_text() == """time,u1,u2,end
0.0,0.0,0.0,0
Expand Down
5 changes: 1 addition & 4 deletions tests/test_ModelicaSystemCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ def test_simflags(mscmd_firstorder):
"noEventEmit": 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',
'-override=b=2,a=1,x=3',
'-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