Skip to content

Commit 4650a34

Browse files
refactor: rewrite parameter timeseries interface, indexing
- some new, some deleted interface methods - extensive validation for input values - consistency with getu and getp - proper error messages
1 parent 2c8255e commit 4650a34

File tree

6 files changed

+833
-161
lines changed

6 files changed

+833
-161
lines changed

src/SymbolicIndexingInterface.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ export ScalarSymbolic, ArraySymbolic, NotSymbolic, symbolic_type, hasname, getna
1212
include("trait.jl")
1313

1414
export is_variable, variable_index, variable_symbols, is_parameter, parameter_index,
15+
is_timeseries_parameter, timeseries_parameter_index, ParameterTimeseriesIndex,
1516
parameter_symbols, is_independent_variable, independent_variable_symbols,
16-
is_observed,
17-
observed, is_time_dependent, constant_structure, symbolic_container,
18-
all_variable_symbols,
19-
all_symbols, solvedvariables, allvariables, default_values, symbolic_evaluate
17+
is_observed, observed, parameter_observed, ParameterObservedFunction,
18+
is_time_dependent, constant_structure, symbolic_container,
19+
all_variable_symbols, all_symbols, solvedvariables, allvariables, default_values,
20+
symbolic_evaluate
2021
include("index_provider_interface.jl")
2122

2223
export SymbolCache
2324
include("symbol_cache.jl")
2425

2526
export parameter_values, set_parameter!, finalize_parameters_hook!,
26-
parameter_values_at_time, parameter_values_at_state_time, parameter_timeseries,
27+
get_parameter_timeseries_collection, with_updated_parameter_timeseries_values,
2728
state_values, set_state!, current_time
2829
include("value_provider_interface.jl")
2930

src/index_provider_interface.jl

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,66 @@ Return the index of the given parameter `sym` in `indp`, or `nothing` otherwise.
5353
"""
5454
parameter_index(indp, sym) = parameter_index(symbolic_container(indp), sym)
5555

56+
"""
57+
is_timeseries_parameter(indp, sym)
58+
59+
Check whether the given `sym` is a timeseries parameter in `indp`.
60+
"""
61+
function is_timeseries_parameter(indp, sym)
62+
if hasmethod(symbolic_container, Tuple{typeof(indp)})
63+
is_timeseries_parameter(symbolic_container(indp), sym)
64+
else
65+
return false
66+
end
67+
end
68+
69+
"""
70+
struct ParameterTimeseriesIndex
71+
function ParameterTimeseriesIndex(timeseries_idx, parameter_idx)
72+
73+
A struct storing the index of the timeseries of a timeseries parameter in a parameter
74+
timeseries object. `timeseries_idx` refers to an index that identifies the timeseries
75+
that the parameter belongs to. `parameter_idx` refers to the index of the parameter's
76+
timeseries in that timeseries object. Note that `parameter_idx` may be different from
77+
the object returned by [`parameter_index`](@ref) for a given parameter. The two fields in
78+
this struct are `timeseries_idx` and `parameter_idx`.
79+
"""
80+
struct ParameterTimeseriesIndex{T, I}
81+
timeseries_idx::T
82+
parameter_idx::I
83+
end
84+
85+
"""
86+
timeseries_parameter_index(indp, sym)
87+
88+
Return the index of timeseries parameter `sym` in `indp`. Must return this index as a
89+
[`ParameterTimeseriesIndex`](@ref) object. Return `nothing` if `sym` is not a timeseries
90+
parameter in `indp`. Defaults to returning `nothing`. Respects the
91+
[`symbolic_container`](@ref) fallback for `indp` if present.
92+
"""
93+
function timeseries_parameter_index(indp, sym)
94+
if hasmethod(symbolic_container, Tuple{typeof(indp)})
95+
timeseries_parameter_index(symbolic_container(indp), sym)
96+
else
97+
return nothing
98+
end
99+
end
100+
101+
struct ParameterObservedFunction{I, F <: Function}
102+
timeseries_idx::I
103+
observed_fn::F
104+
end
105+
106+
"""
107+
parameter_observed(indp, sym)
108+
109+
Return the observed function of `sym` in `indp`. The returned function must have the
110+
signature `(p, t) -> [values...]` where `p` is the parameter object and `t` is the
111+
current time. If `!is_time_dependent(indp)` then the returned function must have the
112+
signature `(p) -> [values...]`.
113+
"""
114+
parameter_observed(indp, sym) = parameter_observed(symbolic_container(indp), sym)
115+
56116
"""
57117
parameter_symbols(indp)
58118
@@ -88,7 +148,7 @@ is_observed(indp, sym) = is_observed(symbolic_container(indp), sym)
88148
89149
Return the observed function of the given `sym` in `indp`. The returned function should
90150
have the signature `(u, p) -> [values...]` where `u` and `p` is the current state and
91-
parameter vector, respectively. If `istimedependent(indp) == true`, the function should
151+
parameter object, respectively. If `istimedependent(indp) == true`, the function should
92152
accept the current time `t` as its third parameter. If `constant_structure(indp) == false`,
93153
`observed` accepts a third parameter, which can either be a vector of symbols indicating
94154
the order of states or a time index, which identifies the order of states. This function

0 commit comments

Comments
 (0)