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

Switch numerical scaling to relative #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions corda/corda.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
from collections import Counter
import re
from optlang.symbolics import Zero
from optlang.interface import OPTIMAL

UPPER = 1e6 # default upper bound
UPPER = 1e6 # default internal bound for metabolic requirements
SCALE = 1e3 # default bound scaling
CI = 1.01 # cost increase for redundancy detection


Expand Down Expand Up @@ -115,9 +117,13 @@ def __init__(self, model, confidence, met_prod=None, n=np.inf,
self.redundancies = {}
for r in self.model.reactions:
if r.lower_bound < -self.tol:
r.lower_bound = -UPPER
r.lower_bound *= SCALE
else:
r.lower_bound = 0
if r.upper_bound > self.tol:
r.upper_bound = UPPER
r.upper_bound *= SCALE
else:
r.upper_bound = 0
if r.id in confidence:
if confidence[r.id] not in [-1, 0, 1, 2, 3]:
raise ValueError("Not a valid confidence value!")
Expand Down Expand Up @@ -197,7 +203,6 @@ def associated(self, targets, conf=None, penalize_medium=True,
continue
else:
va.lb = max(self.tflux, va.lb)
va.ub = UPPER
has_new = True
pen = penalties.copy()
iteration = 0
Expand Down Expand Up @@ -269,8 +274,8 @@ def build(self):
if self.conf[v.name] == 1 or self.conf[v.name] == 2:
self.model.objective.set_linear_coefficients({v: 1})
sol = self.model.solver.optimize()
if (sol == "optimal" and
self.model.objective.value > self.tflux):
if (sol == OPTIMAL and
self.model.solver.objective.value > self.tflux):
self.conf[v.name] = 3
self.model.objective.set_linear_coefficients({v: 0})

Expand Down
2 changes: 1 addition & 1 deletion tests/test_large.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_build_works(self, large):
assert len(include) > 3
rec = opt.cobra_model("reconstruction")
sol = rec.optimize()
assert sol.f > 1
assert sol.objective_value > 1

@pytest.mark.parametrize("solver", solvers)
def test_benchmark_large(self, large, benchmark, solver):
Expand Down
13 changes: 0 additions & 13 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@ def test_none(self):

class TestMisc:

def test_remove_breaks(self):
model = Model("test model")
A = Metabolite("A")
r = Reaction("r")
r.add_metabolites({A: -1})
r.lower_bound = -1000
r.upper_bound = 1000
model.add_reaction(r)
convert_to_irreversible(model)
model.remove_reactions(["r"])
with pytest.raises(KeyError):
revert_to_reversible(model)

def test_cemet(self):
model = test_model()
assert len(model.reactions) == 60
Expand Down