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

Automatic Network Generation 3 #1647

Merged
merged 8 commits into from
Aug 4, 2019
Merged

Automatic Network Generation 3 #1647

merged 8 commits into from
Aug 4, 2019

Conversation

mjohnson541
Copy link
Contributor

This adds a number of miscellaneous bug fixes and improvements for automatic network generation. Forbidden structure checking is now done on the edge for automatic network generation, flux reduction is now done on netReactions instead of pathReactions and has an additional very robust fallback algorithm just using rate coefficients. Fixed a bug related to reduction when an isomer is removed.

@mjohnson541 mjohnson541 self-assigned this Jul 9, 2019
@mjohnson541 mjohnson541 force-pushed the pdepnetworkgen3 branch 2 times, most recently from ff67fdf to 505333f Compare July 9, 2019 20:05
@codecov
Copy link

codecov bot commented Jul 9, 2019

Codecov Report

Merging #1647 into master will decrease coverage by 0.09%.
The diff coverage is 6.45%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1647     +/-   ##
=========================================
- Coverage   41.87%   41.77%   -0.1%     
=========================================
  Files         176      176             
  Lines       29369    29423     +54     
  Branches     6059     6075     +16     
=========================================
- Hits        12297    12291      -6     
- Misses      16192    16257     +65     
+ Partials      880      875      -5
Impacted Files Coverage Δ
rmgpy/rmg/pdep.py 12.33% <6.45%> (-3.8%) ⬇️
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 589ba9a...48f12c8. Read the comment docs.

@mjohnson541 mjohnson541 requested review from alongd and removed request for alongd July 11, 2019 18:39
@amarkpayne amarkpayne requested a review from lily90502 July 11, 2019 18:39
@alongd alongd self-requested a review July 11, 2019 18:40
@mjohnson541 mjohnson541 removed the request for review from alongd July 11, 2019 18:40
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.

Sorry for the delay in reviewing, please see some comments.
How would you recommend me to test these additions?

if forbiddenStructures.isMoleculeForbidden(spc.molecule[0]):
reaction_model.removeSpeciesFromEdge(reaction_model.reactionSystems, spc)
reaction_model.removeEmptyPdepNetworks()
logging.error(spc.label)
Copy link
Member

Choose a reason for hiding this comment

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

Is this a leftover from debugging? If not, consider adding a 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.

removed

reaction_model.enlarge((network, spc), reactEdge=False, unimolecularReact=flags,
logging.info('adding new isomer {0} to network'.format(spc))
flags = np.array([s.molecule[0].getFormula() == form for s in reaction_model.core.species])
reaction_model.enlarge((network, spc), reactEdge=False, unimolecularReact=flags,
bimolecularReact=np.zeros((len(reaction_model.core.species),
Copy link
Member

Choose a reason for hiding this comment

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

fix the over-indentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -472,22 +472,49 @@ def remove_disconnected_reactions(self):
logging.info('Removing rxn: {}'.format(rxn))
self.pathReactions.remove(rxn)

nrxns = []
for nrxn in self.netReactions:
prod = nrxn.products
Copy link
Member

Choose a reason for hiding this comment

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

Looks like prod isn't used below

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

nrxns = []
for nrxn in self.netReactions:
prod = nrxn.products
if nrxn.products not in keptProducts or nrxn.reactants not in keptProducts:
Copy link
Member

Choose a reason for hiding this comment

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

nrxn.products is a list of length 1 to 3, right? Can an in or not in check be performed that way? Shouldn't we iterate through the products in nrxn.products before the check?

Copy link
Contributor Author

@mjohnson541 mjohnson541 Jul 19, 2019

Choose a reason for hiding this comment

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

keptProducts is constructed as a list of lists of species (from a pdep network perspective this makes sense since each represents a configuration) so this should work fine.


con = np.linalg.cond(A)

try:
Copy link
Member

Choose a reason for hiding this comment

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

I think the error message and comment are a bit confusing: So if it is ill-conditioned we raise an error, but if it is "very ill-conditioned" we troubleshoot?

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've adjusted this to use an if statement rather than the first try except, which makes it a bit clearer. In general if we expect we can handle the matrix we do it normally, otherwise we fall back to arbitrary precision arithmetic, and lastly if we can't manage that we just assume all the isomers that aren't reactant channels have zero concentration which makes the calculation trivial.

@@ -354,32 +354,42 @@ def get_energy_filtered_reactions(self,T,tol):

return filtered_rxns

def get_rate_filtered_reactions(self,T,P,tol):
def get_rate_filtered_products(self,T,P,tol):
Copy link
Member

Choose a reason for hiding this comment

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

Add space between comma and argument

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

for prod in productSet:
logging.info([x.label for x in prod])

if rxnSet:
Copy link
Member

Choose a reason for hiding this comment

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

maybe combine these conditions into the ones above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -536,16 +536,45 @@ def remove_disconnected_reactions(self):
self.Nreac = len(self.reactants)
self.Nprod = len(self.products)

def remove_reactions(self,reactionModel,rxns):
def remove_reactions(self,reactionModel,rxns=None,prods=None):
Copy link
Member

Choose a reason for hiding this comment

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

add spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

for rxn in rxns:
self.pathReactions.remove(rxn)

if rxns:
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 this be if rxns is not None? Or is there no practical difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no practical difference it won't trigger if rxns = None or rxns = [].

@@ -162,19 +162,14 @@ def setUp(self):
self.pdepnetwork.index = 1
self.pdepnetwork.explored = []


def test_SS_solver(self):
Copy link
Member

Choose a reason for hiding this comment

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

But pdep.py still had the method, doesn't it? (or was the method itself removed as well?)
If we're still using the original method somewhere, lets keep/relocate the test for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the method exists, but the problem is that pdepTest doesn't have appropriate objects to test it directly after changes made in solve_SS_network. test_flux_filter does test it though, so it's still under coverage.
I invested sometime trying to figure out how to make it work, but given it's already under reasonable coverage (get_rate_filtered_products isn't a complicated function), it didn't seem worth it.

@mjohnson541 mjohnson541 force-pushed the pdepnetworkgen3 branch 2 times, most recently from 82e7071 to 2b0730a Compare July 23, 2019 20:00
@mjohnson541
Copy link
Contributor Author

@alongd

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.

OK, looks good. Just a minor comment


c = c.astype(np.float64)

try:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe only leave the critical part (qr_solve?) inside the try: except block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the problem is that nnls (non-negative least squares) is critical as well when required and may fail as well (although given the qr_solve has to succeed to try nnls it shouldn't fail that often, but it should still fall back properly if nnls is called and fails).

@alongd alongd added the Before Py3 Should be merged before Python 3 transition label Aug 1, 2019
@alongd
Copy link
Member

alongd commented Aug 2, 2019

OK, I think we're all set. Can you rebase?

…recision

also if arbitrary precision fails fall back to just using rate coefficients
this includes adding the fallback algorithm that simply uses the rate coefficients rather than the steady state analysis
note that the test_SS_solver is removed because we've switched from using pathReactions to netReactions
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.

Thanks!

@alongd alongd merged commit d66fbfe into master Aug 4, 2019
@alongd alongd deleted the pdepnetworkgen3 branch August 4, 2019 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arkane Before Py3 Should be merged before Python 3 transition Complexity: Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants