1515from rmgpy .chemkin import writeThermoEntry
1616from rmgpy .rmg .model import makeThermoForSpecies
1717from scoop import futures ,shared
18+ import resource # to see memory usage
1819################################################################################
1920def chunks (l , n ):
2021 """
@@ -23,31 +24,43 @@ def chunks(l, n):
2324 for i in range (0 , len (l ), n ):
2425 yield l [i :i + n ]
2526
26- def runThermoEstimator (inputFile ):
27+ def runThermoEstimator (inputFile , chunkSize ):
2728 """
2829 Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file.
2930 """
30-
31+ logging . debug ( "Maximum memory usage:{0} MBs." . format ( resource . getrusage ( resource . RUSAGE_SELF ). ru_maxrss / 1000 ))
3132 rmg = RMG ()
33+
34+ logging .debug ("RMG object created..." )
35+ logging .debug ("Maximum memory usage:{0} MBs." .format (resource .getrusage (resource .RUSAGE_SELF ).ru_maxrss / 1000 ))
3236 rmg .loadThermoInput (inputFile )
37+ logging .debug ("Input file loaded..." )
38+ logging .debug ("Maximum memory usage:{0} MBs." .format (resource .getrusage (resource .RUSAGE_SELF ).ru_maxrss / 1000 ))
3339
3440 # initialize and load the database as well as any QM settings
3541 rmg .loadThermoDatabase ()
42+ logging .debug ("Thermo database loaded..." )
43+ logging .debug ("Maximum memory usage:{0} MBs." .format (resource .getrusage (resource .RUSAGE_SELF ).ru_maxrss / 1000 ))
3644 if rmg .quantumMechanics :
37- logging .debug ("Initialize QM" )
3845 rmg .quantumMechanics .initialize ()
46+ logging .debug ("QM module initialized..." )
47+ logging .debug ("Maximum memory usage:{0} MBs." .format (resource .getrusage (resource .RUSAGE_SELF ).ru_maxrss / 1000 ))
3948
4049 # Generate the thermo for all the species and write them to chemkin format as well as
4150 # ThermoLibrary format with values for H, S, and Cp's.
4251 output = open (os .path .join (rmg .outputDirectory , 'output.txt' ),'wb' )
43- library = ThermoLibrary (name = 'Thermo Estimation Library' )
4452 listOfSpecies = rmg .initialSpecies
45- chunksize = 1000
46- if rmg .reactionModel .quantumMechanics : logging .debug ("qmValue fine @ runThermoEstimator" )
53+ logging .debug ("Initial species loaded..." )
54+ logging .debug ("Maximum memory usage:{0} MBs." .format (resource .getrusage (resource .RUSAGE_SELF ).ru_maxrss / 1000 ))
55+
56+ chunkIndex = 0
4757 shared .setConst (qmValue = rmg .reactionModel .quantumMechanics )
48- for chunk in list (chunks (listOfSpecies ,chunksize )):
58+ for chunk in list (chunks (listOfSpecies ,chunkSize )):
4959 # There will be no stdout from workers except the main one.
5060 outputList = futures .map (makeThermoForSpecies , chunk )
61+ if chunkIndex == 0 : libraryName = 'ThermoLibrary'
62+ else : libraryName = 'ThermoLibrary' + str (chunkIndex )
63+ library = ThermoLibrary (name = libraryName )
5164 for species , thermo in zip (chunk , outputList ):
5265 logging .debug ("Species {0}" .format (species .label ))
5366 species .thermo = thermo
@@ -60,16 +73,19 @@ def runThermoEstimator(inputFile):
6073 )
6174 output .write (writeThermoEntry (species ))
6275 output .write ('\n ' )
63- library .save (os .path .join (rmg .outputDirectory ,'ThermoLibrary.py' ))
64-
76+ logging .debug ("Thermo library created..." )
77+ logging .debug ("Maximum memory usage:{0} MBs." .format (resource .getrusage (resource .RUSAGE_SELF ).ru_maxrss / 1000 ))
78+ library .save (os .path .join (rmg .outputDirectory , libraryName + '.py' ))
79+ del library
80+ chunkIndex += 1
6581 output .close ()
82+ logging .debug ("runThermoEstimator is done." )
6683
6784
6885
6986################################################################################
7087
7188if __name__ == '__main__' :
72-
7389 import argparse
7490
7591 parser = argparse .ArgumentParser (description =
@@ -83,6 +99,8 @@ def runThermoEstimator(inputFile):
8399 """ )
84100 parser .add_argument ('input' , metavar = 'FILE' , type = str , nargs = 1 ,
85101 help = 'Thermo input file' )
102+ parser .add_argument ('CHUNKSIZE' , type = int , default = 10000 ,nargs = '?' , help = '''chunk size that determines number of species passed to
103+ workers at once, should be larger than the number of processors. (default value is 10000)''' )
86104 parser .add_argument ('-p' , '--profile' , action = 'store_true' , help = 'run under cProfile to gather profiling statistics, and postprocess them if job completes' )
87105 parser .add_argument ('-P' , '--postprocess' , action = 'store_true' , help = 'postprocess profiling statistics from previous [failed] run; does not run the simulation' )
88106 group = parser .add_mutually_exclusive_group ()
@@ -94,18 +112,18 @@ def runThermoEstimator(inputFile):
94112
95113 inputFile = os .path .abspath (args .input [0 ])
96114 inputDirectory = os .path .abspath (os .path .dirname (args .input [0 ]))
97-
115+ chunkSize = args . CHUNKSIZE
98116 if args .postprocess :
99117 print "Postprocessing the profiler statistics (will be appended to thermo.log)"
100- print "Use `dot -Tpdf thermo_profile. dot -o thermo_profile .pdf`"
118+ print "Use `dot -Tpdf RMG.profile. dot -o RMG.profile .pdf`"
101119 args .profile = True
102120
103121 if args .profile :
104122 import cProfile , sys , pstats , os
105123 global_vars = {}
106124 local_vars = {'inputFile' : inputFile ,'runThermoEstimator' :runThermoEstimator }
107125 command = """runThermoEstimator(inputFile)"""
108- stats_file = 'thermo .profile'
126+ stats_file = 'RMG .profile'
109127 print ("Running under cProfile" )
110128 if not args .postprocess :
111129 # actually run the program!
@@ -122,4 +140,4 @@ def runThermoEstimator(inputFile):
122140 else : level = logging .INFO
123141 initializeLog (level , 'RMG.log' )
124142 logging .debug ("runThermoEstimator starts..." )
125- runThermoEstimator (inputFile )
143+ runThermoEstimator (inputFile , chunkSize )
0 commit comments