Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling of RMS yaml writer for speedup #2508

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions documentation/source/users/rmg/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ Miscellaneous options::
saveSeedToDatabase=True,
units='si',
generateOutputHTML=True,
generateRMSEachIter=True,
generatePlots=False,
saveSimulationProfiles=True,
verboseComments=False,
Expand All @@ -976,6 +977,8 @@ The ``units`` field is set to ``si``. Currently there are no other unit options
Setting ``generateOutputHTML`` to ``True`` will let RMG know that you want to save 2-D images (png files in the local ``species`` folder) of all species in the generated core model. It will save a visualized
HTML file for your model containing all the species and reactions. Turning this feature off by setting it to ``False`` may save memory if running large jobs.

Setting ``generateRMSEachIter`` to ``True`` will have rmg generate an output yaml file containing the core mechanism for the current iteration, with the number of core species appended to the name of the file (e.g. for 28 core species, the file will be named ``chem28.rms``). If it is ``False`` then only one file will be generated at the end of the run. A value of ``False`` may result in a faster run, as this feature can take up a lot of cpu time.

Setting ``generatePlots`` to ``True`` will generate a number of plots describing the statistics of the RMG job, including the reaction model core and edge size and memory use versus execution time. These will be placed in the output directory in the plot/ folder.

Setting ``saveSimulationProfiles`` to ``True`` will make RMG save csv files of the simulation in .csv files in the ``solver/`` folder. The filename will be ``simulation_1_26.csv`` where the first number corresponds to the reaciton system, and the second number corresponds to the total number of species at the point of the simulation. Therefore, the highest second number will indicate the latest simulation that RMG has complete while enlarging the core model. The information inside the csv file will provide the time, reactor volume in m^3, as well as mole fractions of the individual species.
Expand Down
6 changes: 4 additions & 2 deletions rmgpy/rmg/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,8 +1337,8 @@ def pressure_dependence(

def options(name='Seed', generateSeedEachIteration=True, saveSeedToDatabase=False, units='si', saveRestartPeriod=None,
generateOutputHTML=False, generatePlots=False, saveSimulationProfiles=False, verboseComments=False,
saveEdgeSpecies=False, keepIrreversible=False, trimolecularProductReversible=True, wallTime='00:00:00:00',
saveSeedModulus=-1):
saveEdgeSpecies=False, keepIrreversible=False, trimolecularProductReversible=True, generateRMSEachIter=True,
wallTime='00:00:00:00', saveSeedModulus=-1):
if saveRestartPeriod:
logging.warning("`saveRestartPeriod` flag was set in the input file, but this feature has been removed. Please "
"remove this line from the input file. This will throw an error after RMG-Py 3.1. For "
Expand All @@ -1352,6 +1352,7 @@ def options(name='Seed', generateSeedEachIteration=True, saveSeedToDatabase=Fals
if generateOutputHTML:
logging.warning('Generate Output HTML option was turned on. Note that this will slow down model generation.')
rmg.generate_output_html = generateOutputHTML
rmg.generate_rms_each_iter = generateRMSEachIter
rmg.generate_plots = generatePlots
rmg.save_simulation_profiles = saveSimulationProfiles
rmg.verbose_comments = verboseComments
Expand Down Expand Up @@ -1800,6 +1801,7 @@ def save_input_file(path, rmg):
f.write('options(\n')
f.write(' units = "{0}",\n'.format(rmg.units))
f.write(' generateOutputHTML = {0},\n'.format(rmg.generate_output_html))
f.write(' generateRMSEachIter = {0},\n'.format(rmg.generate_rms_each_iter))
f.write(' generatePlots = {0},\n'.format(rmg.generate_plots))
f.write(' saveSimulationProfiles = {0},\n'.format(rmg.save_simulation_profiles))
f.write(' saveEdgeSpecies = {0},\n'.format(rmg.save_edge_species))
Expand Down
22 changes: 21 additions & 1 deletion rmgpy/rmg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,10 @@ def register_listeners(self):
"""

self.attach(ChemkinWriter(self.output_directory))
self.attach(RMSWriter(self.output_directory))

if self.generate_rms_each_iter:
self.attach(RMSWriter(self.output_directory))

if self.generate_output_html:
self.attach(OutputHTMLWriter(self.output_directory))

Expand Down Expand Up @@ -1187,6 +1189,24 @@ def execute(self, initialize=True, **kwargs):
except Exception:
logging.exception("Could not generate Cantera files for some reason.")

# if we're not writing rms files each iteration, only write one at the end.
if not self.generate_rms_each_iter:
from rmgpy.yml import write_yml

# make rms dir
dirname = os.path.join(self.output_directory, "rms")
if os.path.exists(dirname):
# The directory already exists, so delete it (and all its content!)
shutil.rmtree(dirname)
os.mkdir(dirname)

# save final rms file
solvent_data = None
if self.solvent:
solvent_data = self.database.solvation.get_solvent_data(self.solvent)
write_yml(self.reaction_model.core.species, self.reaction_model.core.reactions, solvent=self.solvent, solvent_data=solvent_data,
path=os.path.join(dirname, 'chem.rms'))

self.check_model()
# Write output file
logging.info("")
Expand Down
4 changes: 2 additions & 2 deletions rmgpy/yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def get_mech_dict(spcs, rxns, solvent='solvent', solvent_data=None):


def get_radicals(spc):
if spc.molecule[0].to_smiles() == "[O][O]": # treat oxygen as stable to improve radical analysis
if spc.molecule[0].smiles == "[O][O]": # treat oxygen as stable to improve radical analysis
return 0
else:
return spc.molecule[0].multiplicity-1
Expand All @@ -112,7 +112,7 @@ def obj_to_dict(obj, spcs, names=None, label="solvent"):
result_dict["type"] = "Species"
if obj.contains_surface_site():
result_dict["adjlist"] = obj.molecule[0].to_adjacency_list()
result_dict["smiles"] = obj.molecule[0].to_smiles()
result_dict["smiles"] = obj.molecule[0].smiles
result_dict["thermo"] = obj_to_dict(obj.thermo, spcs)
result_dict["radicalelectrons"] = get_radicals(obj)
if obj.liquid_volumetric_mass_transfer_coefficient_data:
Expand Down
1 change: 1 addition & 0 deletions test/regression/RMS_CSTR_liquid_oxidation/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
)

options(
generateRMSEachIter=False,
saveEdgeSpecies=True,
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@
options(
units='si',
saveEdgeSpecies=True,
generateRMSEachIter=False,
)
1 change: 1 addition & 0 deletions test/regression/RMS_liquidSurface_ch4o2cat/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@
options(
units="si",
saveEdgeSpecies=True,
generateRMSEachIter=False,
)
1 change: 1 addition & 0 deletions test/regression/aromatics/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@
saveSimulationProfiles = False,
saveEdgeSpecies = True,
verboseComments = False,
generateRMSEachIter=False,
)

1 change: 1 addition & 0 deletions test/regression/liquid_oxidation/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@

options(
saveEdgeSpecies=True,
generateRMSEachIter=False,
)
1 change: 1 addition & 0 deletions test/regression/nitrogen/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
options(
units='si',
saveEdgeSpecies=True,
generateRMSEachIter=False,
)

generatedSpeciesConstraints(
Expand Down
1 change: 1 addition & 0 deletions test/regression/oxidation/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
generatePlots=False,
saveEdgeSpecies=True,
saveSimulationProfiles=False,
generateRMSEachIter=False,
)

generatedSpeciesConstraints(
Expand Down
1 change: 1 addition & 0 deletions test/regression/sulfur/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

options(
generateOutputHTML=False,
generateRMSEachIter=False,
generatePlots=False,
saveEdgeSpecies=True,
saveSimulationProfiles=False,
Expand Down
1 change: 1 addition & 0 deletions test/regression/superminimal/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
units='si',
saveRestartPeriod=None,
generateOutputHTML=True,
generateRMSEachIter=False,
generatePlots=True,
saveEdgeSpecies=True,
saveSimulationProfiles=True,
Expand Down
6 changes: 6 additions & 0 deletions test/rmgpy/rmg/mainTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ def test_rmg_execute(self):
assert isinstance(self.rmg.database, RMGDatabase)
assert self.rmg.done

def test_disable_rms_yaml_writer(self):
"""
generateRMSEachIter = False in input should set the corresponding property in RMG instance
"""
self.assertFalse(self.rmg.generate_rms_each_iter)

def test_rmg_increases_reactions(self):
"""Test that RMG.execute increases reactions and species."""
assert len(self.rmg.reaction_model.core.reactions) > 0
Expand Down
1 change: 1 addition & 0 deletions test/rmgpy/test_data/mainTest/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
name='testSeed',
units='si',
generateSeedEachIteration=True,
generateRMSEachIter=False,
saveSeedToDatabase=True,
generateOutputHTML=False,
generatePlots=False,
Expand Down
Loading