Skip to content

Commit db8a9a3

Browse files
Merge pull request #2386 from AayushSabharwal/as/all-symbols
feat: add new all-symbols methods from SII
2 parents 5da1628 + f6fea58 commit db8a9a3

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ SimpleNonlinearSolve = "0.1.0, 1"
9898
SparseArrays = "1"
9999
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
100100
StaticArrays = "0.10, 0.11, 0.12, 1.0"
101-
SymbolicIndexingInterface = "0.3"
101+
SymbolicIndexingInterface = "0.3.1"
102102
SymbolicUtils = "1.0"
103103
Symbolics = "5.7"
104104
URIs = "1"

src/systems/abstractsystem.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,20 @@ SymbolicIndexingInterface.is_time_dependent(::AbstractTimeIndependentSystem) = f
286286

287287
SymbolicIndexingInterface.constant_structure(::AbstractSystem) = true
288288

289+
function SymbolicIndexingInterface.all_variable_symbols(sys::AbstractSystem)
290+
syms = variable_symbols(sys)
291+
obs = getproperty.(observed(sys), :lhs)
292+
return isempty(obs) ? syms : vcat(syms, obs)
293+
end
294+
295+
function SymbolicIndexingInterface.all_symbols(sys::AbstractSystem)
296+
syms = all_variable_symbols(sys)
297+
for other in (parameter_symbols(sys), independent_variable_symbols(sys))
298+
isempty(other) || (syms = vcat(syms, other))
299+
end
300+
return syms
301+
end
302+
289303
iscomplete(sys::AbstractSystem) = isdefined(sys, :complete) && getfield(sys, :complete)
290304

291305
"""

test/distributed.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ end
3333
solve_lorenz(ode_prob)
3434

3535
future = @spawn solve_lorenz(ode_prob)
36-
@test_broken fetch(future)
36+
fetch(future)

test/inversemodel.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using ModelingToolkit
22
using ModelingToolkitStandardLibrary
33
using ModelingToolkitStandardLibrary.Blocks
44
using OrdinaryDiffEq
5+
using SymbolicIndexingInterface
56
using Test
67
using ControlSystemsMTK: tf, ss, get_named_sensitivity, get_named_comp_sensitivity
78

@@ -144,7 +145,7 @@ sol = solve(prob, Rodas5P())
144145
# plot(sol, idxs=[model.tank.xc, model.tank.xT, model.controller.ctr_output.u], layout=3, sp=[1 2 3])
145146
# hline!([prob[cm.ref.k]], label="ref", sp=1)
146147

147-
@test sol(tspan[2], idxs = cm.tank.xc)prob[cm.ref.k] atol=1e-2 # Test that the inverse model led to the correct reference
148+
@test sol(tspan[2], idxs = cm.tank.xc) getp(prob, cm.ref.k)(prob) atol=1e-2 # Test that the inverse model led to the correct reference
148149

149150
Sf, simplified_sys = Blocks.get_sensitivity_function(model, :y) # This should work without providing an operating opint containing a dummy derivative
150151
x, p = ModelingToolkit.get_u0_p(simplified_sys, op)

0 commit comments

Comments
 (0)