Skip to content

Commit 405b1a5

Browse files
feat: add default_values to interface
1 parent 2a45e9c commit 405b1a5

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

docs/src/complete_sii.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct ExampleSystem
88
state_index::Dict{Symbol,Int}
99
parameter_index::Dict{Symbol,Int}
1010
independent_variable::Union{Symbol,Nothing}
11+
defaults::Dict{Symbol, Float64}
1112
# mapping from observed variable to Expr to calculate its value
1213
observed::Dict{Symbol,Expr}
1314
end
@@ -77,6 +78,10 @@ function SymbolicIndexingInterface.all_symbols(sys::ExampleSystem)
7778
sys.independent_variable === nothing ? Symbol[] : sys.independent_variable
7879
)
7980
end
81+
82+
function SymbolicIndexingInterface.default_values(sys::ExampleSystem)
83+
return sys.defaults
84+
end
8085
```
8186

8287
### Observed Equation Handling

src/SymbolicIndexingInterface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export is_variable, variable_index, variable_symbols, is_parameter, parameter_in
99
is_observed,
1010
observed, is_time_dependent, constant_structure, symbolic_container,
1111
all_variable_symbols,
12-
all_symbols, solvedvariables, allvariables
12+
all_symbols, solvedvariables, allvariables, default_values
1313
include("interface.jl")
1414

1515
export SymbolCache

src/interface.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ variables.
134134
"""
135135
all_symbols(sys) = all_symbols(symbolic_container(sys))
136136

137+
"""
138+
default_values(sys)
139+
140+
Return a dictionary mapping symbols in the system to their default value, if any. This includes
141+
parameter symbols.
142+
"""
143+
default_values(sys) = default_values(symbolic_container(sys))
144+
137145
struct SolvedVariables end
138146

139147
"""

src/symbol_cache.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ all_variable_symbols(sc::SymbolCache) = variable_symbols(sc)
7575
function all_symbols(sc::SymbolCache)
7676
vcat(variable_symbols(sc), parameter_symbols(sc), independent_variable_symbols(sc))
7777
end
78+
default_values(::SymbolCache) = Dict()
7879

7980
function Base.copy(sc::SymbolCache)
8081
return SymbolCache(sc.variables === nothing ? nothing : copy(sc.variables),

test/symbol_cache_test.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ sc = SymbolCache([:x, :y, :z], [:a, :b], [:t])
1919
@test independent_variable_symbols(sc) == [:t]
2020
@test all_variable_symbols(sc) == [:x, :y, :z]
2121
@test sort(all_symbols(sc)) == [:a, :b, :t, :x, :y, :z]
22+
@test isempty(default_values(sc))
2223

2324
sc = SymbolCache([:x, :y], [:a, :b])
2425
@test !is_time_dependent(sc)
@@ -38,6 +39,7 @@ sc = SymbolCache()
3839
@test !is_time_dependent(sc)
3940
@test all_variable_symbols(sc) == []
4041
@test all_symbols(sc) == []
42+
@test isempty(default_values(sc))
4143

4244
sc = SymbolCache(nothing, nothing, :t)
4345
@test all(.!is_independent_variable.((sc,), [:x, :y, :a, :b]))
@@ -46,6 +48,7 @@ sc = SymbolCache(nothing, nothing, :t)
4648
@test is_time_dependent(sc)
4749
@test all_variable_symbols(sc) == []
4850
@test all_symbols(sc) == [:t]
51+
@test isempty(default_values(sc))
4952

5053
sc2 = copy(sc)
5154
@test sc.variables == sc2.variables

0 commit comments

Comments
 (0)