From e4f53a7ad081301d29daf56976981170a248d9eb Mon Sep 17 00:00:00 2001 From: "St. Elmo Wilken" Date: Thu, 9 Jan 2025 10:17:08 +0100 Subject: [PATCH 01/18] use bound constructors directly --- src/builders/enzymes.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/builders/enzymes.jl b/src/builders/enzymes.jl index 86f2a8aa..51ecba38 100644 --- a/src/builders/enzymes.jl +++ b/src/builders/enzymes.jl @@ -219,7 +219,7 @@ function enzyme_constraints(; !isnothing(gpmm) && haskey(gene_product_amounts, gp); init = zero(C.LinearValue), ), - bound, + C.BetweenT(bound...), ) for (id, gps, bound) in capacity_limits ) end @@ -297,7 +297,7 @@ function simplified_enzyme_constraints(; contribution(fluxes_reverse, mass_cost_reverse, f) for f in fs; init = zero(C.LinearValue), # TODO not type stable if LinearValueT{not Float64} ), - bound, + C.BetweenT(bound...), ) for (id, fs, bound) in capacity_limits ) end From 0fb2cb2012f52526b4bf0bb496306d03fc32d282 Mon Sep 17 00:00:00 2001 From: "St. Elmo Wilken" Date: Thu, 9 Jan 2025 16:19:57 +0100 Subject: [PATCH 02/18] implement reviews --- src/builders/enzymes.jl | 4 ++-- src/frontend/enzymes.jl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/builders/enzymes.jl b/src/builders/enzymes.jl index 51ecba38..86f2a8aa 100644 --- a/src/builders/enzymes.jl +++ b/src/builders/enzymes.jl @@ -219,7 +219,7 @@ function enzyme_constraints(; !isnothing(gpmm) && haskey(gene_product_amounts, gp); init = zero(C.LinearValue), ), - C.BetweenT(bound...), + bound, ) for (id, gps, bound) in capacity_limits ) end @@ -297,7 +297,7 @@ function simplified_enzyme_constraints(; contribution(fluxes_reverse, mass_cost_reverse, f) for f in fs; init = zero(C.LinearValue), # TODO not type stable if LinearValueT{not Float64} ), - C.BetweenT(bound...), + bound, ) for (id, fs, bound) in capacity_limits ) end diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index 0313e211..24aacad5 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -140,7 +140,7 @@ function enzyme_constrained_flux_balance_constraints( capacity_limits = capacity isa Real ? [(:total_capacity, gene_ids, (zero(capacity), capacity))] : [ - (Symbol(k), Symbol.(gs), (zero(cap), cap)) for (k, gs, cap) in capacity + (Symbol(k), Symbol.(gs), C.BetweenT(; lower = zero(cap), upper = cap)) for (k, gs, cap) in capacity ], ) end @@ -257,7 +257,7 @@ function simplified_enzyme_constrained_flux_balance_constraints( (zero(capacity), capacity), )] : [ - (Symbol(k), Symbol.(fs), (zero(cap), cap)) for (k, fs, cap) in capacity + (Symbol(k), Symbol.(fs), C.BetweenT(; lower = zero(cap), upper = cap)) for (k, fs, cap) in capacity ], ) * :gene_product_amounts^simplified_isozyme_gene_product_amount_constraints( From a1d8658a29ec8621c5d55c8c1e182e0a86e21724 Mon Sep 17 00:00:00 2001 From: stelmo Date: Thu, 9 Jan 2025 15:36:46 +0000 Subject: [PATCH 03/18] automatic formatting triggered by @stelmo on PR #85 --- src/frontend/enzymes.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index 24aacad5..99d217de 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -140,7 +140,8 @@ function enzyme_constrained_flux_balance_constraints( capacity_limits = capacity isa Real ? [(:total_capacity, gene_ids, (zero(capacity), capacity))] : [ - (Symbol(k), Symbol.(gs), C.BetweenT(; lower = zero(cap), upper = cap)) for (k, gs, cap) in capacity + (Symbol(k), Symbol.(gs), C.BetweenT(; lower = zero(cap), upper = cap)) for + (k, gs, cap) in capacity ], ) end @@ -257,7 +258,8 @@ function simplified_enzyme_constrained_flux_balance_constraints( (zero(capacity), capacity), )] : [ - (Symbol(k), Symbol.(fs), C.BetweenT(; lower = zero(cap), upper = cap)) for (k, fs, cap) in capacity + (Symbol(k), Symbol.(fs), C.BetweenT(; lower = zero(cap), upper = cap)) + for (k, fs, cap) in capacity ], ) * :gene_product_amounts^simplified_isozyme_gene_product_amount_constraints( From ff12cd0da46bded7e3f26018cf726a75afe802ea Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Mon, 13 Jan 2025 16:35:17 +0100 Subject: [PATCH 04/18] solve the capacity problem (incomplete, WIP) --- src/builders/enzymes.jl | 17 ++++++++-------- src/frontend/enzymes.jl | 44 +++++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/builders/enzymes.jl b/src/builders/enzymes.jl index 86f2a8aa..e4b1ce8c 100644 --- a/src/builders/enzymes.jl +++ b/src/builders/enzymes.jl @@ -175,10 +175,11 @@ gene product IDs to numbers (such as `Dict{Symbol, Float64}`), and All parameter functions may return `nothing`, at which point the given object is considered nonexistent and is omitted from constraints. -`capacity_limits` is an interable container of triples `(limit_id, -gene_product_ids, capacity_bound)` which are converted to a constraint +`capacity_limits` is an interable container of pairs `limit_id => +(gene_product_ids, capacity_bound)` which are converted to a constraint identified by the `limit_id` that limits the total mass of `gene_product_ids` -(which is any iterable container) by `capacity_bound`. +(which is any iterable container) by `capacity_bound` (which may be anything +usable as a bound in `Constraint`s). """ function enzyme_constraints(; fluxes_forward::C.ConstraintTree, @@ -220,7 +221,7 @@ function enzyme_constraints(; init = zero(C.LinearValue), ), bound, - ) for (id, gps, bound) in capacity_limits + ) for (id, (gps, bound)) in capacity_limits ) end @@ -271,7 +272,7 @@ Parameter functions `mass_cost_forward` and `mass_cost_reverse` take a flux ID the enzyme mass required to catalyze one "unit" of reaction in the forward or reverse direction, respectively. Returning `nothing` ignores the mass cost. -`capacity_limits` is an iterable container of triples `(limit_id, flux_ids, +`capacity_limits` is an iterable container of pairs `limit_id => (flux_ids, bound)`, which creates the capacity bounds over groups of fluxes (in the same manner as for gene products in [`enzyme_constraints`](@ref)). """ @@ -292,13 +293,13 @@ function simplified_enzyme_constraints(; id => C.Constraint(; value = C.sum( contribution(fluxes_forward, mass_cost_forward, f) for f in fs; - init = zero(C.LinearValue), # TODO not type stable if LinearValueT{not Float64} + init = zero(C.LinearValue), ) + C.sum( contribution(fluxes_reverse, mass_cost_reverse, f) for f in fs; - init = zero(C.LinearValue), # TODO not type stable if LinearValueT{not Float64} + init = zero(C.LinearValue), ), bound, - ) for (id, fs, bound) in capacity_limits + ) for (id, (fs, bound)) in capacity_limits ) end diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index 99d217de..0ddf408e 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -51,6 +51,30 @@ const Isozyme = IsozymeT{Float64} export Isozyme + +""" +$(TYPEDSIGNATURES) + +Expand the `capacity` argument as given to +[`enzyme_constrained_flux_balance_constraints`](@ref) and +[`simplified_enzyme_constrained_flux_balance_constraints`](@ref) into a form +accepted by [`enzyme_constraints`](@ref) and +[`simplified_enzyme_constraints`](@ref) (respectively). + +Overloading this function gives a way to simplify the interface of the +functions by accomodating custom capacity types. + +By default, `Bound`s are kept intact, `Real` values are converted to a fixed +interval between a zero and the value. All other values are assumed to be lists +of capacities. + +The second argument is given to the function as a list of full scope of the +capacities it can work with, by default "all capacities". +""" +expand_enzyme_capacity(x::Bound, all) = [:total_capacity => (all, x)] +expand_enzyme_capacity(x::Real, all) = [:total_capacity => (all, (zero(x), x))] +#TODO + """ $(TYPEDSIGNATURES) @@ -79,7 +103,7 @@ function enzyme_constrained_flux_balance_constraints( model::A.AbstractFBCModel; reaction_isozymes::Dict{String,Dict{String,IsozymeT{R}}}, gene_product_molar_masses::Dict{String,Float64}, - capacity::Union{Vector{Tuple{String,Vector{String},R}},R}, + capacity, interface::Maybe{Symbol} = nothing, interface_name = :interface, ) where {R<:Real} @@ -137,12 +161,7 @@ function enzyme_constrained_flux_balance_constraints( kcat_reverse, isozyme_gene_product_stoichiometry, gene_product_molar_mass, - capacity_limits = capacity isa Real ? - [(:total_capacity, gene_ids, (zero(capacity), capacity))] : - [ - (Symbol(k), Symbol.(gs), C.BetweenT(; lower = zero(cap), upper = cap)) for - (k, gs, cap) in capacity - ], + capacity_limits = expand_enzyme_capacity(capacity, gene_ids), ) end @@ -251,16 +270,7 @@ function simplified_enzyme_constrained_flux_balance_constraints( maybemap(last, get(min_isozyme_cost_forward, rid, nothing)), mass_cost_reverse = rid -> maybemap(last, get(min_isozyme_cost_reverse, rid, nothing)), - capacity_limits = capacity isa Real ? - [( - :total_capacity, - keys(constraints.fluxes), - (zero(capacity), capacity), - )] : - [ - (Symbol(k), Symbol.(fs), C.BetweenT(; lower = zero(cap), upper = cap)) - for (k, fs, cap) in capacity - ], + capacity_limits = expand_enzyme_capacity(capacity, keys(constraints.fluxes)), ) * :gene_product_amounts^simplified_isozyme_gene_product_amount_constraints( ( From 1ea118fc085acc7ac5517f006fb34e589e0b88d0 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 10:03:48 +0100 Subject: [PATCH 05/18] demagic the enzyme capacity interpretation functionality --- src/frontend/enzymes.jl | 62 +++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index 0ddf408e..7318ad01 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -61,19 +61,65 @@ Expand the `capacity` argument as given to accepted by [`enzyme_constraints`](@ref) and [`simplified_enzyme_constraints`](@ref) (respectively). -Overloading this function gives a way to simplify the interface of the -functions by accomodating custom capacity types. - By default, `Bound`s are kept intact, `Real` values are converted to a fixed interval between a zero and the value. All other values are assumed to be lists -of capacities. +of capacities. (See [`expand_enzyme_capacity_bound`](@ref) for translation of +actual bounds). + +Overloading this function (or [`expand_enzyme_capacity_bound`](@ref)) gives a +way to simplify the interface of the functions by accomodating custom capacity +types. -The second argument is given to the function as a list of full scope of the +The second argument is provided to this function as a list of full scope of the capacities it can work with, by default "all capacities". """ -expand_enzyme_capacity(x::Bound, all) = [:total_capacity => (all, x)] -expand_enzyme_capacity(x::Real, all) = [:total_capacity => (all, (zero(x), x))] -#TODO +expand_enzyme_capacity(x, all) = [:total_capacity => (all, expand_enzyme_capacity_bound(x))] + +""" +$(TYPEDSIGNATURES) + +Overload of [`expand_enzyme_capacity`](@ref) for all `Dict`-like iterables. +""" +expand_enzyme_capacity(x::Union{Vector{Pair},Dict}, all) = + expand_enzyme_capacity_iterable(x, all) + +""" +$(TYPEDSIGNATURES) + +Overload of [`expand_enzyme_capacity`](@ref) that provides compatibility with +the earlier capacity specifications (using triples instead of pairs). +""" +expand_enzyme_capacity(x::Vector{Tuple}, all) = expand_enzyme_capacity_iterable(x, all) + +export expand_enzyme_capacity + +""" +$(TYPEDSIGNATURES) + +Internal helper for implementation of [`expand_enzyme_capacity`](@ref) over +iterable `Dict`-like objects. +""" +expand_enzyme_capacity_iterable(x, all) = + [id => (grp, expand_enzyme_capacity_bound(cap)) for (id, (grp, cap)) in x] + +""" +$(TYPEDSIGNATURES) + +Expand a single capacity bound for use in enzyme-constrained models. +Overloading this function provides additional ways to interpret the capacity +specifications. Typically used via [`expand_enzyme_capacity`](@ref). +""" +expand_enzyme_capacity_bound(x::Real) = (zero(x), x) + +""" +$(TYPEDSIGNATURES) + +By default, [`expand_enzyme_capacity_bound`](@ref) leaves all `Bound`s intact. +This overload implements this property. +""" +expand_enzyme_capacity_bound(x::C.Bound) = x + +export expand_enzyme_capacity_bound """ $(TYPEDSIGNATURES) From 71d862ceb8c4ffcda1332d86f8ec4553431caf40 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 10:36:15 +0100 Subject: [PATCH 06/18] dodge coverage issues (some of them) --- src/frontend/enzymes.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index 7318ad01..b29226b5 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -73,7 +73,8 @@ types. The second argument is provided to this function as a list of full scope of the capacities it can work with, by default "all capacities". """ -expand_enzyme_capacity(x, all) = [:total_capacity => (all, expand_enzyme_capacity_bound(x))] +expand_enzyme_capacity(x, all) = + return [:total_capacity => (all, expand_enzyme_capacity_bound(x))] """ $(TYPEDSIGNATURES) @@ -81,7 +82,7 @@ $(TYPEDSIGNATURES) Overload of [`expand_enzyme_capacity`](@ref) for all `Dict`-like iterables. """ expand_enzyme_capacity(x::Union{Vector{Pair},Dict}, all) = - expand_enzyme_capacity_iterable(x, all) + return expand_enzyme_capacity_iterable(x, all) """ $(TYPEDSIGNATURES) @@ -89,7 +90,8 @@ $(TYPEDSIGNATURES) Overload of [`expand_enzyme_capacity`](@ref) that provides compatibility with the earlier capacity specifications (using triples instead of pairs). """ -expand_enzyme_capacity(x::Vector{Tuple}, all) = expand_enzyme_capacity_iterable(x, all) +expand_enzyme_capacity(x::Vector{Tuple}, all) = + return expand_enzyme_capacity_iterable(x, all) export expand_enzyme_capacity @@ -100,7 +102,7 @@ Internal helper for implementation of [`expand_enzyme_capacity`](@ref) over iterable `Dict`-like objects. """ expand_enzyme_capacity_iterable(x, all) = - [id => (grp, expand_enzyme_capacity_bound(cap)) for (id, (grp, cap)) in x] + return [id => (grp, expand_enzyme_capacity_bound(cap)) for (id, (grp, cap)) in x] """ $(TYPEDSIGNATURES) @@ -109,7 +111,7 @@ Expand a single capacity bound for use in enzyme-constrained models. Overloading this function provides additional ways to interpret the capacity specifications. Typically used via [`expand_enzyme_capacity`](@ref). """ -expand_enzyme_capacity_bound(x::Real) = (zero(x), x) +expand_enzyme_capacity_bound(x::Real) = return (zero(x), x) """ $(TYPEDSIGNATURES) @@ -117,7 +119,7 @@ $(TYPEDSIGNATURES) By default, [`expand_enzyme_capacity_bound`](@ref) leaves all `Bound`s intact. This overload implements this property. """ -expand_enzyme_capacity_bound(x::C.Bound) = x +expand_enzyme_capacity_bound(x::C.Bound) = return x export expand_enzyme_capacity_bound From 2fc9f402e6ceeb948166e9eb6f2b97cced5bf94a Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 10:45:55 +0100 Subject: [PATCH 07/18] fixify comments --- src/frontend/enzymes.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index b29226b5..f8401b46 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -142,7 +142,9 @@ material is limited by `capacity`. `capacity` may be a single number, which sets the mass limit for "all described enzymes". Alternatively, `capacity` may be a vector of identifier-genes-limit triples that together form a constraint (identified by the given identifier) -that limits the total sum of the listed genes to the given limit. +that limits the total sum of the listed genes to the given limit. The +interpretation of `capacity` is implemented (and can be extended) via +[`expand_enzyme_capacity`](@ref). `interface` and `interface_name` are forwarded to [`flux_balance_constraints`](@ref). @@ -248,9 +250,9 @@ constraints. BMC Bioinformatics 21, 19 (2020). https://doi.org/10.1186/s12859-019-3329-9*. Arguments are as with [`enzyme_constrained_flux_balance_constraints`](@ref), -with a major difference in `capacity` handling: the identifier lists (2nd -elements of the triples given in the list) are not identifiers of gene -products, but identifiers of reactions. +with a major difference in `capacity` handling: the identifier lists contain +reactions identifiers (i.e., keys of `fluxes` in the constraint tree), instead +of the gene product identifiers. """ function simplified_enzyme_constrained_flux_balance_constraints( model; From bc4e4cf110ef3a7a28e16f29902dca84486c10de Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 10:52:13 +0100 Subject: [PATCH 08/18] use the new bounding functionality in a tutorial --- .../src/examples/05b-enzyme-constrained-models.jl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/src/examples/05b-enzyme-constrained-models.jl b/docs/src/examples/05b-enzyme-constrained-models.jl index 54baacef..689ffa7b 100644 --- a/docs/src/examples/05b-enzyme-constrained-models.jl +++ b/docs/src/examples/05b-enzyme-constrained-models.jl @@ -34,6 +34,7 @@ download_model( # -- let's use HiGHS here: import AbstractFBCModels as A +import ConstraintTrees as C import JSONFBCModels import HiGHS @@ -377,12 +378,23 @@ ec_solution.gene_product_capacity # arguments as the [`enzyme_constrained_flux_balance_analysis`](@ref), but # automatically chooses the "fastest" reaction isozyme for each reaction # direction and builds the model with that. +# +# We additionally show how to specify more complex bounds for the capacities; +# in this case we list all fluxes for which we have isozyme data and add a +# realistic lower limit for the capacity. + +minimum_enzyme_capacity = 20.0 simplified_ec_solution = simplified_enzyme_constrained_flux_balance_analysis( model; reaction_isozymes, gene_product_molar_masses = ecoli_core_gene_product_masses, - capacity = total_enzyme_capacity, + capacity = Dict( + :total => ( + Symbol.(keys(reaction_isozymes)), + C.Between(minimum_enzyme_capacity, total_enzyme_capacity), + ), + ), optimizer = HiGHS.Optimizer, ) @@ -425,7 +437,6 @@ ec_optimum = optimized_values( ) # ...then creating a system constrained to near-optimal growth: -import ConstraintTrees as C ec_system.objective.bound = C.Between(0.99 * ec_optimum, Inf) From cadb631b953f1168fc5e91c47a8413bbc241a6eb Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 10:55:57 +0100 Subject: [PATCH 09/18] remove a forgotten type --- src/frontend/enzymes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index f8401b46..d5aab99a 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -258,7 +258,7 @@ function simplified_enzyme_constrained_flux_balance_constraints( model; reaction_isozymes::Dict{String,Dict{String,IsozymeT{R}}}, gene_product_molar_masses::Dict{String,Float64}, - capacity::Union{Vector{Tuple{String,Vector{String},R}},R}, + capacity, interface::Maybe{Symbol} = nothing, interface_name = :interface, ) where {R<:Real} From e9c528ab5fbe6721c945c4b5728d05c407cff125 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:00:38 +0100 Subject: [PATCH 10/18] fix ident --- docs/src/examples/05b-enzyme-constrained-models.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/examples/05b-enzyme-constrained-models.jl b/docs/src/examples/05b-enzyme-constrained-models.jl index 689ffa7b..67c83a8b 100644 --- a/docs/src/examples/05b-enzyme-constrained-models.jl +++ b/docs/src/examples/05b-enzyme-constrained-models.jl @@ -400,7 +400,7 @@ simplified_ec_solution = simplified_enzyme_constrained_flux_balance_analysis( # In this case, the result is the same as with the full analysis: -simplified_ec_solution.capacity_limits.total_capacity +simplified_ec_solution.capacity_limits.total # Gene product amounts are not present in the model but are reconstructed # nevertheless (they are uniquely determined by the flux): From 21469a6f666274c70f7d617a235a129fd2d2e1ea Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:06:39 +0100 Subject: [PATCH 11/18] add corner-case capacity handling tests --- test/misc.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/misc.jl b/test/misc.jl index 5994f46c..de123879 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -124,3 +124,17 @@ end universal_stoichiometry = stoi, ) end + +@testset "Enzyme capacity expansion compat & corner cases" begin + x = C.EqualTo(123.0) + @test expand_enzyme_capacity(x) === x # should not be touched, thus triple = + + x = expand_enzyme_capacity([(:test, [:ident], 123)]) + @test length(x) == 1 + (i, (ks, v)) = x + @test i == :test + @test ks == [:ident] + @test v isa C.Between + @test v.lower == 0.0 + @test v.upper == 123.0 +end From a9f69cfd87fffcca0532ff8a9981cf95c9b623fa Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:12:04 +0100 Subject: [PATCH 12/18] this needs a feature bump --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 8c9a4c95..865849f0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "COBREXA" uuid = "babc4406-5200-4a30-9033-bf5ae714c842" authors = ["The developers of COBREXA.jl"] -version = "2.5.0" +version = "2.6.0" [deps] AbstractFBCModels = "5a4f3dfa-1789-40f8-8221-69268c29937c" From 065b54b085134224926b15b06b4096a7591766c7 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:14:54 +0100 Subject: [PATCH 13/18] fix the tests --- test/misc.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/misc.jl b/test/misc.jl index de123879..5e51e332 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -127,9 +127,13 @@ end @testset "Enzyme capacity expansion compat & corner cases" begin x = C.EqualTo(123.0) - @test expand_enzyme_capacity(x) === x # should not be touched, thus triple = + y = expand_enzyme_capacity(x, [:ident]) + @test length(y) == 1 + (_, (ks, v)) = y[1] + @test ks == [:ident] + @test v === x # should not be touched, thus triple = - x = expand_enzyme_capacity([(:test, [:ident], 123)]) + x = expand_enzyme_capacity([(:test, [:ident], 123)], [:defa, :ults]) @test length(x) == 1 (i, (ks, v)) = x @test i == :test From 650d826eab9ef2832ea884ea78a55c49d1a03e03 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:20:12 +0100 Subject: [PATCH 14/18] debug type dispatch --- src/frontend/enzymes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index d5aab99a..9feacd5c 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -90,7 +90,7 @@ $(TYPEDSIGNATURES) Overload of [`expand_enzyme_capacity`](@ref) that provides compatibility with the earlier capacity specifications (using triples instead of pairs). """ -expand_enzyme_capacity(x::Vector{Tuple}, all) = +expand_enzyme_capacity(x::Vector{<:Tuple}, all) = return expand_enzyme_capacity_iterable(x, all) export expand_enzyme_capacity From 90561da88df74df5a674ee7c055365f0ab1e795f Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:23:39 +0100 Subject: [PATCH 15/18] reduce a bit of the CI pain by running the misc tests first --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index e7e8cd16..21da5a14 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -56,10 +56,10 @@ end # documentation, which doesn't get erased to improve the test caching. @testset "COBREXA test suite" begin - run_doc_examples() @testset "Miscellaneous tests" begin run_test_file("misc.jl") end + run_doc_examples() run_test_file("aqua.jl") end From 912354a4915a469a3d5428eeb218e1cb70e9f99e Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:27:01 +0100 Subject: [PATCH 16/18] fix tests more, actually translate the old capacity specs --- src/frontend/enzymes.jl | 2 +- test/misc.jl | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index 9feacd5c..a58df5c3 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -91,7 +91,7 @@ Overload of [`expand_enzyme_capacity`](@ref) that provides compatibility with the earlier capacity specifications (using triples instead of pairs). """ expand_enzyme_capacity(x::Vector{<:Tuple}, all) = - return expand_enzyme_capacity_iterable(x, all) + return expand_enzyme_capacity_iterable((id => (grp, cap) for (id, grp, cap) in x), all) export expand_enzyme_capacity diff --git a/test/misc.jl b/test/misc.jl index 5e51e332..f3d38ab3 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -127,11 +127,13 @@ end @testset "Enzyme capacity expansion compat & corner cases" begin x = C.EqualTo(123.0) - y = expand_enzyme_capacity(x, [:ident]) + all = [:ident] + y = expand_enzyme_capacity(x, all) @test length(y) == 1 (_, (ks, v)) = y[1] - @test ks == [:ident] - @test v === x # should not be touched, thus triple = + # these things should not be touched, thus triple = + @test ks === ident + @test v === x x = expand_enzyme_capacity([(:test, [:ident], 123)], [:defa, :ults]) @test length(x) == 1 From 59dff11ab50ce8b122e8270bef1923d1a7c78a8c Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:29:32 +0100 Subject: [PATCH 17/18] oh look at what we find --- test/misc.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/misc.jl b/test/misc.jl index f3d38ab3..e6130c12 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -18,6 +18,8 @@ # documentation. If you want to add tests here, first consider actually # documenting the functionality in `docs/src/examples/` instead. +import ConstraintTrees as C + @testset "Switch bound" begin x = Switch(5, 10) y = -(((1 + 0.5 * (((1 - x) + 1) * 4)) / 2) - 2.5) From 9be39619d4a7c7f8d0f03bca6c18d323692ca0c2 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Tue, 14 Jan 2025 11:37:57 +0100 Subject: [PATCH 18/18] fix even more --- src/frontend/enzymes.jl | 10 +++++----- test/misc.jl | 8 +++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/frontend/enzymes.jl b/src/frontend/enzymes.jl index a58df5c3..1025f13b 100644 --- a/src/frontend/enzymes.jl +++ b/src/frontend/enzymes.jl @@ -81,8 +81,8 @@ $(TYPEDSIGNATURES) Overload of [`expand_enzyme_capacity`](@ref) for all `Dict`-like iterables. """ -expand_enzyme_capacity(x::Union{Vector{Pair},Dict}, all) = - return expand_enzyme_capacity_iterable(x, all) +expand_enzyme_capacity(x::Union{Vector{Pair},Dict}, _) = + return expand_enzyme_capacity_iterable(x) """ $(TYPEDSIGNATURES) @@ -90,8 +90,8 @@ $(TYPEDSIGNATURES) Overload of [`expand_enzyme_capacity`](@ref) that provides compatibility with the earlier capacity specifications (using triples instead of pairs). """ -expand_enzyme_capacity(x::Vector{<:Tuple}, all) = - return expand_enzyme_capacity_iterable((id => (grp, cap) for (id, grp, cap) in x), all) +expand_enzyme_capacity(x::Vector{<:Tuple}, _) = + return expand_enzyme_capacity_iterable(id => (grp, cap) for (id, grp, cap) in x) export expand_enzyme_capacity @@ -101,7 +101,7 @@ $(TYPEDSIGNATURES) Internal helper for implementation of [`expand_enzyme_capacity`](@ref) over iterable `Dict`-like objects. """ -expand_enzyme_capacity_iterable(x, all) = +expand_enzyme_capacity_iterable(x) = return [id => (grp, expand_enzyme_capacity_bound(cap)) for (id, (grp, cap)) in x] """ diff --git a/test/misc.jl b/test/misc.jl index e6130c12..62217c4f 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -134,15 +134,13 @@ end @test length(y) == 1 (_, (ks, v)) = y[1] # these things should not be touched, thus triple = - @test ks === ident + @test ks === all @test v === x x = expand_enzyme_capacity([(:test, [:ident], 123)], [:defa, :ults]) @test length(x) == 1 - (i, (ks, v)) = x + (i, (ks, v)) = x[1] @test i == :test @test ks == [:ident] - @test v isa C.Between - @test v.lower == 0.0 - @test v.upper == 123.0 + @test v == (0, 123) end