Skip to content

Commit

Permalink
convert FBA to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Jan 30, 2024
1 parent caea516 commit 8001a5f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples/02-flux-balance-analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ model = load_model("e_coli_core.json")
# is captured in the default behavior of function
# [`flux_balance_analysis`](@ref):

solution = flux_balance_analysis(model, GLPK.Optimizer)
solution = flux_balance_analysis(model, optimizer = GLPK.Optimizer)

@test isapprox(solution.objective, 0.8739, atol = TEST_TOLERANCE) #src

Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/02a-optimizer-parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ model = load_model("e_coli_core.json")
# limit for IPM algorithm may now look as follows:
solution = flux_balance_analysis(
model,
Tulip.Optimizer;
optimizer = Tulip.Optimizer,
settings = [silence, set_optimizer_attribute("IPM_IterationsLimit", 1000)],
)

Expand All @@ -59,7 +59,7 @@ solution = flux_balance_analysis(

solution = flux_balance_analysis(
model,
Tulip.Optimizer;
optimizer = Tulip.Optimizer,
settings = [set_optimizer_attribute("IPM_IterationsLimit", 2)],
)

Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/02b-model-modifications.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ model.reactions["CS"].stoichiometry

import GLPK

base_solution = flux_balance_analysis(model, GLPK.Optimizer)
base_solution = flux_balance_analysis(model, optimizer = GLPK.Optimizer)
base_solution.objective

# Now, for example, we can limit the intake of glucose by the model:
Expand All @@ -91,7 +91,7 @@ model.reactions["EX_glc__D_e"].lower_bound = -5.0

# ...and solve the modified model:
#
low_glucose_solution = flux_balance_analysis(model, GLPK.Optimizer)
low_glucose_solution = flux_balance_analysis(model, optimizer = GLPK.Optimizer)
low_glucose_solution.objective

@test isapprox(low_glucose_solution.objective, 0.41559777, atol = TEST_TOLERANCE) #src
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/frontend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ front-end analysis function.
function frontend_optimized_values(
builder,
args...;
objective = identity,
objective,
output = identity,
sense,
sense = Maximal,
optimizer,
settings = [],
kwargs...,
Expand All @@ -39,8 +39,8 @@ function frontend_optimized_values(
objective = objective(constraints),
output = output(constraints),
sense,
settings,
optimizer,
settings,
)
end

Expand Down
15 changes: 6 additions & 9 deletions src/frontend/balance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ Most arguments are forwarded to [`optimized_values`](@ref).
Returns a tree with the optimization solution of the same shape as
given by [`flux_balance_constraints`](@ref).
"""
function flux_balance_analysis(model::A.AbstractFBCModel, optimizer; kwargs...)
constraints = flux_balance_constraints(model)
optimized_values(
constraints;
objective = constraints.objective.value,
optimizer,
kwargs...,
)
end
flux_balance_analysis(model::A.AbstractFBCModel; kwargs...) = frontend_optimized_values(
flux_balance_constraints,
model;
objective = x -> x.objective.value,
kwargs...,
)

export flux_balance_analysis

0 comments on commit 8001a5f

Please sign in to comment.