Skip to content

Commit

Permalink
start cleaning out the various names for optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Dec 9, 2023
1 parent f1884db commit a985ffa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
23 changes: 20 additions & 3 deletions docs/src/examples/02c-constraint-modifications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ fermentation = ctmodel.fluxes.EX_ac_e.value + ctmodel.fluxes.EX_etoh_e.value
forced_mixed_fermentation =
ctmodel * :fermentation^C.Constraint(fermentation, (10.0, 1000.0)) # new modified model is created

vt = flux_balance(forced_mixed_fermentation, Tulip.Optimizer; modifications = [silence])
vt = optimized_constraints(
forced_mixed_fermentation,
objective = forced_mixed_fermentation.objective.value,
optimizer = Tulip.Optimizer,
modifications = [silence],
)

@test isapprox(vt.objective, 0.6337, atol = TEST_TOLERANCE) #src

Expand All @@ -52,13 +57,25 @@ vt = flux_balance(forced_mixed_fermentation, Tulip.Optimizer; modifications = [s

ctmodel.fluxes.ATPM.bound = (1000.0, 10000.0)

vt = flux_balance(ctmodel, Tulip.Optimizer; modifications = [silence])
#TODO explicitly show here how false sharing looks like

vt = optimized_constraints(
ctmodel,
objective = ctmodel.objective.value,
optimizer = Tulip.Optimizer,
modifications = [silence],
)

@test isnothing(vt) #src

# Models can also be piped into the analysis functions

ctmodel.fluxes.ATPM.bound = (8.39, 10000.0) # revert
vt = ctmodel |> flux_balance(Tulip.Optimizer; modifications = [silence])
vt = optimized_constraints(
ctmodel,
objective = ctmodel.objective.value,
optimizer = Tulip.Optimizer,
modifications = [silence],
)

@test isapprox(vt.objective, 0.8739, atol = TEST_TOLERANCE) #src
17 changes: 7 additions & 10 deletions docs/src/examples/03-qp-problems.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# # Quandratic objective flux balance analysis type problems

# We will use [`parsimonious_flux_balance_analysis`](@ref) and
# [`minimize_metabolic_adjustment_analysis`](@ref) to find the optimal flux
# We will use [`parsimonious_flux_balance`](@ref) and
# [`minimize_metabolic_adjustment`](@ref) to find the optimal flux
# distribution in the *E. coli* "core" model.

# If it is not already present, download the model and load the package:
Expand All @@ -22,11 +22,11 @@ model = A.load(J.JSONFBCModel, "e_coli_core.json") # load the model

# Use the convenience function to run standard pFBA

vt = X.parsimonious_flux_balance_analysis(model, Clarabel.Optimizer)
vt = X.parsimonious_flux_balance(model, Clarabel.Optimizer)

# Or use the piping functionality

model |> parsimonious_flux_balance_analysis(Clarabel.Optimizer; modifications = [X.silence])
model |> parsimonious_flux_balance(Clarabel.Optimizer; modifications = [X.silence])

@test isapprox(vt.objective, 0.87392; atol = TEST_TOLERANCE) #src
@test isapprox(sum(x^2 for x in values(vt.fluxes)), 11414.2119; atol = QP_TEST_TOLERANCE) #src
Expand Down Expand Up @@ -57,15 +57,12 @@ vt = X.C.constraint_values(ctmodel, X.J.value.(opt_model[:x])) # ConstraintTrees

ref_sol = Dict("ATPS4r" => 33.0, "CYTBD" => 22.0)

vt = X.minimize_metabolic_adjustment_analysis(model, ref_sol, Gurobi.Optimizer)
vt = X.minimize_metabolic_adjustment(model, ref_sol, Gurobi.Optimizer)

# Or use the piping functionality

model |> X.minimize_metabolic_adjustment_analysis(
ref_sol,
Clarabel.Optimizer;
modifications = [X.silence],
)
model |>
X.minimize_metabolic_adjustment(ref_sol, Clarabel.Optimizer; modifications = [X.silence])

@test isapprox(vt.:momaobjective, 0.81580806; atol = TEST_TOLERANCE) #src

Expand Down
2 changes: 1 addition & 1 deletion src/analysis/flux_balance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ solution = flux_balance(model, GLPK.optimizer)
"""
function flux_balance(model::A.AbstractFBCModel, optimizer; kwargs...)
constraints = fbc_model_constraints(model)
optimize_constraints(
optimized_constraints(
constraints;
objective = constraints.objective.value,
optimizer,
Expand Down
4 changes: 3 additions & 1 deletion src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Make an JuMP model out of `constraints` using [`optimization_model`](@ref)
the model, and return either `nothing` if the optimization failed, or `output`
substituted with the solved values (`output` defaults to `constraints`.
"""
function optimize_constraints(
function optimized_constraints(
constraints::C.ConstraintTreeElem,
args...;
modifications = [],
Expand All @@ -70,3 +70,5 @@ function optimize_constraints(
J.optimize!(om)
is_solved(om) ? C.constraint_values(output, J.value.(om[:x])) : nothing
end

export optimized_constraints

0 comments on commit a985ffa

Please sign in to comment.