@@ -322,8 +322,8 @@ def __init__(
322
322
customBuildDirectory : Optional [str | os .PathLike | pathlib .Path ] = None ,
323
323
omhome : Optional [str ] = None ,
324
324
session : Optional [OMCSessionZMQ ] = None ,
325
- build : Optional [bool ] = True
326
- ) :
325
+ build : Optional [bool ] = True ,
326
+ ) -> None :
327
327
"""Initialize, load and build a model.
328
328
329
329
The constructor loads the model file and builds it, generating exe and
@@ -401,8 +401,8 @@ def __init__(
401
401
self .inputFlag = False # for model with input quantity
402
402
self .simulationFlag = False # if the model is simulated?
403
403
self .outputFlag = False
404
- self .csvFile = '' # for storing inputs condition
405
- self .resultfile = None # for storing result file
404
+ self .csvFile : Optional [ pathlib . Path ] = None # for storing inputs condition
405
+ self .resultfile : Optional [ pathlib . Path ] = None # for storing result file
406
406
self .variableFilter = variableFilter
407
407
408
408
if self .fileName is not None and not self .fileName .is_file (): # if file does not exist
@@ -427,7 +427,7 @@ def __init__(
427
427
if build :
428
428
self .buildModel (variableFilter )
429
429
430
- def setCommandLineOptions (self , commandLineOptions : str ):
430
+ def setCommandLineOptions (self , commandLineOptions : Optional [ str ] = None ):
431
431
# set commandLineOptions if provided by users
432
432
if commandLineOptions is None :
433
433
return
@@ -462,7 +462,7 @@ def loadLibrary(self, lmodel: list):
462
462
'1)["Modelica"]\n '
463
463
'2)[("Modelica","3.2.3"), "PowerSystems"]\n ' )
464
464
465
- def setTempDirectory (self , customBuildDirectory ) -> pathlib .Path :
465
+ def setTempDirectory (self , customBuildDirectory : Optional [ str | os . PathLike | pathlib . Path ] = None ) -> pathlib .Path :
466
466
# create a unique temp directory for each session and build the model in that directory
467
467
if customBuildDirectory is not None :
468
468
if not os .path .exists (customBuildDirectory ):
@@ -482,22 +482,22 @@ def setTempDirectory(self, customBuildDirectory) -> pathlib.Path:
482
482
def getWorkDirectory (self ) -> pathlib .Path :
483
483
return self .tempdir
484
484
485
- def buildModel (self , variableFilter = None ):
485
+ def buildModel (self , variableFilter : Optional [ str ] = None ):
486
486
if variableFilter is not None :
487
487
self .variableFilter = variableFilter
488
488
489
489
if self .variableFilter is not None :
490
490
varFilter = f'variableFilter="{ self .variableFilter } "'
491
491
else :
492
492
varFilter = 'variableFilter=".*"'
493
- logger . debug ( "varFilter=%s" , varFilter )
493
+
494
494
buildModelResult = self .requestApi ("buildModel" , self .modelName , properties = varFilter )
495
495
logger .debug ("OM model build result: %s" , buildModelResult )
496
496
497
497
self .xmlFile = pathlib .Path (buildModelResult [0 ]).parent / buildModelResult [1 ]
498
498
self .xmlparse ()
499
499
500
- def sendExpression (self , expr , parsed = True ):
500
+ def sendExpression (self , expr : str , parsed : bool = True ):
501
501
try :
502
502
retval = self .getconn .sendExpression (expr , parsed )
503
503
except OMCSessionException as ex :
@@ -522,7 +522,7 @@ def requestApi(self, apiName, entity=None, properties=None): # 2
522
522
return self .sendExpression (exp )
523
523
524
524
def xmlparse (self ):
525
- if not self .xmlFile .exists ():
525
+ if not self .xmlFile .is_file ():
526
526
raise ModelicaSystemError (f"XML file not generated: { self .xmlFile } " )
527
527
528
528
tree = ET .parse (self .xmlFile )
@@ -597,7 +597,7 @@ def getContinuous(self, names=None): # 4
597
597
try :
598
598
value = self .getSolutions (i )
599
599
self .continuouslist [i ] = value [0 ][- 1 ]
600
- except OMCSessionException as ex :
600
+ except ( OMCSessionException , ModelicaSystemError ) as ex :
601
601
raise ModelicaSystemError (f"{ i } could not be computed" ) from ex
602
602
return self .continuouslist
603
603
@@ -999,8 +999,8 @@ def isParameterChangeable(self, name, value):
999
999
if q [0 ]["changeable" ] == "false" :
1000
1000
logger .verbose (f"setParameters() failed : It is not possible to set the following signal { repr (name )} . "
1001
1001
"It seems to be structural, final, protected or evaluated or has a non-constant binding, "
1002
- f"use sendExpression(\" setParameterValue({ self .modelName } , { name } , { value } )\" , "
1003
- "parsed=False) and rebuild the model using buildModel() API" )
1002
+ f"use sendExpression(\" setParameterValue({ self .modelName } , { name } , { value } )\" ) "
1003
+ "and rebuild the model using buildModel() API" )
1004
1004
return False
1005
1005
return True
1006
1006
0 commit comments