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

Set correct flux bounds #866

Merged
merged 9 commits into from Jul 5, 2019
Merged

Set correct flux bounds #866

merged 9 commits into from Jul 5, 2019

Conversation

MaxGreil
Copy link
Contributor

This PR is supposed to fix #858.

@codecov-io
Copy link

codecov-io commented Jun 30, 2019

Codecov Report

Merging #866 into devel will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel     #866      +/-   ##
==========================================
- Coverage   84.39%   84.38%   -0.02%     
==========================================
  Files          47       47              
  Lines        4216     4213       -3     
  Branches      981      981              
==========================================
- Hits         3558     3555       -3     
  Misses        424      424              
  Partials      234      234
Impacted Files Coverage Δ
cobra/core/reaction.py 87.77% <100%> (-0.09%) ⬇️

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 374ebfe...877339a. Read the comment docs.

@matthiaskoenig
Copy link
Contributor

Hi @MaxGreil,
this looks good.

Some smaller things I would change

  1. use CONFIGURATION.lower_bound directly instead of defining local variables for them.
  2. set upper and lower bounds at the same time (not part of issue, but if you touch the code you should update this)

The problem with setting the upper and lower bounds individually, is that there are 2 checks performed (both time it is checked if the bounds fit, whereas setting both at once requires only one check). In addition as far as I remember the constraints in optlang are generated at once, instead after each other (which results in some speedup for many reactions).

I.e. use

    @bounds.setter
    @resettable
    def bounds(self, value):
        lower, upper = value
        # Validate bounds before setting them.
        self._check_bounds(lower, upper)
        self._lower_bound = lower
        self._upper_bound = upper
        self.update_variable_bounds()

to set the upper and lower bound at the same time directly from configuration, i.e. instead of

self.lower_bound = lower_bound
self.upper_bound = upper_bound

better

self.bounds(CONFIGURATION.lower_bound, CONFIGURATION.upper_bound)

Same at the other two locations.

Copy link
Member

@cdiener cdiener left a comment

Choose a reason for hiding this comment

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

Looks good. Would be helpful to add a test to avoid regressions in the future.

@MaxGreil
Copy link
Contributor Author

MaxGreil commented Jul 1, 2019

Hi @cdiener ,
how should this test look like?

@cdiener
Copy link
Member

cdiener commented Jul 1, 2019

Hi @cdiener ,
how should this test look like?

Sets default bounds via configuration, adds a reaction with build_reaction_from_string and checks that the set bounds were applied. Could be added below

def test_build_from_string(model):
.

Copy link
Member

@Midnighter Midnighter left a comment

Choose a reason for hiding this comment

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

Sorry, didn't get a chance to look at this earlier. Just some style changes:

  • There is no need for parentheses in these cases.
  • Please rename the global CONFIGURATION variable to config. I would like to do this everywhere anyhow.

cobra/core/reaction.py Outdated Show resolved Hide resolved
cobra/core/reaction.py Outdated Show resolved Hide resolved
cobra/core/reaction.py Outdated Show resolved Hide resolved
cobra/core/reaction.py Outdated Show resolved Hide resolved
@matthiaskoenig
Copy link
Contributor

@MaxGreil you are almost there. Just write the test and do the minor changes proposed by @Midnighter then this pull request can be merged.

@Midnighter Midnighter merged commit 9f40934 into opencobra:devel Jul 5, 2019
@Midnighter
Copy link
Member

Thanks a lot for your contribution @MaxGreil 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reaction.build_reaction_from_string sets incorrect flux bounds
5 participants