Skip to content

Commit 52d3ab8

Browse files
refactor: rename structural_simplify to mtkcompile
1 parent 15782f2 commit 52d3ab8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+293
-293
lines changed

src/ModelingToolkit.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ PrecompileTools.@compile_workload begin
233233
using ModelingToolkit
234234
@variables x(ModelingToolkit.t_nounits)
235235
@named sys = System([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits)
236-
prob = ODEProblem(structural_simplify(sys), [x => 30.0], (0, 100), [], jac = true)
236+
prob = ODEProblem(mtkcompile(sys), [x => 30.0], (0, 100), [], jac = true)
237237
@mtkmodel __testmod__ begin
238238
@constants begin
239239
c = 1.0
@@ -304,7 +304,7 @@ export SymScope, LocalScope, ParentScope, GlobalScope
304304
export independent_variable, equations, controls, observed, full_equations, jumps, cost,
305305
brownians
306306
export initialization_equations, guesses, defaults, parameter_dependencies, hierarchy
307-
export structural_simplify, expand_connections, linearize, linearization_function,
307+
export mtkcompile, expand_connections, linearize, linearization_function,
308308
LinearizationProblem
309309
export solve
310310
export Pre

src/inputoutput.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function generate_control_function(sys::AbstractSystem, inputs = unbound_inputs(
202202
kwargs...)
203203
# Remove this when the ControlFunction gets merged.
204204
if check_simplified && !iscomplete(sys)
205-
error("A completed `ODESystem` is required. Call `complete` or `structural_simplify` on the system before creating the control function.")
205+
error("A completed `ODESystem` is required. Call `complete` or `mtkcompile` on the system before creating the control function.")
206206
end
207207
isempty(inputs) && @warn("No unbound inputs were found in system.")
208208
if disturbance_inputs !== nothing
@@ -417,7 +417,7 @@ function add_input_disturbance(sys, dist::DisturbanceModel, inputs = Any[]; kwar
417417
dist.input ~ u + dsys.output.u[1]]
418418
augmented_sys = System(eqs, t, systems = [dsys], name = gensym(:outer))
419419
augmented_sys = extend(augmented_sys, sys)
420-
ssys = structural_simplify(augmented_sys, inputs = all_inputs, disturbance_inputs = [d])
420+
ssys = mtkcompile(augmented_sys, inputs = all_inputs, disturbance_inputs = [d])
421421

422422
f, dvs, p, io_sys = generate_control_function(ssys, all_inputs,
423423
[d]; kwargs...)

src/linearization.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ y &= h(x, z, u)
1515
1616
where `x` are differential unknown variables, `z` algebraic variables, `u` inputs and `y` outputs. To obtain a linear statespace representation, see [`linearize`](@ref). The input argument `variables` is a vector defining the operating point, corresponding to `unknowns(simplified_sys)` and `p` is a vector corresponding to the parameters of `simplified_sys`. Note: all variables in `inputs` have been converted to parameters in `simplified_sys`.
1717
18-
The `simplified_sys` has undergone [`structural_simplify`](@ref) and had any occurring input or output variables replaced with the variables provided in arguments `inputs` and `outputs`. The unknowns of this system also indicate the order of the unknowns that holds for the linearized matrices.
18+
The `simplified_sys` has undergone [`mtkcompile`](@ref) and had any occurring input or output variables replaced with the variables provided in arguments `inputs` and `outputs`. The unknowns of this system also indicate the order of the unknowns that holds for the linearized matrices.
1919
2020
# Arguments:
2121
@@ -58,7 +58,7 @@ function linearization_function(sys::AbstractSystem, inputs,
5858
outputs = mapreduce(vcat, outputs; init = []) do var
5959
symbolic_type(var) == ArraySymbolic() ? collect(var) : [var]
6060
end
61-
ssys = structural_simplify(sys; inputs, outputs, simplify, kwargs...)
61+
ssys = mtkcompile(sys; inputs, outputs, simplify, kwargs...)
6262
diff_idxs, alge_idxs = eq_idxs(ssys)
6363
if zero_dummy_der
6464
dummyder = setdiff(unknowns(ssys), unknowns(sys))
@@ -498,7 +498,7 @@ function linearize_symbolic(sys::AbstractSystem, inputs,
498498
outputs; simplify = false, allow_input_derivatives = false,
499499
eval_expression = false, eval_module = @__MODULE__,
500500
kwargs...)
501-
sys = structural_simplify(sys; inputs, outputs, simplify, kwargs...)
501+
sys = mtkcompile(sys; inputs, outputs, simplify, kwargs...)
502502
diff_idxs, alge_idxs = eq_idxs(sys)
503503
sts = unknowns(sys)
504504
t = get_iv(sys)

src/problems/compatibility.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function check_has_noise(sys::System, T)
120120
if !isempty(brownians(sys))
121121
msg = """
122122
Systems constructed by defining Brownian variables with `@brownian` must be \
123-
simplified by calling `structural_simplify` before a `$T` can be constructed.
123+
simplified by calling `mtkcompile` before a `$T` can be constructed.
124124
"""
125125
end
126126
throw(SystemCompatibilityError(msg))
@@ -131,7 +131,7 @@ function check_is_discrete(sys::System, T)
131131
if !is_discrete_system(sys)
132132
throw(SystemCompatibilityError("""
133133
`$T` expects a discrete system. Consider an `ODEProblem` instead. If your system \
134-
is discrete, ensure `structural_simplify` has been run on it.
134+
is discrete, ensure `mtkcompile` has been run on it.
135135
"""))
136136
end
137137
end

src/problems/initializationproblem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ initial conditions for the given DAE.
3535
time_dependent_init = is_time_dependent(sys),
3636
kwargs...) where {iip, specialize}
3737
if !iscomplete(sys)
38-
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `ODEProblem`")
38+
error("A completed system is required. Call `complete` or `mtkcompile` on the system before creating an `ODEProblem`")
3939
end
4040
if isempty(u0map) && get_initializesystem(sys) !== nothing
4141
isys = get_initializesystem(sys; initialization_eqs, check_units)
@@ -60,7 +60,7 @@ initial conditions for the given DAE.
6060
end
6161

6262
if simplify_system
63-
isys = structural_simplify(isys; fully_determined, split = is_split(sys))
63+
isys = mtkcompile(isys; fully_determined, split = is_split(sys))
6464
end
6565

6666
ts = get_tearing_state(isys)

src/problems/sccnonlinearproblem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::System, u0map,
7373
parammap = SciMLBase.NullParameters(); eval_expression = false, eval_module = @__MODULE__,
7474
cse = true, kwargs...) where {iip}
7575
if !iscomplete(sys) || get_tearing_state(sys) === nothing
76-
error("A simplified `System` is required. Call `structural_simplify` on the system before creating an `SCCNonlinearProblem`.")
76+
error("A simplified `System` is required. Call `mtkcompile` on the system before creating an `SCCNonlinearProblem`.")
7777
end
7878

7979
if !is_split(sys)
80-
error("The system has been simplified with `split = false`. `SCCNonlinearProblem` is not compatible with this system. Pass `split = true` to `structural_simplify` to use `SCCNonlinearProblem`.")
80+
error("The system has been simplified with `split = false`. `SCCNonlinearProblem` is not compatible with this system. Pass `split = true` to `mtkcompile` to use `SCCNonlinearProblem`.")
8181
end
8282

8383
ts = get_tearing_state(sys)

src/structural_transformation/StructuralTransformations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import ModelingToolkit: var_derivative!, var_derivative_graph!
3535
using Graphs
3636
using ModelingToolkit: algeqs, EquationsView,
3737
SystemStructure, TransformationState, TearingState,
38-
structural_simplify!,
38+
mtkcompile!,
3939
isdiffvar, isdervar, isalgvar, isdiffeq, algeqs, is_only_discrete,
4040
dervars_range, diffvars_range, algvars_range,
4141
DiffGraph, complete!,

src/structural_transformation/pantelides.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ end
210210
dae_index_lowering(sys::System; kwargs...) -> System
211211
212212
Perform the Pantelides algorithm to transform a higher index DAE to an index 1
213-
DAE. `kwargs` are forwarded to [`pantelides!`](@ref). End users are encouraged to call [`structural_simplify`](@ref)
213+
DAE. `kwargs` are forwarded to [`pantelides!`](@ref). End users are encouraged to call [`mtkcompile`](@ref)
214214
instead, which calls this function internally.
215215
"""
216216
function dae_index_lowering(sys::System; kwargs...)

src/structural_transformation/symbolics_tearing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ end
989989
tearing(sys; simplify=false)
990990
991991
Tear the nonlinear equations in system. When `simplify=true`, we simplify the
992-
new residual equations after tearing. End users are encouraged to call [`structural_simplify`](@ref)
992+
new residual equations after tearing. End users are encouraged to call [`mtkcompile`](@ref)
993993
instead, which calls this function internally.
994994
"""
995995
function tearing(sys::AbstractSystem, state = TearingState(sys); mm = nothing,

src/systems/abstractsystem.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ may be subsetted using `dvs` and `ps`. All `kwargs` are passed to the internal
146146
[`build_function`](@ref) call. The returned function can be called as `f(u, p, t)` or
147147
`f(du, u, p, t)` for time-dependent systems and `f(u, p)` or `f(du, u, p)` for
148148
time-independent systems. If `split=true` (the default) was passed to [`complete`](@ref),
149-
[`structural_simplify`](@ref) or [`@mtkcompile`](@ref), `p` is expected to be an `MTKParameters`
149+
[`mtkcompile`](@ref) or [`@mtkcompile`](@ref), `p` is expected to be an `MTKParameters`
150150
object.
151151
"""
152152
function generate_custom_function(sys::AbstractSystem, exprs, dvs = unknowns(sys),
153153
ps = parameters(sys; initial_parameters = true);
154154
expression = Val{true}, eval_expression = false, eval_module = @__MODULE__,
155155
cachesyms::Tuple = (), kwargs...)
156156
if !iscomplete(sys)
157-
error("A completed system is required. Call `complete` or `structural_simplify` on the system.")
157+
error("A completed system is required. Call `complete` or `mtkcompile` on the system.")
158158
end
159159
p = (reorder_parameters(sys, unwrap.(ps))..., cachesyms...)
160160
isscalar = !(exprs isa AbstractArray)
@@ -751,7 +751,7 @@ function complete(
751751
newparams = OrderedSet()
752752
iv = has_iv(sys) ? get_iv(sys) : nothing
753753
collect_scoped_vars!(newunknowns, newparams, sys, iv; depth = -1)
754-
# don't update unknowns to not disturb `structural_simplify` order
754+
# don't update unknowns to not disturb `mtkcompile` order
755755
# `GlobalScope`d unknowns will be picked up and added there
756756
@set! sys.ps = unique!(vcat(get_ps(sys), collect(newparams)))
757757

@@ -1178,7 +1178,7 @@ end
11781178
Denotes that a variable belongs to the root system in the hierarchy, regardless of which
11791179
equations of subsystems in the hierarchy it is involved in. Variables with this scope
11801180
are never namespaced and only added to the unknowns/parameters of a system when calling
1181-
`complete` or `structural_simplify`.
1181+
`complete` or `mtkcompile`.
11821182
"""
11831183
struct GlobalScope <: SymScope end
11841184

@@ -2484,7 +2484,7 @@ macro mtkcompile(exprs...)
24842484
else
24852485
kwargs = (Expr(:parameters, kwargs...),)
24862486
end
2487-
call_expr = Expr(:call, structural_simplify, kwargs..., name)
2487+
call_expr = Expr(:call, mtkcompile, kwargs..., name)
24882488
esc(quote
24892489
$named_expr
24902490
$name = $call_expr
@@ -2523,7 +2523,7 @@ function debug_system(
25232523
functions = Set(functions) # more efficient "in" lookup
25242524
end
25252525
if has_systems(sys) && !isempty(get_systems(sys))
2526-
error("debug_system(sys) only works on systems with no sub-systems! Consider flattening it with flatten(sys) or structural_simplify(sys) first.")
2526+
error("debug_system(sys) only works on systems with no sub-systems! Consider flattening it with flatten(sys) or mtkcompile(sys) first.")
25272527
end
25282528
if has_eqs(sys)
25292529
eqs = debug_sub.(equations(sys), Ref(functions); kw...)
@@ -2608,10 +2608,10 @@ end
26082608

26092609
function check_array_equations_unknowns(eqs, dvs)
26102610
if any(eq -> eq isa Equation && Symbolics.isarraysymbolic(eq.lhs), eqs)
2611-
throw(ArgumentError("The system has array equations. Call `structural_simplify` to handle such equations or scalarize them manually."))
2611+
throw(ArgumentError("The system has array equations. Call `mtkcompile` to handle such equations or scalarize them manually."))
26122612
end
26132613
if any(x -> Symbolics.isarraysymbolic(x), dvs)
2614-
throw(ArgumentError("The system has array unknowns. Call `structural_simplify` to handle this or scalarize them manually."))
2614+
throw(ArgumentError("The system has array unknowns. Call `mtkcompile` to handle this or scalarize them manually."))
26152615
end
26162616
end
26172617

0 commit comments

Comments
 (0)