diff --git a/src/index_provider_interface.jl b/src/index_provider_interface.jl index ab5495f..a114450 100644 --- a/src/index_provider_interface.jl +++ b/src/index_provider_interface.jl @@ -126,10 +126,18 @@ end Return the observed function of `sym` in `indp` as a [`ParameterObservedFunction`](@ref). If `sym` only involves variables from a single parameter timeseries (optionally along with non-timeseries parameters) the timeseries index of the parameter timeseries should -be provided in the `ParameterObservedFunction`. In all other cases, just the observed -function should be returned as part of the object. +be provided in the [`ParameterObservedFunction`](@ref). In all other cases, just the +observed function should be returned as part of the `ParameterObservedFunction` object. + +By default, this function returns `nothing`. """ -parameter_observed(indp, sym) = parameter_observed(symbolic_container(indp), sym) +function parameter_observed(indp, sym) + if hasmethod(symbolic_container, Tuple{typeof(indp)}) + return parameter_observed(symbolic_container(indp), sym) + else + return nothing + end +end """ parameter_symbols(indp) diff --git a/src/parameter_indexing.jl b/src/parameter_indexing.jl index 1191c93..de2d6ca 100644 --- a/src/parameter_indexing.jl +++ b/src/parameter_indexing.jl @@ -301,6 +301,9 @@ function _getp(sys, ::ScalarSymbolic, ::SymbolicTypeTrait, p) end elseif is_observed(sys, p) pofn = parameter_observed(sys, p) + if pofn === nothing + throw(ArgumentError("Index provider does not support `parameter_observed`; cannot use generate function for $p")) + end if !is_time_dependent(sys) return GetParameterObservedNoTime(pofn.observed_fn) end @@ -624,6 +627,8 @@ function _setp(sys, ::ArraySymbolic, ::SymbolicTypeTrait, p) if is_parameter(sys, p) idx = parameter_index(sys, p) return setp(sys, idx; run_hook = false) + elseif is_observed(sys, p) && (pobsfn = parameter_observed(sys, p)) !== nothing + return GetParameterObserved{false}(pobsfn.timeseries_idx, pobsfn.observed_fn) end return setp(sys, collect(p); run_hook = false) end