Skip to content

Commit cdf30dc

Browse files
committed
Merge branch 'master' into myb/differential_alias
2 parents 891f58c + e1e6b9a commit cdf30dc

23 files changed

+298
-695
lines changed

Project.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "8.14.1"
4+
version = "8.15.1"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -11,7 +11,6 @@ ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1111
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
1212
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
1313
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
14-
DiffEqJump = "c894b116-72e5-5b58-be3c-e6d8d4ac2b12"
1514
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
1615
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
1716
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
@@ -21,6 +20,7 @@ Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
2120
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
2221
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2322
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
23+
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
2424
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
2525
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
2626
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
@@ -30,7 +30,6 @@ NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
3030
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
3131
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
3232
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
33-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
3433
RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
3534
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
3635
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
@@ -51,22 +50,21 @@ ConstructionBase = "1"
5150
DataStructures = "0.17, 0.18"
5251
DiffEqBase = "6.83.0"
5352
DiffEqCallbacks = "2.16"
54-
DiffEqJump = "7.0, 8"
5553
DiffRules = "0.1, 1.0"
5654
Distributions = "0.23, 0.24, 0.25"
5755
DocStringExtensions = "0.7, 0.8, 0.9"
5856
DomainSets = "0.5"
5957
Graphs = "1.5.2"
6058
IfElse = "0.1"
6159
JuliaFormatter = "1"
60+
JumpProcesses = "9"
6261
LabelledArrays = "1.3"
6362
Latexify = "0.11, 0.12, 0.13, 0.14, 0.15"
6463
MacroTools = "0.5"
6564
NaNMath = "0.3, 1"
6665
NonlinearSolve = "0.3.8"
6766
RecursiveArrayTools = "2.3"
6867
Reexport = "0.2, 1"
69-
Requires = "1.0"
7068
RuntimeGeneratedFunctions = "0.4.3, 0.5"
7169
SciMLBase = "1.26.2"
7270
Setfield = "0.7, 0.8, 1"

docs/pages.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pages = [
88
"tutorials/nonlinear.md",
99
"tutorials/optimization.md",
1010
"tutorials/stochastic_diffeq.md",
11-
"tutorials/nonlinear_optimal_control.md",
1211
"tutorials/parameter_identifiability.md"],
1312
"ModelingToolkitize Tutorials" => Any["mtkitize_tutorials/modelingtoolkitize.md",
1413
"mtkitize_tutorials/modelingtoolkitize_index_reduction.md",
@@ -25,7 +24,6 @@ pages = [
2524
"systems/JumpSystem.md",
2625
"systems/NonlinearSystem.md",
2726
"systems/OptimizationSystem.md",
28-
"systems/ControlSystem.md",
2927
"systems/PDESystem.md"],
3028
"comparison.md",
3129
"internals.md",

docs/src/systems/ControlSystem.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

docs/src/tutorials/nonlinear_optimal_control.md

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/ModelingToolkit.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using Latexify, Unitful, ArrayInterfaceCore
1212
using MacroTools
1313
@reexport using UnPack
1414
using Setfield, ConstructionBase
15-
using DiffEqJump
15+
using JumpProcesses
1616
using DataStructures
1717
using SpecialFunctions, NaNMath
1818
using RuntimeGeneratedFunctions
@@ -60,8 +60,6 @@ import DiffEqBase: @add_kwonly
6060

6161
import Graphs: SimpleDiGraph, add_edge!, incidence_matrix
6262

63-
using Requires
64-
6563
for fun in [:toexpr]
6664
@eval begin
6765
function $fun(eq::Equation; kw...)
@@ -121,6 +119,7 @@ include("domains.jl")
121119

122120
include("systems/abstractsystem.jl")
123121
include("systems/connectors.jl")
122+
include("systems/callbacks.jl")
124123

125124
include("systems/diffeqs/odesystem.jl")
126125
include("systems/diffeqs/sdesystem.jl")
@@ -136,8 +135,6 @@ include("systems/nonlinear/modelingtoolkitize.jl")
136135

137136
include("systems/optimization/optimizationsystem.jl")
138137

139-
include("systems/control/controlsystem.jl")
140-
141138
include("systems/pde/pdesystem.jl")
142139

143140
include("systems/sparsematrixclil.jl")
@@ -172,13 +169,11 @@ export AutoModelingToolkit
172169
export SteadyStateProblem, SteadyStateProblemExpr
173170
export JumpProblem, DiscreteProblem
174171
export NonlinearSystem, OptimizationSystem
175-
export ControlSystem
176172
export alias_elimination, flatten
177173
export connect, @connector, Connection, Flow, Stream, instream
178174
export isinput, isoutput, getbounds, hasbounds, isdisturbance, istunable, getdist, hasdist,
179175
tunable_parameters, isirreducible
180176
export ode_order_lowering, dae_order_lowering, liouville_transform
181-
export runge_kutta_discretize
182177
export PDESystem
183178
export Differential, expand_derivatives, @derivatives
184179
export Equation, ConstrainedEquation

src/structural_transformation/bipartite_tearing/modia_tearing.jl

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,42 +52,13 @@ function tear_graph_modia(structure::SystemStructure, ::Type{U} = Unassigned;
5252
var_eq_matching = complete(maximal_matching(graph, eqfilter, varfilter, U))
5353
var_sccs::Vector{Union{Vector{Int}, Int}} = find_var_sccs(graph, var_eq_matching)
5454

55-
# Here, we're using a maximal matching on the post-pantelides system to find
56-
# the strongly connected components of the system (of variables that depend
57-
# on each other). The strongly connected components are unique, however, the
58-
# maximal matching itself is not. Every maximal matching gives rise to the
59-
# same set of strongly connected components, but the associated equations need
60-
# not be the same. In the absence of solvability constraints, this may be a
61-
# small issue, but here it is possible that an equation got assigned to an
62-
# scc that cannot actually use it for solving a variable, but still precludes
63-
# another scc from using it. To avoid this, we delete any assignments that
64-
# are not in the solvable graph and extend the set of considered eqauations
65-
# below.
66-
for var in ndsts(solvable_graph)
67-
var_eq_matching[var] === unassigned && continue
68-
if !(BipartiteEdge(var, var_eq_matching[var]) in solvable_graph)
69-
var_eq_matching[var] = unassigned
70-
end
71-
end
72-
7355
for vars in var_sccs
7456
filtered_vars = filter(varfilter, vars)
7557
ieqs = Int[var_eq_matching[v]
7658
for v in filtered_vars if var_eq_matching[v] !== unassigned]
7759
for var in vars
7860
var_eq_matching[var] = unassigned
7961
end
80-
for var in filtered_vars
81-
# Add any equations that we may not have been able to use earlier to see
82-
# if a different matching may have been possible.
83-
for eq′ in 𝑑neighbors(solvable_graph, var)
84-
eqfilter(eq′) || continue
85-
eq′ in ieqs && continue
86-
if invview(var_eq_matching)[eq′] === unassigned
87-
push!(ieqs, eq′)
88-
end
89-
end
90-
end
9162
tear_graph_block_modia!(var_eq_matching, graph, solvable_graph, ieqs, filtered_vars)
9263
end
9364

src/systems/abstractsystem.jl

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -162,61 +162,6 @@ independent_variables(sys::AbstractTimeDependentSystem) = [getfield(sys, :iv)]
162162
independent_variables(sys::AbstractTimeIndependentSystem) = []
163163
independent_variables(sys::AbstractMultivariateSystem) = getfield(sys, :ivs)
164164

165-
const NULL_AFFECT = Equation[]
166-
struct SymbolicContinuousCallback
167-
eqs::Vector{Equation}
168-
affect::Vector{Equation}
169-
function SymbolicContinuousCallback(eqs::Vector{Equation}, affect = NULL_AFFECT)
170-
new(eqs, affect)
171-
end # Default affect to nothing
172-
end
173-
174-
function Base.:(==)(e1::SymbolicContinuousCallback, e2::SymbolicContinuousCallback)
175-
isequal(e1.eqs, e2.eqs) && isequal(e1.affect, e2.affect)
176-
end
177-
Base.isempty(cb::SymbolicContinuousCallback) = isempty(cb.eqs)
178-
function Base.hash(cb::SymbolicContinuousCallback, s::UInt)
179-
s = foldr(hash, cb.eqs, init = s)
180-
foldr(hash, cb.affect, init = s)
181-
end
182-
183-
to_equation_vector(eq::Equation) = [eq]
184-
to_equation_vector(eqs::Vector{Equation}) = eqs
185-
function to_equation_vector(eqs::Vector{Any})
186-
isempty(eqs) || error("This should never happen")
187-
Equation[]
188-
end
189-
190-
function SymbolicContinuousCallback(args...)
191-
SymbolicContinuousCallback(to_equation_vector.(args)...)
192-
end # wrap eq in vector
193-
SymbolicContinuousCallback(p::Pair) = SymbolicContinuousCallback(p[1], p[2])
194-
SymbolicContinuousCallback(cb::SymbolicContinuousCallback) = cb # passthrough
195-
196-
SymbolicContinuousCallbacks(cb::SymbolicContinuousCallback) = [cb]
197-
SymbolicContinuousCallbacks(cbs::Vector{<:SymbolicContinuousCallback}) = cbs
198-
SymbolicContinuousCallbacks(cbs::Vector) = SymbolicContinuousCallback.(cbs)
199-
function SymbolicContinuousCallbacks(ve::Vector{Equation})
200-
SymbolicContinuousCallbacks(SymbolicContinuousCallback(ve))
201-
end
202-
function SymbolicContinuousCallbacks(others)
203-
SymbolicContinuousCallbacks(SymbolicContinuousCallback(others))
204-
end
205-
SymbolicContinuousCallbacks(::Nothing) = SymbolicContinuousCallbacks(Equation[])
206-
207-
equations(cb::SymbolicContinuousCallback) = cb.eqs
208-
function equations(cbs::Vector{<:SymbolicContinuousCallback})
209-
reduce(vcat, [equations(cb) for cb in cbs])
210-
end
211-
affect_equations(cb::SymbolicContinuousCallback) = cb.affect
212-
function affect_equations(cbs::Vector{SymbolicContinuousCallback})
213-
reduce(vcat, [affect_equations(cb) for cb in cbs])
214-
end
215-
namespace_equation(cb::SymbolicContinuousCallback, s)::SymbolicContinuousCallback = SymbolicContinuousCallback(namespace_equation.(equations(cb),
216-
(s,)),
217-
namespace_equation.(affect_equations(cb),
218-
(s,)))
219-
220165
for prop in [:eqs
221166
:noiseeqs
222167
:iv
@@ -507,18 +452,6 @@ function observed(sys::AbstractSystem)
507452
init = Equation[])]
508453
end
509454

510-
function continuous_events(sys::AbstractSystem)
511-
obs = get_continuous_events(sys)
512-
filter(!isempty, obs)
513-
systems = get_systems(sys)
514-
cbs = [obs;
515-
reduce(vcat,
516-
(map(o -> namespace_equation(o, s), continuous_events(s))
517-
for s in systems),
518-
init = SymbolicContinuousCallback[])]
519-
filter(!isempty, cbs)
520-
end
521-
522455
Base.@deprecate default_u0(x) defaults(x) false
523456
Base.@deprecate default_p(x) defaults(x) false
524457
function defaults(sys::AbstractSystem)
@@ -586,6 +519,20 @@ function isaffine(sys::AbstractSystem)
586519
all(isaffine(r, states(sys)) for r in rhs)
587520
end
588521

522+
function time_varying_as_func(x, sys::AbstractTimeDependentSystem)
523+
# if something is not x(t) (the current state)
524+
# but is `x(t-1)` or something like that, pass in `x` as a callable function rather
525+
# than pass in a value in place of x(t).
526+
#
527+
# This is done by just making `x` the argument of the function.
528+
if istree(x) &&
529+
operation(x) isa Sym &&
530+
!(length(arguments(x)) == 1 && isequal(arguments(x)[1], get_iv(sys)))
531+
return operation(x)
532+
end
533+
return x
534+
end
535+
589536
struct AbstractSysToExpr
590537
sys::AbstractSystem
591538
states::Vector

0 commit comments

Comments
 (0)