Skip to content

Commit 539fe81

Browse files
Merge pull request #2544 from AayushSabharwal/as/sii-default-values
refactor: implement new additions to SII interface
2 parents 65c9a04 + 713b2dc commit 539fe81

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ SimpleNonlinearSolve = "0.1.0, 1"
102102
SparseArrays = "1"
103103
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
104104
StaticArrays = "0.10, 0.11, 0.12, 1.0"
105-
SymbolicIndexingInterface = "0.3.1"
105+
SymbolicIndexingInterface = "0.3.11"
106106
SymbolicUtils = "1.0"
107107
Symbolics = "5.24"
108108
URIs = "1"

docs/src/basics/FAQ.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ Indexes into the `MTKParameters` object take the form of `ParameterIndex` object
2020
are similarly undocumented. Following is the list of behaviors that should be relied on for
2121
`MTKParameters`:
2222

23-
- It implements the SciMLStructures interface.
24-
- It can be queried for parameters using functions returned from
25-
`SymbolicIndexingInterface.getp`.
26-
- `getindex(::MTKParameters, ::ParameterIndex)` can be used to obtain the value of a
27-
parameter with the given index.
28-
- `setindex!(::MTKParameters, value, ::ParameterIndex)` can be used to set the value of a
29-
parameter with the given index.
30-
- `parameter_values(sys, sym)` will return a `ParameterIndex` object if `sys` has been
31-
`complete`d (through `structural_simplify`, `complete` or `@mtkbuild`).
32-
- `copy(::MTKParameters)` is defined and duplicates the parameter object, including the
33-
memory used by the underlying buffers.
23+
- It implements the SciMLStructures interface.
24+
- It can be queried for parameters using functions returned from
25+
`SymbolicIndexingInterface.getp`.
26+
- `getindex(::MTKParameters, ::ParameterIndex)` can be used to obtain the value of a
27+
parameter with the given index.
28+
- `setindex!(::MTKParameters, value, ::ParameterIndex)` can be used to set the value of a
29+
parameter with the given index.
30+
- `parameter_values(sys, sym)` will return a `ParameterIndex` object if `sys` has been
31+
`complete`d (through `structural_simplify`, `complete` or `@mtkbuild`).
32+
- `copy(::MTKParameters)` is defined and duplicates the parameter object, including the
33+
memory used by the underlying buffers.
3434

3535
Any other behavior of `MTKParameters` (other `getindex`/`setindex!` methods, etc.) is an
3636
undocumented internal and should not be relied upon.

src/systems/abstractsystem.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ function SymbolicIndexingInterface.is_observed(sys::AbstractSystem, sym)
495495
!is_independent_variable(sys, sym) && symbolic_type(sym) != NotSymbolic()
496496
end
497497

498+
SymbolicIndexingInterface.default_values(sys::AbstractSystem) = get_defaults(sys)
499+
498500
SymbolicIndexingInterface.is_time_dependent(::AbstractTimeDependentSystem) = true
499501
SymbolicIndexingInterface.is_time_dependent(::AbstractTimeIndependentSystem) = false
500502

src/systems/systemstructure.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ function _structural_simplify!(state::TearingState, io; simplify = false,
630630
if has_io
631631
ModelingToolkit.markio!(state, orig_inputs, io...)
632632
end
633-
if io !== nothing
633+
if io !== nothing || any(isinput, state.fullvars)
634634
state, input_idxs = ModelingToolkit.inputs_to_parameters!(state, io)
635635
else
636636
input_idxs = 0:-1 # Empty range

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ end
2424
@safetestset "Parsing Test" include("variable_parsing.jl")
2525
@safetestset "Simplify Test" include("simplify.jl")
2626
@safetestset "Direct Usage Test" include("direct.jl")
27+
@safetestset "SymbolicIndeingInterface test" include("symbolic_indexing_interface.jl")
2728
@safetestset "System Linearity Test" include("linearity.jl")
2829
@safetestset "Input Output Test" include("input_output_handling.jl")
2930
@safetestset "Clock Test" include("clock.jl")

test/symbolic_indexing_interface.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using ModelingToolkit, SymbolicIndexingInterface, SciMLBase
22

33
@parameters t a b
4-
@variables x(t) y(t)
4+
@variables x(t)=1.0 y(t)=2.0
55
D = Differential(t)
66
eqs = [D(x) ~ a * y + t, D(y) ~ b * t]
77
@named odesys = ODESystem(eqs, t, [x, y], [a, b])
@@ -21,6 +21,9 @@ eqs = [D(x) ~ a * y + t, D(y) ~ b * t]
2121
@test isequal(independent_variable_symbols(odesys), [t])
2222
@test is_time_dependent(odesys)
2323
@test constant_structure(odesys)
24+
@test !isempty(default_values(odesys))
25+
@test default_values(odesys)[x] == 1.0
26+
@test default_values(odesys)[y] == 2.0
2427

2528
@variables x y z
2629
@parameters σ ρ β

0 commit comments

Comments
 (0)