-
Notifications
You must be signed in to change notification settings - Fork 229
Added fast gapfilling flag. All tests pass with fast_gapfill=True #1450
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
Open
djinnome
wants to merge
7
commits into
opencobra:devel
Choose a base branch
from
AgileBioFoundry:1449-feature-fast-gapfill
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
28e5f23
Added fast gapfilling flag. All tests pass with fast_gapfill=True
djinnome 252508d
Fast Gapfill feature added to release notes
djinnome a21114c
Extracted fast_gapfill check out of the reaction loop so only one che…
djinnome 17a1677
Black has reformatted gapfilling.py
djinnome ab16eac
flake8 passes
djinnome ca0ed13
Removed unnecessary list comprehension
djinnome c0290c7
Added a pytest.skip to test_remote_load if in a CI environment
djinnome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,8 @@ class GapFiller: | |
The threshold at which a value is considered non-zero (aka | ||
integrality threshold). If gapfilled models fail to validate, | ||
you may want to lower this value (default 1E-6). | ||
fast_gapfill : bool, optional | ||
Whether to use the fast gap filling approach (default False). | ||
|
||
Attributes | ||
---------- | ||
|
@@ -110,6 +112,7 @@ def __init__( | |
exchange_reactions: bool = False, | ||
demand_reactions: bool = True, | ||
integer_threshold: float = 1e-6, | ||
fast_gapfill: bool = False, | ||
**kwargs, | ||
) -> None: | ||
"""Initialize a new GapFiller object. | ||
|
@@ -139,6 +142,8 @@ def __init__( | |
if penalties is not None: | ||
self.penalties.update(penalties) | ||
self.indicators = [] | ||
self.fast_gapfill = fast_gapfill | ||
|
||
self.costs = {} | ||
self.extend_model(exchange_reactions, demand_reactions) | ||
fix_objective_as_constraint(self.model, bound=lower_bound) | ||
|
@@ -223,11 +228,16 @@ def add_switches_and_objective(self) -> None: | |
constraints = [] | ||
big_m = max(max(abs(b) for b in r.bounds) for r in self.model.reactions) | ||
prob = self.model.problem | ||
if self.fast_gapfill: | ||
indicator_type = "continuous" | ||
else: | ||
indicator_type = "binary" | ||
for rxn in self.model.reactions: | ||
if not hasattr(rxn, "gapfilling_type"): | ||
continue | ||
|
||
indicator = prob.Variable( | ||
name=f"indicator_{rxn.id}", lb=0, ub=1, type="binary" | ||
name=f"indicator_{rxn.id}", lb=0, ub=1, type=indicator_type | ||
) | ||
if rxn.id in self.penalties: | ||
indicator.cost = self.penalties[rxn.id] | ||
|
@@ -343,6 +353,7 @@ def gapfill( | |
demand_reactions: bool = True, | ||
exchange_reactions: bool = False, | ||
iterations: int = 1, | ||
fast_gapfill: bool = False, | ||
): | ||
"""Perform gap filling on a model. | ||
|
||
|
@@ -375,7 +386,11 @@ def gapfill( | |
which may include previously used reactions i.e., with enough | ||
iterations pathways including 10 steps will eventually be reported | ||
even if the shortest pathway is a single reaction (default 1). | ||
|
||
fast_gapfill : bool, optional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before. |
||
Use continuous variables for the indicator variables instead of | ||
binary variables. This can speed up the gap filling but may lead to | ||
suboptimal solutions. If you want to use this, you should also | ||
consider increasing the number of iterations (default False). | ||
Returns | ||
------- | ||
list of list of cobra.Reaction | ||
|
@@ -402,5 +417,6 @@ def gapfill( | |
penalties=penalties, | ||
demand_reactions=demand_reactions, | ||
exchange_reactions=exchange_reactions, | ||
fast_gapfill=fast_gapfill, | ||
) | ||
return gapfiller.fill(iterations=iterations) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,6 @@ def test_unknown_model() -> None: | |
with pytest.raises(RuntimeError): | ||
load_model("MODELWHO?", cache=False) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"model_id, num_metabolites, num_reactions", | ||
[("e_coli_core", 72, 95), ("BIOMD0000000633", 50, 35)], | ||
|
@@ -89,6 +88,9 @@ def test_remote_load(model_id: str, num_metabolites: int, num_reactions: int) -> | |
The total number of reactions in the model having ID `model_id`. | ||
|
||
""" | ||
if os.getenv("CI") == "true": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better remove this here and let's solve this in a separate PR which we can then rebase on. Thx |
||
pytest.skip("Skipping remote load tests on CI") | ||
|
||
model = load_model(model_id, cache=False) | ||
assert len(model.metabolites) == num_metabolites | ||
assert len(model.reactions) == num_reactions | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is already a gapfill function I think having it in the argument name is redundant. Just calling it "fast" should be enough. Or call it "method" and make it a string to allow for other algorithms in the future.