Skip to content

Commit 4a8245a

Browse files
authored
Merge pull request #2800 to add native Cantera YAML writing
See #2800 for details. Enable in your options block with: generateCanteraYAML1=True, generateCanteraYAML2=True, Or customize with settings like: generateChemkin={'saveInterval': 1, 'saveEdge': False}, generateRMSYAML={'saveInterval': 5}, generateCanteraYAML1={'saveInterval': 5, 'saveEdge':True}, generateCanteraYAML2={'saveInterval': 5, 'saveEdge':False, 'verboseComments':True}, See provided examples and documentation for more.
2 parents 2b516ee + 458bb3f commit 4a8245a

38 files changed

Lines changed: 8703 additions & 149 deletions

documentation/source/users/rmg/input.rst

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,13 +1073,17 @@ Miscellaneous options::
10731073
units='si',
10741074
generateOutputHTML=True,
10751075
generatePlots=False,
1076-
generatePESDiagrams=False,
1076+
generatePESDiagrams=False,
10771077
saveSimulationProfiles=True,
10781078
verboseComments=False,
10791079
saveEdgeSpecies=True,
10801080
keepIrreversible=True,
10811081
trimolecularProductReversible=False,
1082-
saveSeedModulus=-1
1082+
saveSeedModulus=-1,
1083+
generateChemkin=True,
1084+
generateRMSYAML=True,
1085+
generateCanteraYAML1=False,
1086+
generateCanteraYAML2=False,
10831087
)
10841088

10851089
The ``name`` field is the name of any generated seed mechanisms
@@ -1090,25 +1094,97 @@ Setting ``saveSeedToDatabase`` to ``True`` tells RMG (if generating a seed) to a
10901094

10911095
The ``units`` field is set to ``si``. Currently there are no other unit options.
10921096

1093-
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
1094-
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.
1097+
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.
1098+
It will save a visualized HTML file for your model containing all the species and reactions.
1099+
Turning this feature off by setting it to ``False`` may save memory if running large jobs.
1100+
It can be configured using a dictionary of settings in place of the ``True`` statement, as described below.
10951101

10961102
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.
10971103

10981104
Setting ``generatePESDiagrams`` to ``True`` will generate potential energy surface diagrams for each pressure dependent network in the model. These diagrams will be saved in the ``pdep/`` folder in the output directory. Only applicable if pressure dependence is enabled.
10991105

11001106
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.
11011107

1102-
Setting ``verboseComments`` to ``True`` will make RMG generate chemkin files with complete verbose commentary for the kinetic and thermo parameters. This will be helpful in debugging what values are being averaged for the kinetics. Note that this may produce very large files.
1108+
Setting ``verboseComments`` to ``True`` will make RMG generate chemkin files with complete verbose commentary for the kinetic and thermo parameters. This will be helpful in debugging what values are being averaged for the kinetics. Note that this may produce very large files. This is a global fallback; individual writers can override it (see below).
11031109

1104-
Setting ``saveEdgeSpecies`` to ``True`` will make RMG generate chemkin files of the edge reactions in addition to the core model in files such as ``chem_edge.inp`` and ``chem_edge_annotated.inp`` files located inside the ``chemkin`` folder. These files will be helpful in viewing RMG's estimate for edge reactions and seeing if certain reactions one expects are actually in the edge or not.
1110+
Setting ``saveEdgeSpecies`` to ``True`` will make RMG generate chemkin files of the edge reactions in addition to the core model in files such as ``chem_edge.inp`` and ``chem_edge_annotated.inp`` files located inside the ``chemkin`` folder. These files will be helpful in viewing RMG's estimate for edge reactions and seeing if certain reactions one expects are actually in the edge or not. This is a global fallback; individual writers can override it (see below).
11051111

11061112
Setting ``keepIrreversible`` to ``True`` will make RMG import library reactions as is, whether they are reversible or irreversible in the library. Otherwise, if ``False`` (default value), RMG will force all library reactions to be reversible, and will assign the forward rate from the relevant library.
11071113

11081114
Setting ``trimolecularProductReversible`` to ``False`` will not allow families with three products to react in the reverse direction. Default is ``True``.
11091115

11101116
Setting ``saveSeedModulus`` to ``-1`` will only save the seed from the last iteration at the end of an RMG job. Alternatively, the seed can be saved every ``n`` iterations by setting ``saveSeedModulus`` to ``n``.
11111117

1118+
Per-writer Output Configuration
1119+
--------------------------------
1120+
1121+
Each of the following options controls a separate output-format writer.
1122+
Each accepts ``True``, ``False``, or a Python dict with optional keys:
1123+
1124+
* ``'saveInterval'`` *(int)* — positive N writes every N iterations (iteration
1125+
numbering starts at 0); ``-1`` writes only at the very end of the run.
1126+
Defaults to ``1`` (every iteration) for writers that are on by default.
1127+
* ``'verboseComments'`` *(bool, optional)* — overrides the global
1128+
``verboseComments`` flag for this writer only.
1129+
* ``'saveEdge'`` *(bool, optional)* — overrides the global ``saveEdgeSpecies``
1130+
flag for this writer only.
1131+
1132+
Examples::
1133+
1134+
# Chemkin: save only at the end, with verbose comments and edge species
1135+
generateChemkin={'saveInterval': -1, 'verboseComments': True, 'saveEdge': True}
1136+
1137+
# RMS YAML: save every 5 iterations
1138+
generateRMSYAML={'saveInterval': 5}
1139+
1140+
# Cantera YAML v2: save every iteration with verbose comments
1141+
generateCanteraYAML2={'saveInterval': 1, 'verboseComments': True, 'saveEdge': False}
1142+
1143+
``generateChemkin`` (default ``True``)
1144+
Controls the Chemkin writer. Output is written to the ``chemkin/`` folder.
1145+
When enabled, Cantera's ``ck2yaml`` converter is also run at the end of the
1146+
job to produce a ``cantera_from_ck/`` folder — see :ref:`output`.
1147+
1148+
``generateRMSYAML`` (default ``True``)
1149+
Controls the RMS YAML writer. Output is written to the ``rms/`` folder.
1150+
1151+
``generateCanteraYAML1`` (default ``False``) *(beta)*
1152+
Controls the *direct* Cantera YAML v1 writer. Output is written to the
1153+
``cantera1/`` folder. Unlike the ``cantera_from_ck`` route (which converts
1154+
a Chemkin file via ``ck2yaml``), this writer constructs the YAML directly
1155+
from RMG's internal Python objects without going through Chemkin at all.
1156+
It runs at every iteration (or on the configured schedule) so you get a
1157+
history of the growing mechanism.
1158+
1159+
.. warning::
1160+
1161+
This writer is in **beta**. The output should be valid Cantera YAML, but
1162+
it has been less extensively tested than the established
1163+
``cantera_from_ck`` route. If both this writer and the Chemkin writer
1164+
are enabled, a ``comparison_report.txt`` is generated at the end of the
1165+
run comparing the two outputs numerically. Please report discrepancies
1166+
on the `RMG-Py issue tracker
1167+
<https://github.com/ReactionMechanismGenerator/RMG-Py/issues>`_.
1168+
1169+
``generateCanteraYAML2`` (default ``False``) *(beta)*
1170+
Controls the *direct* Cantera YAML v2 writer. Output is written to the
1171+
``cantera2/`` folder. Like ``generateCanteraYAML1``, this writer bypasses
1172+
the Chemkin intermediate, but instead uses the Cantera Python API
1173+
(``ct.Solution``) to construct and serialise the mechanism. It also runs
1174+
at every iteration (or on the configured schedule).
1175+
1176+
.. warning::
1177+
1178+
This writer is in **beta**. It has been less extensively tested than the
1179+
established ``cantera_from_ck`` route. When enabled alongside the Chemkin
1180+
writer, a ``comparison_report.txt`` is generated at the end of the run.
1181+
Please report discrepancies on the `RMG-Py issue tracker
1182+
<https://github.com/ReactionMechanismGenerator/RMG-Py/issues>`_.
1183+
1184+
``generateOutputHTML`` (default ``False``)
1185+
Controls the HTML species-visualisation writer. Output is written to the
1186+
``species/`` folder. Accepts ``True``/``False`` or the same dict format.
1187+
11121188
Species Constraints
11131189
=====================
11141190

documentation/source/users/rmg/output.rst

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
Analyzing the Output Files
55
**************************
66

7-
You will see that a sucessfully executed RMG job will create multiple output files and folders:
7+
You will see that a sucessfully executed RMG job will create multiple output files and folders:
88
``output.html`` (if ``generateOutputHTML=True`` is specified)
9+
``/cantera_from_ck``
10+
``/cantera1`` (if ``generateCanteraYAML1=True`` is specified)
11+
``/cantera2`` (if ``generateCanteraYAML2=True`` is specified)
912
``/chemkin``
10-
``/pdep``
13+
``/pdep``
1114
``/plot``
15+
``/rms``
1216
``/solver``
13-
``/species``
17+
``/species``
1418
``RMG.log``
1519

1620
------------------
@@ -39,6 +43,92 @@ network.
3943

4044
------------------
4145
The Solver Folder
42-
------------------
43-
RMG currently includes a solver for isothermal batch reactors. This is in fact a critical part of the model enlargement algorithm. If you have included simulations in your input file, the solutions will be located in ``/solver``. You will probably only be interested in the files with the largest number tags.
46+
------------------
47+
RMG currently includes a solver for isothermal batch reactors. This is in fact a critical part of the model enlargement algorithm. If you have included simulations in your input file, the solutions will be located in ``/solver``. You will probably only be interested in the files with the largest number tags.
4448
Please note that up to and including RMG-Py version 2.3.0 these files showed mole fraction of each species at each step, but they now show amount (number of moles) of each species; you must divide by the sum if you wish to get a mole fraction.
49+
50+
------------------------------
51+
Cantera Output Folders
52+
------------------------------
53+
54+
RMG can write mechanisms in `Cantera <https://cantera.org>`_ YAML format via three distinct
55+
routes, producing up to three output folders. All three require Cantera to be installed in
56+
the conda environment (it is included in the standard ``rmg_env``).
57+
58+
``/cantera_from_ck``
59+
^^^^^^^^^^^^^^^^^^^^
60+
61+
This folder is always produced when the Chemkin writer is enabled (``generateChemkin=True``, the default).
62+
After the final RMG iteration, Cantera's own ``ck2yaml`` converter is used to translate the Chemkin-format files in ``/chemkin`` into Cantera YAML.
63+
This is the most thoroughly tested route and is the recommended output for production use.
64+
65+
``/cantera1`` *(beta)*
66+
^^^^^^^^^^^^^^^^^^^^^^
67+
68+
.. note::
69+
70+
The ``cantera1`` writer is in **beta**. It uses the Cantera Python API to construct and
71+
serialise the mechanism YAML, rather than writing the YAML by hand. It has been less
72+
extensively tested than the ``cantera_from_ck`` route. Please report any discrepancies.
73+
74+
This folder is created when ``generateCanteraYAML1=True`` is set in the ``options()`` block
75+
(disabled by default). The writer runs after every RMG iteration (or on the schedule set by
76+
``saveInterval``), so the folder accumulates a history of the growing mechanism.
77+
78+
Files generated:
79+
80+
* ``chem{NNNN}.yaml`` — mechanism snapshot at the iteration when the core contained *NNNN*
81+
species (e.g. ``chem0042.yaml``)
82+
* ``chem.yaml`` — copy of the latest snapshot; always reflects the current model state
83+
* ``chem_annotated.yaml`` — annotated version with SMILES, source, and kinetics comments
84+
(written when ``verboseComments=True`` for this writer)
85+
* ``chem_edge{NNNN}.yaml`` / ``chem_edge.yaml`` / ``chem_edge_annotated.yaml`` — edge-model
86+
equivalents (written when ``saveEdge=True``)
87+
* ``comparison_report.txt`` — numerical comparison of ``chem.yaml`` against the
88+
``cantera_from_ck`` translation (written at the end of the run if both writers are enabled;
89+
see below)
90+
91+
``/cantera2`` *(beta)*
92+
^^^^^^^^^^^^^^^^^^^^^^
93+
94+
.. note::
95+
96+
The ``cantera2`` writer is in **beta**. It generates Cantera YAML directly from RMG's
97+
internal Python data structures, without going through the Chemkin intermediate. While
98+
it should produce valid mechanisms, it has been less extensively tested than the
99+
``cantera_from_ck`` route. Please report any discrepancies.
100+
101+
This folder is created when ``generateCanteraYAML2=True`` is set in the ``options()`` block
102+
(disabled by default). Like ``cantera1``, it runs at every iteration (or on the configured
103+
schedule).
104+
105+
Files generated:
106+
107+
* ``chem{NNNN}.yaml`` / ``chem.yaml`` — latest mechanism snapshot and its labelled history
108+
* ``chem_annotated.yaml`` — annotated version (written when ``verboseComments=True``)
109+
* ``chem_edge{NNNN}.yaml`` / ``chem_edge.yaml`` / ``chem_edge_annotated.yaml`` — edge-model
110+
equivalents (written when ``saveEdge=True``)
111+
* ``comparison_report.txt`` — numerical comparison against the ``cantera_from_ck``
112+
translation (written at the end of the run if both writers are enabled)
113+
114+
Comparison Reports
115+
^^^^^^^^^^^^^^^^^^
116+
117+
When a direct-writer folder (``cantera1`` or ``cantera2``) is used alongside the Chemkin
118+
writer, RMG automatically compares the final ``chem.yaml`` from that folder against the
119+
``cantera_from_ck/chem.yaml`` produced by ``ck2yaml``. The comparison checks differences
120+
in the yaml data. Not all differences are necessarily problematic. Results are written to
121+
``comparison_report.txt`` inside the relevant direct-writer folder.
122+
123+
If you find that the two routes disagree in a problematic way, please open an issue on the
124+
`RMG-Py GitHub repository <https://github.com/ReactionMechanismGenerator/RMG-Py/issues>`_
125+
and include the ``comparison_report.txt`` and a minimal reproducing ``input.py``.
126+
127+
------------------------------
128+
The RMS YAML Folder
129+
------------------------------
130+
131+
The ``/rms`` folder contains the mechanism in
132+
`ReactionMechanismSimulator (RMS) <https://github.com/ReactionMechanismGenerator/ReactionMechanismSimulator.jl>`_
133+
YAML format. This writer is enabled by default (``generateRMSYAML=True``) and writes at
134+
every iteration, unless configured otherwise by ``saveInterval``.

documentation/source/users/rmg/running.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ at the command line will print the documentation from ``util.py``, which is repr
4848
-P, --postprocess postprocess profiling statistics from previous
4949
[failed] run; does not run the simulation
5050
-t DD:HH:MM:SS, --walltime DD:HH:MM:SS
51-
set the maximum execution time
51+
set the maximum execution time (overrides input.py if provided)
5252
-i MAXITER, --maxiter MAXITER
53-
set the maximum number of RMG iterations
53+
set the maximum number of RMG iterations (overrides input.py if provided)
5454
-n MAXPROC, --maxproc MAXPROC
5555
max number of processes used during reaction
5656
generation
@@ -73,7 +73,7 @@ Run with multiprocessing for reaction generation and QMTP::
7373

7474
python rmg.py -n <Max number of processes allowed> input.py
7575

76-
Run with setting a limit on the maximum execution time::
76+
Run with setting a limit on the maximum execution time (if specified, then the command-line value overrides any value read from ``input.py``)::
7777

7878
python rmg.py -t <DD:HH:MM:SS> input.py
7979

examples/rmg/1,3-hexadiene/input.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,9 @@
9090
generateOutputHTML=False,
9191
generatePlots=False,
9292
generatePESDiagrams=True,
93+
# Large model: write output every 5 iterations and skip edge species to reduce I/O
94+
generateChemkin={'saveInterval': 1, 'saveEdge': False},
95+
generateRMSYAML={'saveInterval': 5},
96+
generateCanteraYAML1={'saveInterval': 5},
97+
generateCanteraYAML2={'saveInterval': 5},
9398
)

examples/rmg/MR_test/input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@
260260
#Sets a time limit in the form DD:HH:MM:SS after which the RMG job will stop. Useful for profiling on jobs that
261261
#do not converge.
262262
#wallTime = '00:00:00',
263+
#When keepIrreversible=False (default), forces RMG to import library reactions as reversible.
264+
#Otherwise, if set to True, RMG will import library reactions while keeping the reversibility as specified.
263265
keepIrreversible=False,
264-
#Forces RMG to import library reactions as reversible (default). Otherwise, if set to True, RMG will import library
265-
#reactions while keeping the reversibility as as.
266266
)
267267

268268
# optional module allows for correction to unimolecular reaction rates at low pressures and/or temperatures.

examples/rmg/ch3no2/input.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@
8080
)
8181

8282
simulator(atol=1e-16,rtol=1e-8)
83+
8384
options(
8485
units='si',
8586
generateOutputHTML=False,
8687
generatePlots=False,
88+
# Large model: write output every 5 iterations to reduce I/O
89+
generateChemkin={'saveInterval': 5, 'saveEdge': False},
90+
generateRMSYAML={'saveInterval': 5},
91+
generateCanteraYAML2={'saveInterval': 10, 'saveEdge': True},
8792
)

examples/rmg/commented/input.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,47 @@
221221
generatePESDiagrams=False,
222222
# saves mole fraction of species in 'solver/' to help you create plots
223223
saveSimulationProfiles=False,
224-
# gets RMG to output comments on where kinetics were obtained in the chemkin file.
225-
# useful for debugging kinetics but increases memory usage of the chemkin output file
224+
# Global fallback for verbose comments (comments on where kinetics were obtained).
225+
# Useful for debugging kinetics but increases output file size.
226+
# Individual writers can override this with their own verboseComments key.
226227
verboseComments=False,
227-
# gets RMG to generate edge species chemkin files. Uses lots of memory in output.
228-
# Helpful for seeing why some reaction are not appearing in core model.
228+
# Global fallback for saving edge-species files. Uses lots of memory in output.
229+
# Helpful for seeing why some reactions are not appearing in the core model.
230+
# Individual writers can override this with their own saveEdge key.
229231
saveEdgeSpecies=False,
230-
# Sets a time limit in the form DD:HH:MM:SS after which the RMG job will stop. Useful for profiling on jobs that
231-
# do not converge.
232-
# wallTime = '00:00:00',
233-
# Forces RMG to import library reactions as reversible (default). Otherwise, if set to True, RMG will import library
234-
# reactions while keeping the reversibility as as.
232+
# Sets a time limit in the form DD:HH:MM:SS after (or shortly before) which the RMG job will stop.
233+
# Useful for profiling on jobs that do not converge.
234+
wallTime = '00:00:00:00',
235+
# If keepIrreversible=False (default) forces RMG to import library reactions as reversible.
236+
# If set to True, RMG will import library reactions while keeping the reversibility as specified.
235237
keepIrreversible=False,
236238
# Allows families with three products to react in the diverse direction (default).
237239
trimolecularProductReversible=True,
238240
# Allows a seed to be saved every n iterations.
239241
# The default of -1 causes the iteration to only be saved at the end of the RMG job
240-
saveSeedModulus=-1
242+
saveSeedModulus=-1,
243+
#
244+
# --- Per-writer output configuration ---
245+
# Each writer accepts True/False or a dict with keys:
246+
# 'saveInterval': N (positive = every N iterations; -1 = end of run only)
247+
# 'verboseComments': True/False (overrides the global verboseComments above)
248+
# 'saveEdge': True/False (overrides the global saveEdgeSpecies above)
249+
#
250+
# Chemkin writer: always on by default; saves every iteration.
251+
generateChemkin=True,
252+
# generateChemkin={'saveInterval': -1, 'verboseComments': True, 'saveEdge': True},
253+
#
254+
# RMS YAML writer: always on by default; saves every iteration.
255+
generateRMSYAML=True,
256+
# generateRMSYAML={'saveInterval': -1},
257+
#
258+
# Cantera YAML v1 writer: off by default.
259+
generateCanteraYAML1=False,
260+
# generateCanteraYAML1={'saveInterval': -1, 'verboseComments': True, 'saveEdge': False},
261+
#
262+
# Cantera YAML v2 writer: off by default.
263+
generateCanteraYAML2=False,
264+
# generateCanteraYAML2={'saveInterval': 1, 'verboseComments': True, 'saveEdge': True},
241265
)
242266

243267
# optional module allows for correction to unimolecular reaction rates at low pressures and/or temperatures.

0 commit comments

Comments
 (0)