SciML / FiniteStateProjection.jl

Finite State Projection algorithms for chemical reaction networks
MIT License
18 stars 7 forks source link

No method matching adjoint(::AbstractAlgebra.Generic.MatSpaceElem{BigInt}) #4

Closed voduchuy closed 9 months ago

voduchuy commented 2 years ago

I’m unable to set up the FSPSystem due to some error related to the adjoint method. I'm using Julia 1.7 on Apple M1. Here's the Julia code that ran into trouble. It's based on the telegraph example in the tutorial.

using FiniteStateProjection
using DifferentialEquations
using Sundials 
using SparseArrays

@parameters k01 k10 α γ
rn = @reaction_network begin 
    k01, G0 --> G1 
    k10, G1 --> G0 
    α, G1 --> G1 + RNA
    γ, RNA --> ∅
end k01 k10 α γ

ih = ReducingIndexHandler(rn)
fspsys = FSPSystem(rn, ih);
cons = conservedquantities([1, 0, 0], sys)

θ = (0.05, 0.1, 5.0, 1.0);
p0 = zeros(2, 200);
p0[1,1] = 1.0;
tspan = (0.0, 120.0);
prob = ODEProblem(fspsys, p0, tspan, θ);
@time sol = solve(prob, CVODE_BDF(linear_solver=:GMRES), atol=1e-14, rtol=1.0e-4, saveat=range(start=0.0, stop=120.0, step=20.0));

The error message is

LoadError: MethodError: no method matching adjoint(::AbstractAlgebra.Generic.MatSpaceElem{BigInt})

And here's the Stacktrace:

Stacktrace:
 [1] conservationlaws(nsm::LinearAlgebra.Adjoint{Int64, Matrix{Int64}})
   @ FiniteStateProjection ~/.julia/packages/FiniteStateProjection/7Rdxc/src/fspsystem.jl:83
 [2] conservationlaws(rs::ReactionSystem{Nothing})
   @ FiniteStateProjection ~/.julia/packages/FiniteStateProjection/7Rdxc/src/fspsystem.jl:94
 [3] ReducingIndexHandler(rs::ReactionSystem{Nothing}, offset::Int64) (repeats 2 times)
   @ FiniteStateProjection ~/.julia/packages/FiniteStateProjection/7Rdxc/src/indexhandlers.jl:138

Thanks for looking into this!

kaandocal commented 2 years ago

I recently noticed that ReducingIndexHandler does not work anymore, likely due to API changes in some of the packages. I was planning to move the functionality into Catalyst here but got distracted - I should write some tests and finish that soon. How about this code in the meantime?

using FiniteStateProjection
using DifferentialEquations
using Sundials 
using SparseArrays

@parameters k01 k10 α γ
rn = @reaction_network begin 
    k01 * (1 - G1), 0 --> G1 
    k10, G1 --> 0 
    α, G1 --> G1 + RNA
    γ, RNA --> ∅
end k01 k10 α γ

fspsys = FSPSystem(rn);

θ = (0.05, 0.1, 5.0, 1.0);
p0 = zeros(2, 200);
p0[1,1] = 1.0;
tspan = (0.0, 120.0);
prob = ODEProblem(fspsys, p0, tspan, θ);
@time sol = solve(prob, CVODE_BDF(linear_solver=:GMRES), atol=1e-14, rtol=1.0e-4, saveat=range(start=0.0, stop=120.0, step=20.0));
voduchuy commented 2 years ago

Thank you! It works now.