Skip to content

Commit 7b26af0

Browse files
fix: fix backward compatibility
1 parent efa68af commit 7b26af0

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/index_provider_interface.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,18 @@ end
126126
Return the observed function of `sym` in `indp` as a [`ParameterObservedFunction`](@ref).
127127
If `sym` only involves variables from a single parameter timeseries (optionally along
128128
with non-timeseries parameters) the timeseries index of the parameter timeseries should
129-
be provided in the `ParameterObservedFunction`. In all other cases, just the observed
130-
function should be returned as part of the object.
129+
be provided in the [`ParameterObservedFunction`](@ref). In all other cases, just the
130+
observed function should be returned as part of the `ParameterObservedFunction` object.
131+
132+
By default, this function returns `nothing`.
131133
"""
132-
parameter_observed(indp, sym) = parameter_observed(symbolic_container(indp), sym)
134+
function parameter_observed(indp, sym)
135+
if hasmethod(symbolic_container, Tuple{typeof(indp)})
136+
return parameter_observed(symbolic_container(indp), sym)
137+
else
138+
return nothing
139+
end
140+
end
133141

134142
"""
135143
parameter_symbols(indp)

src/parameter_indexing.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ function _getp(sys, ::ScalarSymbolic, ::SymbolicTypeTrait, p)
301301
end
302302
elseif is_observed(sys, p)
303303
pofn = parameter_observed(sys, p)
304+
if pofn === nothing
305+
throw(ArgumentError("Index provider does not support `parameter_observed`; cannot use generate function for $p"))
306+
end
304307
if !is_time_dependent(sys)
305308
return GetParameterObservedNoTime(pofn.observed_fn)
306309
end
@@ -624,6 +627,8 @@ function _setp(sys, ::ArraySymbolic, ::SymbolicTypeTrait, p)
624627
if is_parameter(sys, p)
625628
idx = parameter_index(sys, p)
626629
return setp(sys, idx; run_hook = false)
630+
elseif is_observed(sys, p) && (pobsfn = parameter_observed(sys, p)) !== nothing
631+
return GetParameterObserved{false}(pobsfn.timeseries_idx, pobsfn.observed_fn)
627632
end
628633
return setp(sys, collect(p); run_hook = false)
629634
end

0 commit comments

Comments
 (0)