Skip to content

Commit 8926af4

Browse files
authored
update docstrings and more linter based fixes (#379)
* rename DummyPopen to DockerPopen and add docstring * docstring for OMCSessionException * docstring for OMCSessionCmd - depreciated! * docstring for OMCPathCompatibility* * improve documentation for OMCSessionZMQ * docstring for OMCSessionZMQ * improve documentation of OMCProcess*.omc_run_data_update() and OMCSessionRunData.cmd_model_executable * [OMCSessionZMQ] small fixes based on pylint * OMPython/OMCSession.py:615:12: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return) * OMPython/OMCSession.py:835:12: W0621: Redefining name 'ex' from outer scope (line 831) (redefined-outer-name) * docstring for OMCProcess * update docstring for ModelicaSystemCmd * [ModelicaSystem] fix varable names - use snake_case naming style * [ModelicaSystem] add docstring for isParameterChangeable * [OMCSessionZMQ] fix another not needed else * fix exception string * fix pylint hints about (internal) variable names OMPython/OMCSession.py:1106:8: C0103: Attribute name "_dockerExtraArgs" doesn't conform to snake_case naming style (invalid-name) OMPython/OMCSession.py:1107:8: C0103: Attribute name "_dockerOpenModelicaPath" doesn't conform to snake_case naming style (invalid-name) OMPython/OMCSession.py:1108:8: C0103: Attribute name "_dockerNetwork" doesn't conform to snake_case naming style (invalid-name) OMPython/OMCSession.py:1110:8: C0103: Attribute name "_interactivePort" doesn't conform to snake_case naming style (invalid-name) OMPython/OMCSession.py:1112:8: C0103: Attribute name "_dockerCid" doesn't conform to snake_case naming style (invalid-name) OMPython/OMCSession.py:1121:12: C0103: Variable name "dockerTop" doesn't conform to snake_case naming style (invalid-name) OMPython/OMCSession.py:1282:8: C0103: Variable name "extraFlags" doesn't conform to snake_case naming style (invalid-name) OMPython/OMCSession.py:1297:12: C0103: Variable name "dockerNetworkStr" doesn't conform to snake_case naming style (invalid-name) * reorder imports in tests based on pylint * [OMCSessionCmd] update exception string * [ModelicaSystemCmd] fix docstring
1 parent 53abbc1 commit 8926af4

12 files changed

+167
-111
lines changed

OMPython/ModelicaSystem.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ def __getitem__(self, index: int):
119119

120120

121121
class ModelicaSystemCmd:
122-
"""A compiled model executable."""
122+
"""
123+
All information about a compiled model executable. This should include data about all structured parameters, i.e.
124+
parameters which need a recompilation of the model. All non-structured parameters can be easily changed without
125+
the need for recompilation.
126+
"""
123127

124128
def __init__(
125129
self,
@@ -505,10 +509,10 @@ def _loadLibrary(self, libraries: list):
505509
if element is not None:
506510
if isinstance(element, str):
507511
if element.endswith(".mo"):
508-
apiCall = "loadFile"
512+
api_call = "loadFile"
509513
else:
510-
apiCall = "loadModel"
511-
self._requestApi(apiName=apiCall, entity=element)
514+
api_call = "loadModel"
515+
self._requestApi(apiName=api_call, entity=element)
512516
elif isinstance(element, tuple):
513517
if not element[1]:
514518
expr_load_lib = f"loadModel({element[0]})"
@@ -563,8 +567,8 @@ def buildModel(self, variableFilter: Optional[str] = None):
563567
else:
564568
var_filter = 'variableFilter=".*"'
565569

566-
buildModelResult = self._requestApi(apiName="buildModel", entity=self._model_name, properties=var_filter)
567-
logger.debug("OM model build result: %s", buildModelResult)
570+
build_model_result = self._requestApi(apiName="buildModel", entity=self._model_name, properties=var_filter)
571+
logger.debug("OM model build result: %s", build_model_result)
568572

569573
# check if the executable exists ...
570574
om_cmd = ModelicaSystemCmd(
@@ -580,7 +584,7 @@ def buildModel(self, variableFilter: Optional[str] = None):
580584
if returncode != 0:
581585
raise ModelicaSystemError("Model executable not working!")
582586

583-
xml_file = self._session.omcpath(buildModelResult[0]).parent / buildModelResult[1]
587+
xml_file = self._session.omcpath(build_model_result[0]).parent / build_model_result[1]
584588
self._xmlparse(xml_file=xml_file)
585589

586590
def sendExpression(self, expr: str, parsed: bool = True) -> Any:
@@ -618,13 +622,13 @@ def _xmlparse(self, xml_file: OMCPath):
618622

619623
xml_content = xml_file.read_text()
620624
tree = ET.ElementTree(ET.fromstring(xml_content))
621-
rootCQ = tree.getroot()
622-
for attr in rootCQ.iter('DefaultExperiment'):
625+
root = tree.getroot()
626+
for attr in root.iter('DefaultExperiment'):
623627
for key in ("startTime", "stopTime", "stepSize", "tolerance",
624628
"solver", "outputFormat"):
625629
self._simulate_options[key] = str(attr.get(key))
626630

627-
for sv in rootCQ.iter('ScalarVariable'):
631+
for sv in root.iter('ScalarVariable'):
628632
translations = {
629633
"alias": "alias",
630634
"aliasvariable": "aliasVariable",
@@ -1405,6 +1409,10 @@ def isParameterChangeable(
14051409
self,
14061410
name: str,
14071411
) -> bool:
1412+
"""
1413+
Return if the parameter defined by name is changeable (= non-structural; can be modified without the need to
1414+
recompile the model).
1415+
"""
14081416
q = self.getQuantities(name)
14091417
if q[0]["changeable"] == "false":
14101418
return False
@@ -1670,10 +1678,10 @@ def convertMo2Fmu(
16701678
fileNamePrefix = "<default>"
16711679
else:
16721680
fileNamePrefix = self._model_name
1673-
includeResourcesStr = "true" if includeResources else "false"
1681+
include_resources_str = "true" if includeResources else "false"
16741682

16751683
properties = (f'version="{version}", fmuType="{fmuType}", '
1676-
f'fileNamePrefix="{fileNamePrefix}", includeResources={includeResourcesStr}')
1684+
f'fileNamePrefix="{fileNamePrefix}", includeResources={include_resources_str}')
16771685
fmu = self._requestApi(apiName='buildModelFMU', entity=self._model_name, properties=properties)
16781686
fmu_path = self._session.omcpath(fmu)
16791687

@@ -1742,12 +1750,9 @@ def optimize(self) -> dict[str, Any]:
17421750
'timeTemplates': 0.002007785,
17431751
'timeTotal': 1.079097854}
17441752
"""
1745-
cName = self._model_name
17461753
properties = ','.join(f"{key}={val}" for key, val in self._optimization_options.items())
17471754
self.set_command_line_options("-g=Optimica")
1748-
optimizeResult = self._requestApi(apiName='optimize', entity=cName, properties=properties)
1749-
1750-
return optimizeResult
1755+
return self._requestApi(apiName='optimize', entity=self._model_name, properties=properties)
17511756

17521757
def linearize(
17531758
self,

0 commit comments

Comments
 (0)