Skip to content

Commit

Permalink
Merge pull request #2386 from AayushSabharwal/as/all-symbols
Browse files Browse the repository at this point in the history
feat: add new all-symbols methods from SII
  • Loading branch information
ChrisRackauckas authored Dec 28, 2023
2 parents 5da1628 + f6fea58 commit db8a9a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ SimpleNonlinearSolve = "0.1.0, 1"
SparseArrays = "1"
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 1.0, 2"
StaticArrays = "0.10, 0.11, 0.12, 1.0"
SymbolicIndexingInterface = "0.3"
SymbolicIndexingInterface = "0.3.1"
SymbolicUtils = "1.0"
Symbolics = "5.7"
URIs = "1"
Expand Down
14 changes: 14 additions & 0 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ SymbolicIndexingInterface.is_time_dependent(::AbstractTimeIndependentSystem) = f

SymbolicIndexingInterface.constant_structure(::AbstractSystem) = true

function SymbolicIndexingInterface.all_variable_symbols(sys::AbstractSystem)
syms = variable_symbols(sys)
obs = getproperty.(observed(sys), :lhs)
return isempty(obs) ? syms : vcat(syms, obs)
end

function SymbolicIndexingInterface.all_symbols(sys::AbstractSystem)
syms = all_variable_symbols(sys)
for other in (parameter_symbols(sys), independent_variable_symbols(sys))
isempty(other) || (syms = vcat(syms, other))
end
return syms
end

iscomplete(sys::AbstractSystem) = isdefined(sys, :complete) && getfield(sys, :complete)

"""
Expand Down
2 changes: 1 addition & 1 deletion test/distributed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ end
solve_lorenz(ode_prob)

future = @spawn solve_lorenz(ode_prob)
@test_broken fetch(future)
fetch(future)
3 changes: 2 additions & 1 deletion test/inversemodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using ModelingToolkit
using ModelingToolkitStandardLibrary
using ModelingToolkitStandardLibrary.Blocks
using OrdinaryDiffEq
using SymbolicIndexingInterface
using Test
using ControlSystemsMTK: tf, ss, get_named_sensitivity, get_named_comp_sensitivity

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

@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
@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

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

0 comments on commit db8a9a3

Please sign in to comment.