Skip to content

Commit

Permalink
Allow parameters to be passed as a vector of :symbol => value pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaandocal committed Jun 25, 2024
1 parent 8987d70 commit 72240c5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/build_rhs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/build_rhs_ss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/fspsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand All @@ -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

0 comments on commit 72240c5

Please sign in to comment.