From 72240c5b11584a4735ba29ee792782a58c69576d Mon Sep 17 00:00:00 2001 From: kaandocal <26488673+kaandocal@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:27:52 -0600 Subject: [PATCH] Allow parameters to be passed as a vector of :symbol => value pairs --- src/build_rhs.jl | 4 ++-- src/build_rhs_ss.jl | 4 ++-- src/fspsystem.jl | 5 +++++ src/matrix.jl | 8 ++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/build_rhs.jl b/src/build_rhs.jl index bb72745..14b2711 100644 --- a/src/build_rhs.jl +++ b/src/build_rhs.jl @@ -139,6 +139,6 @@ Return an `ODEProblem` for use in `DifferentialEquations`. This function implici calls `convert(ODEFunction, sys)`. It is usually more efficient to create an `ODEFunction` first and then use that to create `ODEProblem`s. """ -function Base.convert(::Type{ODEProblem}, sys::FSPSystem, u0, tint, p=NullParameters()) - ODEProblem(convert(ODEFunction, sys), u0, tint, p) +function Base.convert(::Type{ODEProblem}, sys::FSPSystem, u0, tint, pmap=NullParameters()) + ODEProblem(convert(ODEFunction, sys), u0, tint, pmap_to_p(sys, pmap)) end diff --git a/src/build_rhs_ss.jl b/src/build_rhs_ss.jl index b537149..40e2a4d 100644 --- a/src/build_rhs_ss.jl +++ b/src/build_rhs_ss.jl @@ -72,6 +72,6 @@ Base.convert(::Type{ODEFunction}, sys::FSPSystem, ::SteadyState) = ODEFunction{t Return a `SteadyStateProblem` for use in `DifferentialEquations. """ -function Base.convert(::Type{SteadyStateProblem}, sys::FSPSystem, u0, p=NullParameters()) - SteadyStateProblem(convert(ODEFunction, sys, SteadyState()), u0, p) +function Base.convert(::Type{SteadyStateProblem}, sys::FSPSystem, u0, pmap=NullParameters()) + SteadyStateProblem(convert(ODEFunction, sys, SteadyState()), u0, pmap_to_p(sys, pmap)) end diff --git a/src/fspsystem.jl b/src/fspsystem.jl index a2081e7..531cf0a 100644 --- a/src/fspsystem.jl +++ b/src/fspsystem.jl @@ -49,3 +49,8 @@ function compile_ratefunc(ex_rf, params) ex = :((idx_in, t, $(params...)) -> $(ex_rf)) |> MacroTools.flatten @RuntimeGeneratedFunction(ex) end + +function pmap_to_p(sys::FSPSystem, pmap) + pmap_conv = eltype(pmap) <: Pair{Symbol} ? Catalyst.symmap_to_varmap(sys.rs, pmap) : pmap + ModelingToolkit.varmap_to_vars(pmap_conv, Catalyst.parameters(sys.rs)) +end diff --git a/src/matrix.jl b/src/matrix.jl index ddd19c0..6101665 100644 --- a/src/matrix.jl +++ b/src/matrix.jl @@ -84,8 +84,8 @@ Chemical Master Equation. `dims` is a tuple denoting the dimensions of the FSP a `ps` is the tuple of parameters. The sparse matrix works on the flattened version of the state obtained using `vec`. """ -function Base.convert(::Type{SparseMatrixCSC}, sys::FSPSystem, dims::NTuple, ps, t::Real) - create_sparsematrix(sys, dims, ps, t) +function Base.convert(::Type{SparseMatrixCSC}, sys::FSPSystem, dims::NTuple, pmap, t::Real) + create_sparsematrix(sys, dims, pmap_to_p(sys, pmap), t) end """ @@ -94,6 +94,6 @@ end Convert the reaction system into a sparse matrix defining the right-hand side of the Chemical Master Equation, steady-state version. """ -function Base.convert(::Type{SparseMatrixCSC}, sys::FSPSystem, dims::NTuple, ps, ::SteadyState) - create_sparsematrix_ss(sys, dims, ps) +function Base.convert(::Type{SparseMatrixCSC}, sys::FSPSystem, dims::NTuple, pmap, ::SteadyState) + create_sparsematrix_ss(sys, dims, pmap_to_p(sys, pmap)) end