Skip to content

Commit 53abbc1

Browse files
authored
Rename variables (#377)
* [ModelicaSystem] rename variables * [ModelicaSystemDoE] rename variables * [ModelicaSystem] rename variables: commandLineOptions => command_line * [ModelicaSystemDoE] rename variables: commandLineOptions => command_line * [ModelicaSystem] rename variables: customBuildDirectory => work_directory * [ModelicaSystemDoE] rename variables: customBuildDirectory => work_directory * [ModelicaSystem] rename variables: customBuildDirectory => work_directory (2) * [ModelicaSystem] rename variable / function setCommandLineOptions() => set_command_line_options() commandLineOptions => command_line_option * [MOdelicaSystem*] rename: command_line => command_line_options
1 parent 8a50b5f commit 53abbc1

File tree

9 files changed

+82
-80
lines changed

9 files changed

+82
-80
lines changed

OMPython/ModelicaSystem.py

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,18 @@ class ModelicaSystem:
329329

330330
def __init__(
331331
self,
332-
commandLineOptions: Optional[list[str]] = None,
333-
customBuildDirectory: Optional[str | os.PathLike] = None,
332+
command_line_options: Optional[list[str]] = None,
333+
work_directory: Optional[str | os.PathLike] = None,
334334
omhome: Optional[str] = None,
335335
omc_process: Optional[OMCProcess] = None,
336336
) -> None:
337337
"""Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo().
338338
339339
Args:
340-
commandLineOptions: List with extra command line options as elements. The list elements are
340+
command_line_options: List with extra command line options as elements. The list elements are
341341
provided to omc via setCommandLineOptions(). If set, the default values will be overridden.
342342
To disable any command line options, use an empty list.
343-
customBuildDirectory: Path to a directory to be used for temporary
343+
work_directory: Path to a directory to be used for temporary
344344
files like the model executable. If left unspecified, a tmp
345345
directory will be created.
346346
omhome: path to OMC to be used when creating the OMC session (see OMCSessionZMQ).
@@ -378,20 +378,20 @@ def __init__(
378378
self._session = OMCSessionZMQ(omhome=omhome)
379379

380380
# set commandLineOptions using default values or the user defined list
381-
if commandLineOptions is None:
381+
if command_line_options is None:
382382
# set default command line options to improve the performance of linearization and to avoid recompilation if
383383
# the simulation executable is reused in linearize() via the runtime flag '-l'
384-
commandLineOptions = [
384+
command_line_options = [
385385
"--linearizationDumpLanguage=python",
386386
"--generateSymbolicLinearization",
387387
]
388-
for opt in commandLineOptions:
389-
self.setCommandLineOptions(commandLineOptions=opt)
388+
for opt in command_line_options:
389+
self.set_command_line_options(command_line_option=opt)
390390

391391
self._simulated = False # True if the model has already been simulated
392392
self._result_file: Optional[OMCPath] = None # for storing result file
393393

394-
self._work_dir: OMCPath = self.setWorkDirectory(customBuildDirectory)
394+
self._work_dir: OMCPath = self.setWorkDirectory(work_directory)
395395

396396
self._model_name: Optional[str] = None
397397
self._libraries: Optional[list[str | tuple[str, str]]] = None
@@ -400,8 +400,8 @@ def __init__(
400400

401401
def model(
402402
self,
403-
name: Optional[str] = None,
404-
file: Optional[str | os.PathLike] = None,
403+
model_name: Optional[str] = None,
404+
model_file: Optional[str | os.PathLike] = None,
405405
libraries: Optional[list[str | tuple[str, str]]] = None,
406406
variable_filter: Optional[str] = None,
407407
build: bool = True,
@@ -411,9 +411,9 @@ def model(
411411
This method loads the model file and builds it if requested (build == True).
412412
413413
Args:
414-
file: Path to the model file. Either absolute or relative to
414+
model_file: Path to the model file. Either absolute or relative to
415415
the current working directory.
416-
name: The name of the model class. If it is contained within
416+
model_name: The name of the model class. If it is contained within
417417
a package, "PackageName.ModelName" should be used.
418418
libraries: List of libraries to be loaded before the model itself is
419419
loaded. Two formats are supported for the list elements:
@@ -439,7 +439,7 @@ def model(
439439
raise ModelicaSystemError("Can not reuse this instance of ModelicaSystem "
440440
f"defined for {repr(self._model_name)}!")
441441

442-
if name is None or not isinstance(name, str):
442+
if model_name is None or not isinstance(model_name, str):
443443
raise ModelicaSystemError("A model name must be provided!")
444444

445445
if libraries is None:
@@ -449,16 +449,16 @@ def model(
449449
raise ModelicaSystemError(f"Invalid input type for libraries: {type(libraries)} - list expected!")
450450

451451
# set variables
452-
self._model_name = name # Model class name
452+
self._model_name = model_name # Model class name
453453
self._libraries = libraries # may be needed if model is derived from other model
454454
self._variable_filter = variable_filter
455455

456456
if self._libraries:
457457
self._loadLibrary(libraries=self._libraries)
458458

459459
self._file_name = None
460-
if file is not None:
461-
file_path = pathlib.Path(file)
460+
if model_file is not None:
461+
file_path = pathlib.Path(model_file)
462462
# special handling for OMCProcessLocal - consider a relative path
463463
if isinstance(self._session.omc_process, OMCProcessLocal) and not file_path.is_absolute():
464464
file_path = pathlib.Path.cwd() / file_path
@@ -487,11 +487,11 @@ def session(self) -> OMCSessionZMQ:
487487
"""
488488
return self._session
489489

490-
def setCommandLineOptions(self, commandLineOptions: str):
490+
def set_command_line_options(self, command_line_option: str):
491491
"""
492492
Set the provided command line option via OMC setCommandLineOptions().
493493
"""
494-
exp = f'setCommandLineOptions("{commandLineOptions}")'
494+
exp = f'setCommandLineOptions("{command_line_option}")'
495495
self.sendExpression(exp)
496496

497497
def _loadFile(self, fileName: OMCPath):
@@ -522,15 +522,15 @@ def _loadLibrary(self, libraries: list):
522522
'1)["Modelica"]\n'
523523
'2)[("Modelica","3.2.3"), "PowerSystems"]\n')
524524

525-
def setWorkDirectory(self, customBuildDirectory: Optional[str | os.PathLike] = None) -> OMCPath:
525+
def setWorkDirectory(self, work_directory: Optional[str | os.PathLike] = None) -> OMCPath:
526526
"""
527527
Define the work directory for the ModelicaSystem / OpenModelica session. The model is build within this
528528
directory. If no directory is defined a unique temporary directory is created.
529529
"""
530-
if customBuildDirectory is not None:
531-
workdir = self._session.omcpath(customBuildDirectory).absolute()
530+
if work_directory is not None:
531+
workdir = self._session.omcpath(work_directory).absolute()
532532
if not workdir.is_dir():
533-
raise IOError(f"Provided work directory does not exists: {customBuildDirectory}!")
533+
raise IOError(f"Provided work directory does not exists: {work_directory}!")
534534
else:
535535
workdir = self._session.omcpath_tempdir().absolute()
536536
if not workdir.is_dir():
@@ -1709,8 +1709,8 @@ def convertFmu2Mo(
17091709
raise ModelicaSystemError(f"Missing file {filepath.as_posix()}")
17101710

17111711
self.model(
1712-
name=f"{fmu_path.stem}_me_FMU",
1713-
file=filepath,
1712+
model_name=f"{fmu_path.stem}_me_FMU",
1713+
model_file=filepath,
17141714
)
17151715

17161716
return filepath
@@ -1744,7 +1744,7 @@ def optimize(self) -> dict[str, Any]:
17441744
"""
17451745
cName = self._model_name
17461746
properties = ','.join(f"{key}={val}" for key, val in self._optimization_options.items())
1747-
self.setCommandLineOptions("-g=Optimica")
1747+
self.set_command_line_options("-g=Optimica")
17481748
optimizeResult = self._requestApi(apiName='optimize', entity=cName, properties=properties)
17491749

17501750
return optimizeResult
@@ -1926,8 +1926,8 @@ def run_doe():
19261926
resdir.mkdir(exist_ok=True)
19271927
19281928
doe_mod = OMPython.ModelicaSystemDoE(
1929-
fileName=model.as_posix(),
1930-
modelName="M",
1929+
model_name="M",
1930+
model_file=model.as_posix(),
19311931
parameters=param,
19321932
resultpath=resdir,
19331933
simargs={"override": {'stopTime': 1.0}},
@@ -1955,12 +1955,12 @@ def run_doe():
19551955
def __init__(
19561956
self,
19571957
# data to be used for ModelicaSystem
1958-
fileName: Optional[str | os.PathLike] = None,
1959-
modelName: Optional[str] = None,
1960-
lmodel: Optional[list[str | tuple[str, str]]] = None,
1961-
commandLineOptions: Optional[list[str]] = None,
1962-
variableFilter: Optional[str] = None,
1963-
customBuildDirectory: Optional[str | os.PathLike] = None,
1958+
model_file: Optional[str | os.PathLike] = None,
1959+
model_name: Optional[str] = None,
1960+
libraries: Optional[list[str | tuple[str, str]]] = None,
1961+
command_line_options: Optional[list[str]] = None,
1962+
variable_filter: Optional[str] = None,
1963+
work_directory: Optional[str | os.PathLike] = None,
19641964
omhome: Optional[str] = None,
19651965
omc_process: Optional[OMCProcess] = None,
19661966
# simulation specific input
@@ -1976,21 +1976,23 @@ def __init__(
19761976
ModelicaSystem.simulate(). Additionally, the path to store the result files is needed (= resultpath) as well as
19771977
a list of parameters to vary for the Doe (= parameters). All possible combinations are considered.
19781978
"""
1979+
if model_name is None:
1980+
raise ModelicaSystemError("No model name provided!")
19791981

19801982
self._mod = ModelicaSystem(
1981-
commandLineOptions=commandLineOptions,
1982-
customBuildDirectory=customBuildDirectory,
1983+
command_line_options=command_line_options,
1984+
work_directory=work_directory,
19831985
omhome=omhome,
19841986
omc_process=omc_process,
19851987
)
19861988
self._mod.model(
1987-
file=fileName,
1988-
name=modelName,
1989-
libraries=lmodel,
1990-
variable_filter=variableFilter,
1989+
model_file=model_file,
1990+
model_name=model_name,
1991+
libraries=libraries,
1992+
variable_filter=variable_filter,
19911993
)
19921994

1993-
self._model_name = modelName
1995+
self._model_name = model_name
19941996

19951997
self._simargs = simargs
19961998
self._timeout = timeout
@@ -2046,7 +2048,7 @@ def prepare(self) -> int:
20462048

20472049
build_dir = self._resultpath / f"DOE_{idx_pc_structure:09d}"
20482050
build_dir.mkdir()
2049-
self._mod.setWorkDirectory(customBuildDirectory=build_dir)
2051+
self._mod.setWorkDirectory(work_directory=build_dir)
20502052

20512053
sim_param_structure = {}
20522054
for idx_structure, pk_structure in enumerate(param_structure.keys()):

tests/test_FMIExport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def test_CauerLowPassAnalog():
88
mod = OMPython.ModelicaSystem()
99
mod.model(
10-
name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
10+
model_name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
1111
libraries=["Modelica"],
1212
)
1313
tmp = pathlib.Path(mod.getWorkDirectory())
@@ -21,7 +21,7 @@ def test_CauerLowPassAnalog():
2121
def test_DrumBoiler():
2222
mod = OMPython.ModelicaSystem()
2323
mod.model(
24-
name="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler",
24+
model_name="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler",
2525
libraries=["Modelica"],
2626
)
2727
tmp = pathlib.Path(mod.getWorkDirectory())

tests/test_FMIImport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_FMIImport(model_firstorder):
2424

2525
# create model & simulate it
2626
mod1 = OMPython.ModelicaSystem()
27-
mod1.model(file=filePath, name="M")
27+
mod1.model(model_file=filePath, model_name="M")
2828
mod1.simulate()
2929

3030
# create FMU & check
@@ -33,7 +33,7 @@ def test_FMIImport(model_firstorder):
3333

3434
# import FMU & check & simulate
3535
# TODO: why is '--allowNonStandardModelica=reinitInAlgorithms' needed? any example without this possible?
36-
mod2 = OMPython.ModelicaSystem(commandLineOptions=['--allowNonStandardModelica=reinitInAlgorithms'])
36+
mod2 = OMPython.ModelicaSystem(command_line_options=['--allowNonStandardModelica=reinitInAlgorithms'])
3737
mo = mod2.convertFmu2Mo(fmu=fmu)
3838
assert os.path.exists(mo)
3939

tests/test_ModelicaSystem.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def worker():
4040
filePath = model_firstorder.as_posix()
4141
mod = OMPython.ModelicaSystem()
4242
mod.model(
43-
file=filePath,
44-
name="M",
43+
model_file=filePath,
44+
model_name="M",
4545
)
4646
mod.simulate()
4747
mod.convertMo2Fmu(fmuType="me")
@@ -55,8 +55,8 @@ def test_setParameters():
5555
model_path = omc.omcpath(model_path_str)
5656
mod = OMPython.ModelicaSystem()
5757
mod.model(
58-
file=model_path / "BouncingBall.mo",
59-
name="BouncingBall",
58+
model_file=model_path / "BouncingBall.mo",
59+
model_name="BouncingBall",
6060
)
6161

6262
# method 1 (test depreciated variants)
@@ -90,8 +90,8 @@ def test_setSimulationOptions():
9090
model_path = omc.omcpath(model_path_str)
9191
mod = OMPython.ModelicaSystem()
9292
mod.model(
93-
file=model_path / "BouncingBall.mo",
94-
name="BouncingBall",
93+
model_file=model_path / "BouncingBall.mo",
94+
model_name="BouncingBall",
9595
)
9696

9797
# method 1
@@ -127,8 +127,8 @@ def test_relative_path(model_firstorder):
127127

128128
mod = OMPython.ModelicaSystem()
129129
mod.model(
130-
file=model_relative,
131-
name="M",
130+
model_file=model_relative,
131+
model_name="M",
132132
)
133133
assert float(mod.getParameters("a")[0]) == -1
134134
finally:
@@ -139,10 +139,10 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
139139
filePath = model_firstorder.as_posix()
140140
tmpdir = tmp_path / "tmpdir1"
141141
tmpdir.mkdir()
142-
mod = OMPython.ModelicaSystem(customBuildDirectory=tmpdir)
142+
mod = OMPython.ModelicaSystem(work_directory=tmpdir)
143143
mod.model(
144-
file=filePath,
145-
name="M",
144+
model_file=filePath,
145+
model_name="M",
146146
)
147147
assert pathlib.Path(mod.getWorkDirectory()).resolve() == tmpdir.resolve()
148148
result_file = tmpdir / "a.mat"
@@ -161,8 +161,8 @@ def test_getSolutions_docker(model_firstorder):
161161
omc_process=omc.omc_process,
162162
)
163163
mod.model(
164-
name="M",
165-
file=model_firstorder.as_posix(),
164+
model_file=model_firstorder,
165+
model_name="M",
166166
)
167167

168168
_run_getSolutions(mod)
@@ -171,8 +171,8 @@ def test_getSolutions_docker(model_firstorder):
171171
def test_getSolutions(model_firstorder):
172172
mod = OMPython.ModelicaSystem()
173173
mod.model(
174-
file=model_firstorder.as_posix(),
175-
name="M",
174+
model_file=model_firstorder,
175+
model_name="M",
176176
)
177177

178178
_run_getSolutions(mod)
@@ -219,8 +219,8 @@ def test_getters(tmp_path):
219219
""")
220220
mod = OMPython.ModelicaSystem()
221221
mod.model(
222-
file=model_file.as_posix(),
223-
name="M_getters",
222+
model_file=model_file.as_posix(),
223+
model_name="M_getters",
224224
)
225225

226226
q = mod.getQuantities()
@@ -415,8 +415,8 @@ def test_simulate_inputs(tmp_path):
415415
""")
416416
mod = OMPython.ModelicaSystem()
417417
mod.model(
418-
file=model_file.as_posix(),
419-
name="M_input",
418+
model_file=model_file.as_posix(),
419+
model_name="M_input",
420420
)
421421

422422
simOptions = {"stopTime": 1.0}

tests/test_ModelicaSystemCmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def model_firstorder(tmp_path):
1919
def mscmd_firstorder(model_firstorder):
2020
mod = OMPython.ModelicaSystem()
2121
mod.model(
22-
file=model_firstorder.as_posix(),
23-
name="M",
22+
model_file=model_firstorder.as_posix(),
23+
model_name="M",
2424
)
2525
mscmd = OMPython.ModelicaSystemCmd(
2626
session=mod.session(),

0 commit comments

Comments
 (0)