Skip to content

[ModelicaSystem] reorder input (mypy) #294

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

Merged
merged 2 commits into from
Jun 11, 2025
Merged
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
6 changes: 5 additions & 1 deletion OMPython/ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def parse_simflags(simflags: str) -> dict[str, Optional[str | dict[str, str]]]:
class ModelicaSystem:
def __init__(
self,
fileName: Optional[str | os.PathLike] = None,
fileName: Optional[str | os.PathLike | pathlib.Path] = None,
modelName: Optional[str] = None,
lmodel: Optional[list[str | tuple[str, str]]] = None,
commandLineOptions: Optional[str] = None,
Expand Down Expand Up @@ -360,9 +360,13 @@ def __init__(
mod = ModelicaSystem("ModelicaModel.mo", "modelName", ["Modelica"])
mod = ModelicaSystem("ModelicaModel.mo", "modelName", [("Modelica","3.2.3"), "PowerSystems"])
"""

if fileName is None and modelName is None and not lmodel: # all None
raise ModelicaSystemError("Cannot create ModelicaSystem object without any arguments")

if modelName is None:
raise ModelicaSystemError("A modelname must be provided (argument modelName)!")

self.quantitiesList = []
self.paramlist = {}
self.inputlist = {}
Expand Down
8 changes: 4 additions & 4 deletions tests/test_ModelicaSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_setParameters():
def test_setSimulationOptions():
omc = OMPython.OMCSessionZMQ()
model_path = omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/"
mod = OMPython.ModelicaSystem(model_path + "BouncingBall.mo", "BouncingBall")
mod = OMPython.ModelicaSystem(fileName=model_path + "BouncingBall.mo", modelName="BouncingBall")

# method 1
mod.setSimulationOptions("stopTime=1.234")
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_relative_path(model_firstorder):
model_relative = str(model_file)
assert "/" not in model_relative

mod = OMPython.ModelicaSystem(model_relative, "M")
mod = OMPython.ModelicaSystem(fileName=model_relative, modelName="M")
assert float(mod.getParameters("a")[0]) == -1
finally:
model_file.unlink() # clean up the temporary file
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_getters(tmp_path):
y = der(x);
end M_getters;
""")
mod = OMPython.ModelicaSystem(model_file.as_posix(), "M_getters")
mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="M_getters")

q = mod.getQuantities()
assert isinstance(q, list)
Expand Down Expand Up @@ -324,7 +324,7 @@ def test_simulate_inputs(tmp_path):
y = x;
end M_input;
""")
mod = OMPython.ModelicaSystem(model_file.as_posix(), "M_input")
mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="M_input")

mod.setSimulationOptions("stopTime=1.0")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ModelicaSystemCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def model_firstorder(tmp_path):


def test_simflags(model_firstorder):
mod = OMPython.ModelicaSystem(model_firstorder.as_posix(), "M")
mod = OMPython.ModelicaSystem(fileName=model_firstorder.as_posix(), modelName="M")
mscmd = OMPython.ModelicaSystemCmd(runpath=mod.tempdir, modelname=mod.modelName)
mscmd.args_set({
"noEventEmit": None,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_linearization.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_getters(tmp_path):
y2 = phi + u1;
end Pendulum;
""")
mod = OMPython.ModelicaSystem(model_file.as_posix(), "Pendulum", ["Modelica"])
mod = OMPython.ModelicaSystem(fileName=model_file.as_posix(), modelName="Pendulum", lmodel=["Modelica"])

d = mod.getLinearizationOptions()
assert isinstance(d, dict)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_optimization_example(tmp_path):
end BangBang2021;
""")

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

mod.setOptimizationOptions(["numberOfIntervals=16", "stopTime=1",
"stepSize=0.001", "tolerance=1e-8"])
Expand Down
Loading