Skip to content

Commit a049d76

Browse files
Merge pull request #3656 from AayushSabharwal/as/mtkcompile
refactor: rename `@mtkbuild` to `@mtkcompile` and `structural_simplify` to `mtkcompile`
2 parents dd80bd3 + a45fef8 commit a049d76

File tree

79 files changed

+602
-583
lines changed

Some content is hidden

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

79 files changed

+602
-583
lines changed

src/ModelingToolkit.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ include("structural_transformation/StructuralTransformations.jl")
214214
include("inputoutput.jl")
215215

216216
include("adjoints.jl")
217+
include("deprecations.jl")
217218

218219
const t_nounits = let
219220
only(@independent_variables t)
@@ -233,7 +234,7 @@ PrecompileTools.@compile_workload begin
233234
using ModelingToolkit
234235
@variables x(ModelingToolkit.t_nounits)
235236
@named sys = System([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits)
236-
prob = ODEProblem(structural_simplify(sys), [x => 30.0], (0, 100), [], jac = true)
237+
prob = ODEProblem(mtkcompile(sys), [x => 30.0], (0, 100), [], jac = true)
237238
@mtkmodel __testmod__ begin
238239
@constants begin
239240
c = 1.0
@@ -288,7 +289,7 @@ export alias_elimination, flatten
288289
export connect, domain_connect, @connector, Connection, AnalysisPoint, Flow, Stream,
289290
instream
290291
export initial_state, transition, activeState, entry, ticksInState, timeInState
291-
export @component, @mtkmodel, @mtkbuild
292+
export @component, @mtkmodel, @mtkcompile, @mtkbuild
292293
export isinput, isoutput, getbounds, hasbounds, getguess, hasguess, isdisturbance,
293294
istunable, getdist, hasdist,
294295
tunable_parameters, isirreducible, getdescription, hasdescription,
@@ -304,8 +305,8 @@ export SymScope, LocalScope, ParentScope, GlobalScope
304305
export independent_variable, equations, controls, observed, full_equations, jumps, cost,
305306
brownians
306307
export initialization_equations, guesses, defaults, parameter_dependencies, hierarchy
307-
export structural_simplify, expand_connections, linearize, linearization_function,
308-
LinearizationProblem
308+
export mtkcompile, expand_connections, linearize, linearization_function,
309+
LinearizationProblem, structural_simplify
309310
export solve
310311
export Pre
311312

src/deprecations.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@deprecate structural_simplify(sys; kwargs...) mtkcompile(sys; kwargs...)
2+
@deprecate structural_simplify(sys, io; kwargs...) mtkcompile(
3+
sys; inputs = io[1], outputs = io[2], kwargs...)
4+
5+
macro mtkbuild(exprs...)
6+
return quote
7+
Base.depwarn("`@mtkbuild` is deprecated. Use `@mtkcompile` instead.", :mtkbuild)
8+
@mtkcompile $(exprs...)
9+
end |> esc
10+
end
11+

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/bvproblem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ If a `System` without `constraints` is specified, it will be treated as an initi
3030
D(D(y)) ~ λ * y - g
3131
x(t)^2 + y^2 ~ 1]
3232
cstr = [x(0.5) ~ 1]
33-
@mtkbuild pend = System(eqs, t; constraints = cstrs)
33+
@mtkcompile pend = System(eqs, t; constraints = cstrs)
3434
3535
tspan = (0.0, 1.5)
3636
u0map = [x(t) => 0.6, y => 0.8]

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...)

0 commit comments

Comments
 (0)