Skip to content

Commit

Permalink
fix: fix backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Jun 4, 2024
1 parent efa68af commit 7b26af0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/index_provider_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 138 in src/index_provider_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/index_provider_interface.jl#L138

Added line #L138 was not covered by tests
end
end

"""
parameter_symbols(indp)
Expand Down
5 changes: 5 additions & 0 deletions src/parameter_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Check warning on line 305 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L305

Added line #L305 was not covered by tests
end
if !is_time_dependent(sys)
return GetParameterObservedNoTime(pofn.observed_fn)
end
Expand Down Expand Up @@ -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)

Check warning on line 631 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L630-L631

Added lines #L630 - L631 were not covered by tests
end
return setp(sys, collect(p); run_hook = false)
end

0 comments on commit 7b26af0

Please sign in to comment.