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

Enable Restarting RMG Jobs from a Seed Mechanism #1641

Merged
merged 17 commits into from
Aug 12, 2019
Merged

Conversation

amarkpayne
Copy link
Member

@amarkpayne amarkpayne commented Jun 24, 2019

Motivation or Problem

There are many instances where it is desirable to restart an RMG job from the last iteration instead of having to start the mechanism generation from the beginning. RMG currently has a restart file, but it has not been maintained and will be deprecated starting in the next release. Furthermore, these restart files are extremely slow.

The agreed upon solution to this problem is to restart RMG jobs from the seed mechanism files that RMG already outputs. These files allow for the complete reconstruction of the model core and edge at the time of the restart. The only missing piece of information missing is the filter tensors, which help RMG decide which species to react, which species have already reacted, and which species not to react because their expected rate is well below what would be included based on the tolerance. This PR saves these filter tensors and allows for them to be loaded so that RMG jobs can be restarted using this technique

Description of Changes

  • Reorganized when seed mechanisms are saved
  • Save the filter tensors (and necessary mappings) to a Filters sub folder of the seed mechanism
  • Add in a block to the RMG input file format for telling RMG to perform a restart job from a seed mechanism
  • Automatically generate input files entitled restart_from_seed.py that can be run to restart the job
  • Updated the documentation to describe how the user can use this restart feature
  • Saving the seed mechanism each iteration is now the default behavior

Testing

I have restarted the superminimal and minimal examples using this technique, and the same mechanism was obtained if the job was run to completion or if the job was restarted from a seed mechanism from an intermediate iteration seed mechanism.

I have not added anything in the way of unit testing yet, but I am happy to add tests for the crucial features of this PR.

@codecov
Copy link

codecov bot commented Jun 25, 2019

Codecov Report

Merging #1641 into master will decrease coverage by 0.13%.
The diff coverage is 17.82%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1641      +/-   ##
==========================================
- Coverage   41.79%   41.66%   -0.14%     
==========================================
  Files         177      176       -1     
  Lines       30207    30215       +8     
  Branches     6252     6256       +4     
==========================================
- Hits        12625    12588      -37     
- Misses      16659    16703      +44     
- Partials      923      924       +1
Impacted Files Coverage Δ
rmgpy/solver/files/listener/input.py 100% <ø> (ø) ⬆️
rmgpy/solver/files/liquid_phase_constSPC/input.py 100% <ø> (ø) ⬆️
rmgpy/tools/data/sim/simple/input.py 100% <ø> (ø) ⬆️
rmgpy/tools/data/sim/mbSampled/input.py 100% <ø> (ø) ⬆️
rmgpy/tools/data/sim/liquid/input.py 100% <ø> (ø) ⬆️
rmgpy/rmg/model.py 41.07% <0%> (-0.63%) ⬇️
rmgpy/stats.py 59.81% <0%> (+0.33%) ⬆️
rmgpy/rmg/main.py 21.85% <15.78%> (-1.23%) ⬇️
rmgpy/rmg/input.py 36.58% <7.14%> (-1.36%) ⬇️
rmgpy/data/kinetics/library.py 43.13% <78.57%> (+0.03%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04d4d42...3a00ee3. Read the comment docs.

@amarkpayne amarkpayne force-pushed the SaveFilterTensors branch 2 times, most recently from 47aee7b to 4f73f35 Compare June 28, 2019 21:27
rmgpy/rmg/input.py Outdated Show resolved Hide resolved
@amarkpayne amarkpayne force-pushed the SaveFilterTensors branch 3 times, most recently from 63a0590 to 47cf386 Compare August 5, 2019 19:58
@amarkpayne amarkpayne added Status: Ready for Review PR is complete and ready to be reviewed and removed Status: Blocked by PR This PR is dependent on another PR labels Aug 5, 2019
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
examples/rmg/commented/input.py Outdated Show resolved Hide resolved
@mliu49 mliu49 added the Before Py3 Should be merged before Python 3 transition label Aug 6, 2019
Copy link
Member Author

@amarkpayne amarkpayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the helpful comments @mliu49 ! There are a couple of things I need to change depending on what we want to do with the old style restart

rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
examples/rmg/commented/input.py Outdated Show resolved Hide resolved
@amarkpayne amarkpayne force-pushed the SaveFilterTensors branch 2 times, most recently from d980302 to 27fd30b Compare August 7, 2019 13:55
Copy link
Contributor

@mjohnson541 mjohnson541 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I think this looks like it avoids a lot of the bugs that could easily occur with this feature. I've brought up a few issues I noticed below.

rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Show resolved Hide resolved
documentation/source/users/rmg/input.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@mliu49 mliu49 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes to seed paths done as well?

documentation/source/users/rmg/input.rst Outdated Show resolved Hide resolved
rmgpy/rmg/input.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Show resolved Hide resolved
documentation/source/users/rmg/input.rst Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Outdated Show resolved Hide resolved
examples/rmg/commented/input.py Outdated Show resolved Hide resolved
rmgpy/rmg/input.py Outdated Show resolved Hide resolved
Copy link
Contributor

@mjohnson541 mjohnson541 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small additional things.

rmgpy/rmg/main.py Outdated Show resolved Hide resolved
rmgpy/rmg/main.py Show resolved Hide resolved
@amarkpayne
Copy link
Member Author

I have force pushed the requested changes and confirmed that the (updated, the species map changed from a dictionary to a list) minimal restart example works.

documentation/source/users/rmg/input.rst Outdated Show resolved Hide resolved
rmgpy/rmg/input.py Outdated Show resolved Hide resolved
rmgpy/rmg/input.py Outdated Show resolved Hide resolved
reordered_core_species = []
for spc in restartSpeciesList:
for j, oldCoreSpc in enumerate(self.reactionModel.core.species):
if oldCoreSpc.isIsomorphic(spc):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use the strict=False argument since we don't generate resonance structures for the restart species.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

rmgpy/rmg/main.py Outdated Show resolved Hide resolved
@@ -431,14 +433,9 @@ def initialize(self, **kwargs):
self.logHeader()

try:
restart = kwargs['restart']
self.restart_seed_path = kwargs['restart']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this doesn't do anything. It should set the coreSeedPath, edgeSeedPath, filtersPath, and speciesMapPath like you do when loading the input file.

Alternatively, if you don't think we should support both methods, you can remove this and set the -r flag to simply print a warning that the old restart method has been removed and the flag does not do anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks for the catch!

@mliu49
Copy link
Contributor

mliu49 commented Aug 9, 2019

@amarkpayne was correct, and the problem was in fact the extra indentation, which was messing up the family name parsing and causing the reaction to be loaded as a library reaction with .library (and .family) as seedMechanism.name (here). We missed the warning, which would have led us to the cause much faster.

I added a few commits to resolve this and some related issues:

  • Switch to using the longDesc property of the entries instead of the private _longDesc attribute in getLibraryReactions. Not a bug, but the point of a private attribute is that it shouldn't be used.
  • Improve parsing of reaction template and family name in getLibraryReactions, including stripping the family name. I discovered while debugging that the reaction template was completely wrong in some cases because the comment strings weren't exactly as expected.
  • Remove leading spaces from kinetics comments in getLibraryReactions. I wasn't sure the best place to put this, but it seemed to make sense there. This prevents the gradual increase in indentation with each read/write cycle.

amarkpayne and others added 17 commits August 10, 2019 11:24
We now perform this check when/if these edge species are moved to the core
Has been deprecated for a while, and is now completely replaced by the restart from seed mechanism feature.
We will still use the job name when outputting to the database, but the name should be fixed in the output directory
More robust methods to determine template and family name
Make sure to strip family name
Otherwise, indents are retained over each read/write operation
@amarkpayne
Copy link
Member Author

I have also confirmed that with @mliu49 fixes enable unlimited successive restarts. I have also addressed the last remaining comment that I need to fixup, and I have squashed all of the fixups and force pushed. This should be ready for final approval/merging

Copy link
Contributor

@mliu49 mliu49 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go now. @mjohnson541, do you have any comments on the fixes that I added?

@mjohnson541
Copy link
Contributor

Took a look now, looks fine to me!

@mliu49 mliu49 merged commit 3846fcc into master Aug 12, 2019
@mliu49 mliu49 deleted the SaveFilterTensors branch August 12, 2019 01:19
@mliu49 mliu49 mentioned this pull request Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Before Py3 Should be merged before Python 3 transition Complexity: Medium Status: Ready for Review PR is complete and ready to be reviewed Topic: Restart Type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants