diff --git a/docs/src/api.md b/docs/src/api.md index 065a1042..dc9b0d1a 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -14,6 +14,8 @@ is_observed observed is_time_dependent constant_structure +all_solvable_symbols +all_symbols parameter_values getp setp diff --git a/docs/src/tutorial.md b/docs/src/tutorial.md index b0ede675..5a7f7973 100644 --- a/docs/src/tutorial.md +++ b/docs/src/tutorial.md @@ -41,6 +41,8 @@ struct ExampleSolution state_index::Dict{Symbol,Int} parameter_index::Dict{Symbol,Int} independent_variable::Union{Symbol,Nothing} + # mapping from observed variable to Expr to calculate its value + observed::Dict{Symbol,Expr} u::Vector{Vector{Float64}} p::Vector{Float64} t::Vector{Float64} @@ -86,9 +88,9 @@ function SymbolicIndexingInterface.independent_variable_symbols(sys::ExampleSolu sys.independent_variable === nothing ? [] : [sys.independent_variable] end -# this types accepts `Expr` for observed expressions involving state/parameter +# this type accepts `Expr` for observed expressions involving state/parameter/observed # variables -SymbolicIndexingInterface.is_observed(sys::ExampleSolution, sym) = sym isa Expr +SymbolicIndexingInterface.is_observed(sys::ExampleSolution, sym) = sym isa Expr || sym isa Symbol && haskey(sys.observed, sym) function SymbolicIndexingInterface.observed(sys::ExampleSolution, sym::Expr) if is_time_dependent(sys) @@ -109,6 +111,21 @@ function SymbolicIndexingInterface.is_time_dependent(sys::ExampleSolution) end SymbolicIndexingInterface.constant_structure(::ExampleSolution) = true + +function SymbolicIndexingInterface.all_solvable_symbols(sys::ExampleSolution) + return vcat( + collect(keys(sys.state_index)), + collect(keys(sys.observed)), + ) +end + +function SymbolicIndexingInterface.all_symbols(sys::ExampleSolution) + return vcat( + all_solvable_symbols(sys), + collect(keys(sys.parameter_index)), + sys.independent_variable === nothing ? Symbol[] : sys.independent_variable + ) +end ``` Note that the method definitions are all assuming `constant_structure(p) == true`. diff --git a/src/interface.jl b/src/interface.jl index bcce0b20..bd43c53b 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -110,3 +110,19 @@ Check if `sys` has a constant structure. Constant structure systems do not chang number of variables or parameters over time. """ constant_structure(sys) = constant_structure(symbolic_container(sys)) + +""" + all_solvable_symbols(sys) + +Return an array of all symbols in the system that can be solved for. This includes +observed variables, but not parameters or independent variables. +""" +all_solvable_symbols(sys) = all_solvable_symbols(symbolic_container(sys)) + +""" + all_symbols(sys) + +Return an array of all symbols in the system. This includes parameters and independent +variables. +""" +all_symbols(sys) = all_symbols(symbolic_container(sys))