@@ -1201,8 +1201,8 @@ def _verify_model_exists(model_name):
1201
1201
1202
1202
if self ._modelica_tool == 'dymola' :
1203
1203
for ent in self ._data :
1204
- ent ['dymola' ]['time_out' ] = 10 # fixme 300
1205
- else : # Non-dymola
1204
+ ent ['dymola' ]['time_out' ] = 10 # fixme 300
1205
+ else : # Non-dymola
1206
1206
def_dic = {}
1207
1207
def_dic [self ._modelica_tool ] = {
1208
1208
'translate' : True ,
@@ -1290,7 +1290,6 @@ def _verify_model_exists(model_name):
1290
1290
if self ._reporter .getNumberOfErrors () > 0 :
1291
1291
raise ValueError (f"Wrong specification in { conf_file_name } ." )
1292
1292
1293
-
1294
1293
def _checkDataDictionary (self ):
1295
1294
""" Check if the data used to run the regression tests do not have duplicate ``*.fmu`` files
1296
1295
and ``*.mat`` names.
@@ -2909,7 +2908,8 @@ def _checkSimulationError(self, errorFile):
2909
2908
for k , v in list (self ._error_dict .get_dictionary ().items ()):
2910
2909
# For OPTIMICA, we neither have simulate nor FMUExport
2911
2910
if ele [key ][k ] > 0 :
2912
- self ._reporter .writeWarning (v ["model_message" ].format (ele [key ]["command" ]))
2911
+ self ._reporter .writeWarning (
2912
+ v ["model_message" ].format (ele [key ]["command" ]))
2913
2913
self ._error_dict .increment_counter (k )
2914
2914
2915
2915
if hasTranslationError and logFil is not None :
@@ -2921,8 +2921,10 @@ def _checkSimulationError(self, errorFile):
2921
2921
with open (logFil , "r" ) as f2 :
2922
2922
f .write (f2 .read ())
2923
2923
else :
2924
- # Logfile does not exists, which may be because simulation was terminated due to time out
2925
- f .write (f"Log file { logFil } does not exist, this can happen if the process was terminated due to time out." )
2924
+ # Logfile does not exists, which may be because simulation was terminated
2925
+ # due to time out
2926
+ f .write (
2927
+ f"Log file { logFil } does not exist, this can happen if the process was terminated due to time out." )
2926
2928
f .write ("\n \n \n " )
2927
2929
2928
2930
if iChe > 0 :
@@ -3101,7 +3103,6 @@ def _write_runscript_dymola(self, iPro, tra_data_pro):
3101
3103
for tra_data in tra_data_pro :
3102
3104
self ._write_dymola_script (iPro , tra_data )
3103
3105
3104
-
3105
3106
def _write_dymola_script (self , iPro , tra_data ):
3106
3107
"""Create the run_modelName.mos script for the current model and for Dymola,
3107
3108
and return the number of generated regression tests.
@@ -3141,7 +3142,7 @@ def _print_end_of_json(isLastItem, fileHandle, logFileName):
3141
3142
3142
3143
statistics_log = f"{ tra_data ['model_name' ]} .statistics.log"
3143
3144
runFil = open (os .path .join (self ._temDir [iPro ], self .getLibraryName (),
3144
- f"run_{ tra_data ['model_name' ]} .mos" ), mode = "w" , encoding = "utf-8" )
3145
+ f"run_{ tra_data ['model_name' ]} .mos" ), mode = "w" , encoding = "utf-8" )
3145
3146
runFil .write (
3146
3147
f"""// File autogenerated for process { iPro + 1 } of { self ._nPro }
3147
3148
// File created for execution by { self ._modelica_tool } . Do not edit.
@@ -3185,12 +3186,12 @@ def _print_end_of_json(isLastItem, fileHandle, logFileName):
3185
3186
Modelica.Utilities.Streams.print("{\"testCase\" : [", "%s");
3186
3187
""" % statistics_log )
3187
3188
3188
- #if self._isPresentAndTrue(
3189
+ # if self._isPresentAndTrue(
3189
3190
# 'translate',
3190
3191
# tra_data['dymola']) or self._isPresentAndTrue(
3191
3192
# 'exportFMU',
3192
3193
# tra_data['dymola']):
3193
- #nItem = nItem + 1
3194
+ #nItem = nItem + 1
3194
3195
3195
3196
# iItem = 0
3196
3197
# Write unit tests for this process
@@ -3200,7 +3201,7 @@ def _print_end_of_json(isLastItem, fileHandle, logFileName):
3200
3201
tra_data ['dymola' ]) or self ._isPresentAndTrue (
3201
3202
'exportFMU' ,
3202
3203
tra_data ['dymola' ]):
3203
- isLastItem = True # (iItem == nItem - 1)
3204
+ isLastItem = True # (iItem == nItem - 1)
3204
3205
mosFilNam = os .path .join (self .getLibraryName (),
3205
3206
"Resources" , "Scripts" , "Dymola" ,
3206
3207
tra_data ['ScriptFile' ])
@@ -3564,7 +3565,6 @@ def _write_run_all_script(self, iPro, tra_data_pro):
3564
3565
txt += " import os;\n "
3565
3566
fil .write (txt )
3566
3567
3567
-
3568
3568
def _write_python_runscripts (self , iPro , tra_data_pro ):
3569
3569
""" Write the Python runfiles for all experiments in tra_data_pro.
3570
3570
@@ -3632,7 +3632,7 @@ def _write_python_runscripts(self, iPro, tra_data_pro):
3632
3632
lambda m : '[{}]' .format (m .group ()),
3633
3633
re .sub (' ' , '' , x )) for x in result_variables ]
3634
3634
)
3635
- else : # dymola
3635
+ else : # dymola
3636
3636
# assemble command
3637
3637
cmd = list ()
3638
3638
cmd .append (f"{ self .getModelicaCommand ()} " )
@@ -3644,14 +3644,14 @@ def _write_python_runscripts(self, iPro, tra_data_pro):
3644
3644
model = model ,
3645
3645
working_directory = directory ,
3646
3646
library_name = self .getLibraryName (),
3647
- #ncp=dat[self._modelica_tool]['ncp'],
3648
- #rtol=dat[self._modelica_tool]['rtol'],
3649
- #solver=dat[self._modelica_tool]['solver'],
3650
- #start_time='mod.get_default_experiment_start_time()',
3651
- #final_time='mod.get_default_experiment_stop_time()',
3652
- #simulate=dat[self._modelica_tool]['simulate'],
3647
+ # ncp=dat[self._modelica_tool]['ncp'],
3648
+ # rtol=dat[self._modelica_tool]['rtol'],
3649
+ # solver=dat[self._modelica_tool]['solver'],
3650
+ # start_time='mod.get_default_experiment_start_time()',
3651
+ # final_time='mod.get_default_experiment_stop_time()',
3652
+ # simulate=dat[self._modelica_tool]['simulate'],
3653
3653
time_out = dat [self ._modelica_tool ]['time_out' ],
3654
- cmd = cmd
3654
+ cmd = cmd
3655
3655
)
3656
3656
3657
3657
file_name = os .path .join (directory , "{}.py" .format (model .replace ("." , "_" )))
@@ -3747,8 +3747,10 @@ def _get(model, key, data):
3747
3747
temp ['model' ] = case ['model' ]
3748
3748
temp ['simulation' ] = {}
3749
3749
temp ['simulation' ]['elapsed_time' ] = case ['simulate' ]['elapsed_time' ] if 'elapsed_time' in case ['simulate' ] else 0
3750
- temp ['simulation' ]['start_time' ] = case ['simulate' ]['start_time' ] if 'start_time' in case ['simulate' ] else _get (case ['model' ], 'startTime' , self ._data )
3751
- temp ['simulation' ]['final_time' ] = case ['simulate' ]['final_time' ] if 'final_time' in case ['simulate' ] else _get (case ['model' ], 'stopTime' , self ._data )
3750
+ temp ['simulation' ]['start_time' ] = case ['simulate' ]['start_time' ] if 'start_time' in case ['simulate' ] else _get (
3751
+ case ['model' ], 'startTime' , self ._data )
3752
+ temp ['simulation' ]['final_time' ] = case ['simulate' ]['final_time' ] if 'final_time' in case ['simulate' ] else _get (
3753
+ case ['model' ], 'stopTime' , self ._data )
3752
3754
temp ['simulation' ]['jacobians' ] = case ['simulate' ]['jacobians' ] if 'jacobians' in case ['simulate' ] else 0
3753
3755
temp ['simulation' ]['state_events' ] = case ['simulate' ]['state_events' ] if 'state_events' in case ['simulate' ] else 0
3754
3756
temp ['simulation' ]['success' ] = case ['simulate' ]['result' ]
@@ -3841,9 +3843,9 @@ def run(self):
3841
3843
tem_dir = []
3842
3844
libNam = self .getLibraryName ()
3843
3845
for di in self ._temDir :
3844
- #if self._modelica_tool == 'dymola':
3846
+ # if self._modelica_tool == 'dymola':
3845
3847
# tem_dir.append(os.path.join(di, libNam))
3846
- #else:
3848
+ # else:
3847
3849
# tem_dir.append(di)
3848
3850
tem_dir .append (di )
3849
3851
@@ -3895,64 +3897,68 @@ def run(self):
3895
3897
stat = list ()
3896
3898
for d in self ._temDir :
3897
3899
for temLogFilNam in glob .glob (
3898
- os .path .join (d , self .getLibraryName (), '*.statistics.log' )):
3899
- if os .path .exists (temLogFilNam ):
3900
- with open (temLogFilNam .replace ('Temp\t mp' , 'Temp\\ tmp' ), mode = "r" , encoding = "utf-8-sig" ) as temSta :
3901
- try :
3902
- jsonLog = json .load (temSta )
3903
- cas = jsonLog ["testCase" ]
3904
- # Iterate over all test cases of this output file
3905
- for ele in cas :
3906
- stat .append (ele )
3907
- except json .decoder .JSONDecodeError as e :
3908
- # If a run timed out, then temLogFilNam is not a valid json file
3909
- # because the file is written on the fly, and dymola did not finish
3910
- # writing all of it, which results in an invalid file.
3911
- # Check if /tmp/tmp-Buildings-1-o_m7nj7p/Buildings_Examples_VAVReheat_ASHRAE2006_buildingspy.json
3912
- # exists
3913
- modelName = os .path .split (temLogFilNam )[1 ].replace ('.statistics.log' , '' )
3914
- buiLogNam = os .path .join (
3915
- d ,
3916
- f"{ modelName .replace ('.' , '_' )} _buildingspy.json" )
3917
- if os .path .exists (buiLogNam ):
3918
- # Read the log file of the python script that invoked dymola
3919
- with open (buiLogNam , mode = "r" , encoding = "utf-8-sig" ) as buiLog :
3920
- jsonBui = json .load (buiLog )
3921
- # Build up the entry for reporting the case
3922
- if "simulation" in jsonBui and "exception" in jsonBui ["simulation" ]:
3923
- exception = '' .join (jsonBui ['simulation' ]['exception' ])
3924
- else :
3925
- exception = f"JSONDecodeError in { temLogFilNam } : { str (e )} "
3926
- ele = {
3927
- "model" : modelName ,
3928
- "simulate" : {
3929
- "command" : '' .join (jsonBui ['simulation' ]['cmd' ]),
3930
- "result" : False ,
3931
- "exception" : exception
3932
- }
3933
- }
3934
- self ._reporter .writeError (
3935
- f"Model '{ modelName } ' failed: { exception } " )
3936
- stat .append (ele )
3937
- # Add the failure also to self._data so that _checkReferencePoints is not trying to read the output.
3938
- for ele in self ._data :
3939
- if ele ['model_name' ] == modelName :
3940
- if "simulation" in ele [self ._modelica_tool ]:
3941
- ele [self ._modelica_tool ]['simulation' ]['success' ] = False
3942
- else :
3943
- ele [self ._modelica_tool ]['simulation' ] = {'success' : False }
3944
- else :
3900
+ os .path .join (d , self .getLibraryName (), '*.statistics.log' )):
3901
+ if os .path .exists (temLogFilNam ):
3902
+ with open (temLogFilNam .replace ('Temp\t mp' , 'Temp\\ tmp' ), mode = "r" , encoding = "utf-8-sig" ) as temSta :
3903
+ try :
3904
+ jsonLog = json .load (temSta )
3905
+ cas = jsonLog ["testCase" ]
3906
+ # Iterate over all test cases of this output file
3907
+ for ele in cas :
3908
+ stat .append (ele )
3909
+ except json .decoder .JSONDecodeError as e :
3910
+ # If a run timed out, then temLogFilNam is not a valid json file
3911
+ # because the file is written on the fly, and dymola did not finish
3912
+ # writing all of it, which results in an invalid file.
3913
+ # Check if /tmp/tmp-Buildings-1-o_m7nj7p/Buildings_Examples_VAVReheat_ASHRAE2006_buildingspy.json
3914
+ # exists
3915
+ modelName = os .path .split (temLogFilNam )[
3916
+ 1 ].replace ('.statistics.log' , '' )
3917
+ buiLogNam = os .path .join (
3918
+ d ,
3919
+ f"{ modelName .replace ('.' , '_' )} _buildingspy.json" )
3920
+ if os .path .exists (buiLogNam ):
3921
+ # Read the log file of the python script that invoked dymola
3922
+ with open (buiLogNam , mode = "r" , encoding = "utf-8-sig" ) as buiLog :
3923
+ jsonBui = json .load (buiLog )
3924
+ # Build up the entry for reporting the case
3925
+ if "simulation" in jsonBui and "exception" in jsonBui ["simulation" ]:
3926
+ exception = '' .join (
3927
+ jsonBui ['simulation' ]['exception' ])
3928
+ else :
3929
+ exception = f"JSONDecodeError in { temLogFilNam } : { str (e )} "
3930
+ ele = {
3931
+ "model" : modelName ,
3932
+ "simulate" : {
3933
+ "command" : '' .join (
3934
+ jsonBui ['simulation' ]['cmd' ]),
3935
+ "result" : False ,
3936
+ "exception" : exception }}
3945
3937
self ._reporter .writeError (
3946
- f"Decoding '{ temLogFilNam } ' failed and '{ buiLogNam } ' does not exist: { e } " )
3947
- raise
3948
- except ValueError as e :
3938
+ f"Model '{ modelName } ' failed: { exception } " )
3939
+ stat .append (ele )
3940
+ # Add the failure also to self._data so that
3941
+ # _checkReferencePoints is not trying to read the
3942
+ # output.
3943
+ for ele in self ._data :
3944
+ if ele ['model_name' ] == modelName :
3945
+ if "simulation" in ele [self ._modelica_tool ]:
3946
+ ele [self ._modelica_tool ]['simulation' ]['success' ] = False
3947
+ else :
3948
+ ele [self ._modelica_tool ]['simulation' ] = {
3949
+ 'success' : False }
3950
+ else :
3949
3951
self ._reporter .writeError (
3950
- "Loading '%s ' failed: %s" % ( temLogFilNam , e ) )
3952
+ f"Decoding ' { temLogFilNam } ' failed and ' { buiLogNam } ' does not exist: { e } " )
3951
3953
raise
3952
- else :
3953
- self ._reporter .writeError (
3954
- "Log file '" + temLogFilNam + "' does not exist.\n " )
3955
- retVal = 1
3954
+ except ValueError as e :
3955
+ self ._reporter .writeError (
3956
+ "Loading '%s' failed: %s" % (temLogFilNam , e ))
3957
+ raise
3958
+ else :
3959
+ self ._reporter .writeError (
3960
+ "Log file '" + temLogFilNam + "' does not exist.\n " )
3961
+ retVal = 1
3956
3962
# Dump an array of testCase objects
3957
3963
# dump to a string first using json.dumps instead of json.dump
3958
3964
json_string = json .dumps ({"testCase" : stat },
0 commit comments