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

Uncertainty fixes and user experience improvement #1593

Merged
merged 32 commits into from Jun 7, 2019
Merged

Conversation

mliu49
Copy link
Contributor

@mliu49 mliu49 commented May 2, 2019

Motivation or Problem

This PR contains 3 parts:

  • Minor maintenance of uncertainty analysis functionality to make sure it works
  • Major user experience improvements in how uncertainty analysis is performed
  • Updates to related IPython notebooks and examples

Description of Changes

User experience improvements:

  • It is now possible to request uncertainty analysis be automatically performed at the end of an RMG job via input file settings
  • The simulate.py script can be similarly used to run uncertainty analysis automatically
  • Uncertainty values for uncorrelated global analysis can be retrieved automatically instead of manually entered

IPython notebook updates:

  • findParameterSourcesAndAssignUncertainties.ipynb
  • localUncertainty.ipynb
  • globalUncertainty.ipynb
  • canteraSimulation.ipynb
  • canteraSensitivityComparison.ipynb

There are also a number of bug fixes. Documentation updates to be included soon.

Testing

The input files in ipython/data/ethane_model and ipython/data/pdd_model can be run to test uncertainty analysis following an RMG job. All of the IPython notebooks should work. Note that globalUncertainty does require setting up MUQ properly, which is non-trivial currently.

To set up MUQ:

  • I suggest creating a new environment first
  • Add /home/user/anaconda2/envs/rmg_new/lib to path
  • Do conda install hdf5=1.8
  • Do conda install icu=54

Reviewer Tips

I suggest going through the commits in order rather than viewing all changes at once.

@mliu49 mliu49 added Status: Ready for Review PR is complete and ready to be reviewed Type: User Experience labels May 2, 2019
@mliu49 mliu49 self-assigned this May 2, 2019
@codecov
Copy link

codecov bot commented May 2, 2019

Codecov Report

Merging #1593 into master will decrease coverage by 0.09%.
The diff coverage is 20.4%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1593     +/-   ##
========================================
- Coverage   41.59%   41.5%   -0.1%     
========================================
  Files         176     176             
  Lines       29150   29306    +156     
  Branches     5992    6033     +41     
========================================
+ Hits        12126   12163     +37     
- Misses      16178   16292    +114     
- Partials      846     851      +5
Impacted Files Coverage Δ
rmgpy/tools/canteraModel.py 38.87% <0%> (ø) ⬆️
rmgpy/tools/muq.py 8.48% <10.89%> (-0.57%) ⬇️
rmgpy/rmg/input.py 35.77% <25%> (-0.08%) ⬇️
rmgpy/tools/uncertainty.py 38.46% <27.96%> (-3.82%) ⬇️
rmgpy/rmg/main.py 23.07% <5.31%> (+0.34%) ⬆️
rmgpy/tools/simulate.py 71.69% <75%> (-5.67%) ⬇️
rmgpy/tools/plot.py 45.93% <84.61%> (+1.02%) ⬆️
rmgpy/data/kinetics/family.py 52.9% <0%> (+0.23%) ⬆️

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 a6c78ca...7e15900. Read the comment docs.

Copy link
Member

@alongd alongd left a comment

Choose a reason for hiding this comment

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

The code looks great, I added some minor comments

try:
os.makedirs(folder)
except:
raise Exception('Uncertainty output directory could not be created.')
Copy link
Member

Choose a reason for hiding this comment

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

Can we use a more specific exception class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I forget why I decided to catch this exception at all. I might have just copied it from somewhere.

@@ -81,6 +81,29 @@ def __init__(self, cantera, outputSpeciesList, kParams, kUncertainty, gParams, g
# The size of the uncertain inputs: [parameters affecting k, parameters affecting free energy G]
self.inputSize = [len(kParams) + len(gParams)]

if not self.correlated:
Copy link
Member

Choose a reason for hiding this comment

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

Above, before class ReactorModPiece(ModPiece): there are installation instructions for MUQ. Do these require an update in light of the recommendation you gave in the PR message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. Ideally, we should update the MUQ binaries so none of this is an issue anymore. Idk when I'll get a chance to look into doing so though.

@@ -476,8 +476,8 @@ def analyzeResults(self):
description = 'dln[{0}]/dln[{1}]'.format(outputSpecies.toChemkin(), descriptor)

print '{0:55} {1:10.3f} {2:10.3f}'.format(description,
mainSens[outputIndex][parameterIndex],
totalSens[outputIndex][parameterIndex])
100*mainSens[outputIndex][parameterIndex],
Copy link
Member

Choose a reason for hiding this comment

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

Minor: PEP 8 style asks to add spaces around operators

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -476,8 +476,8 @@ def analyzeResults(self):
description = 'dln[{0}]/dln[{1}]'.format(outputSpecies.toChemkin(), descriptor)

print '{0:55} {1:10.3f} {2:10.3f}'.format(description,
mainSens[outputIndex][parameterIndex],
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we add % symbols to the print statement accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had put (%) in the column headers, but I've moved them to the values to make it clearer.

def uncertainty(localAnalysis=False, globalAnalysis=False, uncorrelated=True, correlated=True,
localNumber=10, globalNumber=5, terminationTime=None, pceRunTime=1800):
rmg.uncertainty = {
'local': localAnalysis if not globalAnalysis else True, # Must run local before global
Copy link
Member

Choose a reason for hiding this comment

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

If localAnalysis was set to False but globalAnalysis to True, would we like to print that we're setting localAnalysis to True?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a logging statement.

"""
Assign uncertainties based on the sources of the species thermo and reaction kinetics.
"""

if gParamEngine is None:
Copy link
Member

Choose a reason for hiding this comment

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

Way to go, auto-formatting tool!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, this was manually changed.

@@ -96,12 +96,12 @@ def parseCSVData(csvFile):
rxn = data.label.split()[1]
index = data.label.split()[0][:-2].rpartition('dln[k')[2]
data.reaction = rxn
data.index = index
data.index = int(index)
Copy link
Member

Choose a reason for hiding this comment

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

What type was index before this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a string, parsed from the csv.

@mliu49
Copy link
Contributor Author

mliu49 commented Jun 3, 2019

@amarkpayne Would you still like to review this?

@alongd Could you take a look at the fixups and documentation additions?

Copy link
Member

@alongd alongd left a comment

Choose a reason for hiding this comment

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

Code looks great! I just had one minor suggestion for the documentation. Please go ahead and squash. I'll try it out before merging.


Finally, there are a few miscellaneous options for global uncertainty analysis. The ``terminationTime`` applies for the
reactor simulation. It is only necessary if termination time is not specified in the reactor settings (i.e. only other
termination criteria are used). The ``pceRunTime`` sets the time limit for fitting the PCE to the output surface.
Copy link
Member

Choose a reason for hiding this comment

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

Define PCE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the abbreviation to the first mention of Polynomial Chaos Expansion earlier in the section (line 806).

mliu49 added 13 commits June 7, 2019 12:50
For the default temperatures in the thermo block,
the lower bound should be 10 characters.
If multiple species were included in the local analysis, then
a given parameter might appear more than once. However, we only
want to include it once for global analysis.
So user can toggle whether to perform the analysis for ln(x) or just x
Remove ipython/uncertainty files since new example files have been
added to ipython/data
New ethane model was generated for the uncertainty notebooks,
so this updates the Cantera notebooks to use the same files and
removes the old mechanisms.
@mliu49
Copy link
Contributor Author

mliu49 commented Jun 7, 2019

I rebased again. Please go ahead and merge whenever you're ready.

@alongd
Copy link
Member

alongd commented Jun 7, 2019

Thanks for this awesome PR!

@alongd alongd merged commit 85c81ea into master Jun 7, 2019
@alongd alongd deleted the uncertainty_fixes branch June 7, 2019 20:16
@mliu49 mliu49 mentioned this pull request Jun 10, 2019
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Ready for Review PR is complete and ready to be reviewed Type: User Experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants