Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ include("structural_transformation/StructuralTransformations.jl")
include("inputoutput.jl")

include("adjoints.jl")
include("deprecations.jl")

const t_nounits = let
only(@independent_variables t)
Expand All @@ -233,7 +234,7 @@ PrecompileTools.@compile_workload begin
using ModelingToolkit
@variables x(ModelingToolkit.t_nounits)
@named sys = System([ModelingToolkit.D_nounits(x) ~ -x], ModelingToolkit.t_nounits)
prob = ODEProblem(structural_simplify(sys), [x => 30.0], (0, 100), [], jac = true)
prob = ODEProblem(mtkcompile(sys), [x => 30.0], (0, 100), [], jac = true)
@mtkmodel __testmod__ begin
@constants begin
c = 1.0
Expand Down Expand Up @@ -288,7 +289,7 @@ export alias_elimination, flatten
export connect, domain_connect, @connector, Connection, AnalysisPoint, Flow, Stream,
instream
export initial_state, transition, activeState, entry, ticksInState, timeInState
export @component, @mtkmodel, @mtkbuild
export @component, @mtkmodel, @mtkcompile, @mtkbuild
export isinput, isoutput, getbounds, hasbounds, getguess, hasguess, isdisturbance,
istunable, getdist, hasdist,
tunable_parameters, isirreducible, getdescription, hasdescription,
Expand All @@ -304,8 +305,8 @@ export SymScope, LocalScope, ParentScope, GlobalScope
export independent_variable, equations, controls, observed, full_equations, jumps, cost,
brownians
export initialization_equations, guesses, defaults, parameter_dependencies, hierarchy
export structural_simplify, expand_connections, linearize, linearization_function,
LinearizationProblem
export mtkcompile, expand_connections, linearize, linearization_function,
LinearizationProblem, structural_simplify
export solve
export Pre

Expand Down
11 changes: 11 additions & 0 deletions src/deprecations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@deprecate structural_simplify(sys; kwargs...) mtkcompile(sys; kwargs...)
@deprecate structural_simplify(sys, io; kwargs...) mtkcompile(
sys; inputs = io[1], outputs = io[2], kwargs...)

macro mtkbuild(exprs...)
return quote
Base.depwarn("`@mtkbuild` is deprecated. Use `@mtkcompile` instead.", :mtkbuild)
@mtkcompile $(exprs...)
end |> esc
end

4 changes: 2 additions & 2 deletions src/inputoutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function generate_control_function(sys::AbstractSystem, inputs = unbound_inputs(
kwargs...)
# Remove this when the ControlFunction gets merged.
if check_simplified && !iscomplete(sys)
error("A completed `ODESystem` is required. Call `complete` or `structural_simplify` on the system before creating the control function.")
error("A completed `ODESystem` is required. Call `complete` or `mtkcompile` on the system before creating the control function.")
end
isempty(inputs) && @warn("No unbound inputs were found in system.")
if disturbance_inputs !== nothing
Expand Down Expand Up @@ -417,7 +417,7 @@ function add_input_disturbance(sys, dist::DisturbanceModel, inputs = Any[]; kwar
dist.input ~ u + dsys.output.u[1]]
augmented_sys = System(eqs, t, systems = [dsys], name = gensym(:outer))
augmented_sys = extend(augmented_sys, sys)
ssys = structural_simplify(augmented_sys, inputs = all_inputs, disturbance_inputs = [d])
ssys = mtkcompile(augmented_sys, inputs = all_inputs, disturbance_inputs = [d])

f, dvs, p, io_sys = generate_control_function(ssys, all_inputs,
[d]; kwargs...)
Expand Down
6 changes: 3 additions & 3 deletions src/linearization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ y &= h(x, z, u)

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

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

# Arguments:

Expand Down Expand Up @@ -58,7 +58,7 @@ function linearization_function(sys::AbstractSystem, inputs,
outputs = mapreduce(vcat, outputs; init = []) do var
symbolic_type(var) == ArraySymbolic() ? collect(var) : [var]
end
ssys = structural_simplify(sys; inputs, outputs, simplify, kwargs...)
ssys = mtkcompile(sys; inputs, outputs, simplify, kwargs...)
diff_idxs, alge_idxs = eq_idxs(ssys)
if zero_dummy_der
dummyder = setdiff(unknowns(ssys), unknowns(sys))
Expand Down Expand Up @@ -498,7 +498,7 @@ function linearize_symbolic(sys::AbstractSystem, inputs,
outputs; simplify = false, allow_input_derivatives = false,
eval_expression = false, eval_module = @__MODULE__,
kwargs...)
sys = structural_simplify(sys; inputs, outputs, simplify, kwargs...)
sys = mtkcompile(sys; inputs, outputs, simplify, kwargs...)
diff_idxs, alge_idxs = eq_idxs(sys)
sts = unknowns(sys)
t = get_iv(sys)
Expand Down
2 changes: 1 addition & 1 deletion src/problems/bvproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If a `System` without `constraints` is specified, it will be treated as an initi
D(D(y)) ~ λ * y - g
x(t)^2 + y^2 ~ 1]
cstr = [x(0.5) ~ 1]
@mtkbuild pend = System(eqs, t; constraints = cstrs)
@mtkcompile pend = System(eqs, t; constraints = cstrs)

tspan = (0.0, 1.5)
u0map = [x(t) => 0.6, y => 0.8]
Expand Down
4 changes: 2 additions & 2 deletions src/problems/compatibility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function check_has_noise(sys::System, T)
if !isempty(brownians(sys))
msg = """
Systems constructed by defining Brownian variables with `@brownian` must be \
simplified by calling `structural_simplify` before a `$T` can be constructed.
simplified by calling `mtkcompile` before a `$T` can be constructed.
"""
end
throw(SystemCompatibilityError(msg))
Expand All @@ -131,7 +131,7 @@ function check_is_discrete(sys::System, T)
if !is_discrete_system(sys)
throw(SystemCompatibilityError("""
`$T` expects a discrete system. Consider an `ODEProblem` instead. If your system \
is discrete, ensure `structural_simplify` has been run on it.
is discrete, ensure `mtkcompile` has been run on it.
"""))
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/problems/initializationproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ initial conditions for the given DAE.
time_dependent_init = is_time_dependent(sys),
kwargs...) where {iip, specialize}
if !iscomplete(sys)
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `ODEProblem`")
error("A completed system is required. Call `complete` or `mtkcompile` on the system before creating an `ODEProblem`")
end
if isempty(u0map) && get_initializesystem(sys) !== nothing
isys = get_initializesystem(sys; initialization_eqs, check_units)
Expand All @@ -60,7 +60,7 @@ initial conditions for the given DAE.
end

if simplify_system
isys = structural_simplify(isys; fully_determined, split = is_split(sys))
isys = mtkcompile(isys; fully_determined, split = is_split(sys))
end

ts = get_tearing_state(isys)
Expand Down
4 changes: 2 additions & 2 deletions src/problems/sccnonlinearproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ function SciMLBase.SCCNonlinearProblem{iip}(sys::System, u0map,
parammap = SciMLBase.NullParameters(); eval_expression = false, eval_module = @__MODULE__,
cse = true, kwargs...) where {iip}
if !iscomplete(sys) || get_tearing_state(sys) === nothing
error("A simplified `System` is required. Call `structural_simplify` on the system before creating an `SCCNonlinearProblem`.")
error("A simplified `System` is required. Call `mtkcompile` on the system before creating an `SCCNonlinearProblem`.")
end

if !is_split(sys)
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`.")
error("The system has been simplified with `split = false`. `SCCNonlinearProblem` is not compatible with this system. Pass `split = true` to `mtkcompile` to use `SCCNonlinearProblem`.")
end

ts = get_tearing_state(sys)
Expand Down
2 changes: 1 addition & 1 deletion src/structural_transformation/StructuralTransformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import ModelingToolkit: var_derivative!, var_derivative_graph!
using Graphs
using ModelingToolkit: algeqs, EquationsView,
SystemStructure, TransformationState, TearingState,
structural_simplify!,
mtkcompile!,
isdiffvar, isdervar, isalgvar, isdiffeq, algeqs, is_only_discrete,
dervars_range, diffvars_range, algvars_range,
DiffGraph, complete!,
Expand Down
2 changes: 1 addition & 1 deletion src/structural_transformation/pantelides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ end
dae_index_lowering(sys::System; kwargs...) -> System

Perform the Pantelides algorithm to transform a higher index DAE to an index 1
DAE. `kwargs` are forwarded to [`pantelides!`](@ref). End users are encouraged to call [`structural_simplify`](@ref)
DAE. `kwargs` are forwarded to [`pantelides!`](@ref). End users are encouraged to call [`mtkcompile`](@ref)
instead, which calls this function internally.
"""
function dae_index_lowering(sys::System; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ end
tearing(sys; simplify=false)

Tear the nonlinear equations in system. When `simplify=true`, we simplify the
new residual equations after tearing. End users are encouraged to call [`structural_simplify`](@ref)
new residual equations after tearing. End users are encouraged to call [`mtkcompile`](@ref)
instead, which calls this function internally.
"""
function tearing(sys::AbstractSystem, state = TearingState(sys); mm = nothing,
Expand Down
18 changes: 9 additions & 9 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ may be subsetted using `dvs` and `ps`. All `kwargs` are passed to the internal
[`build_function`](@ref) call. The returned function can be called as `f(u, p, t)` or
`f(du, u, p, t)` for time-dependent systems and `f(u, p)` or `f(du, u, p)` for
time-independent systems. If `split=true` (the default) was passed to [`complete`](@ref),
[`structural_simplify`](@ref) or [`@mtkbuild`](@ref), `p` is expected to be an `MTKParameters`
[`mtkcompile`](@ref) or [`@mtkcompile`](@ref), `p` is expected to be an `MTKParameters`
object.
"""
function generate_custom_function(sys::AbstractSystem, exprs, dvs = unknowns(sys),
ps = parameters(sys; initial_parameters = true);
expression = Val{true}, eval_expression = false, eval_module = @__MODULE__,
cachesyms::Tuple = (), kwargs...)
if !iscomplete(sys)
error("A completed system is required. Call `complete` or `structural_simplify` on the system.")
error("A completed system is required. Call `complete` or `mtkcompile` on the system.")
end
p = (reorder_parameters(sys, unwrap.(ps))..., cachesyms...)
isscalar = !(exprs isa AbstractArray)
Expand Down Expand Up @@ -751,7 +751,7 @@ function complete(
newparams = OrderedSet()
iv = has_iv(sys) ? get_iv(sys) : nothing
collect_scoped_vars!(newunknowns, newparams, sys, iv; depth = -1)
# don't update unknowns to not disturb `structural_simplify` order
# don't update unknowns to not disturb `mtkcompile` order
# `GlobalScope`d unknowns will be picked up and added there
@set! sys.ps = unique!(vcat(get_ps(sys), collect(newparams)))

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

Expand Down Expand Up @@ -2470,7 +2470,7 @@ macro component(expr)
esc(component_post_processing(expr, false))
end

macro mtkbuild(exprs...)
macro mtkcompile(exprs...)
expr = exprs[1]
named_expr = ModelingToolkit.named_expr(expr)
name = named_expr.args[1]
Expand All @@ -2484,7 +2484,7 @@ macro mtkbuild(exprs...)
else
kwargs = (Expr(:parameters, kwargs...),)
end
call_expr = Expr(:call, structural_simplify, kwargs..., name)
call_expr = Expr(:call, mtkcompile, kwargs..., name)
esc(quote
$named_expr
$name = $call_expr
Expand Down Expand Up @@ -2523,7 +2523,7 @@ function debug_system(
functions = Set(functions) # more efficient "in" lookup
end
if has_systems(sys) && !isempty(get_systems(sys))
error("debug_system(sys) only works on systems with no sub-systems! Consider flattening it with flatten(sys) or structural_simplify(sys) first.")
error("debug_system(sys) only works on systems with no sub-systems! Consider flattening it with flatten(sys) or mtkcompile(sys) first.")
end
if has_eqs(sys)
eqs = debug_sub.(equations(sys), Ref(functions); kw...)
Expand Down Expand Up @@ -2608,10 +2608,10 @@ end

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

Expand Down
2 changes: 1 addition & 1 deletion src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function make_affect(affect::Vector{Equation}; discrete_parameters = Any[],
@named affectsys = System(
vcat(affect, alg_eqs), iv, collect(union(_dvs, discretes)),
collect(union(pre_params, sys_params)))
affectsys = structural_simplify(affectsys; fully_determined = nothing)
affectsys = mtkcompile(affectsys; fully_determined = nothing)
# get accessed parameters p from Pre(p) in the callback parameters
accessed_params = filter(isparameter, map(unPre, collect(pre_params)))
union!(accessed_params, sys_params)
Expand Down
6 changes: 3 additions & 3 deletions src/systems/diffeqs/basic_transformations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Any extra equations `eqs` involving the new and old independent variables will b
# Usage before structural simplification

The variable change must take place before structural simplification.
In following calls to `structural_simplify`, consider passing `allow_symbolic = true` to avoid undesired constraint equations between between dummy variables.
In following calls to `mtkcompile`, consider passing `allow_symbolic = true` to avoid undesired constraint equations between between dummy variables.

# Usage with non-autonomous systems

Expand All @@ -99,7 +99,7 @@ julia> @named M = System([D(D(y)) ~ -9.81, D(D(x)) ~ 0.0], t);

julia> M = change_independent_variable(M, x);

julia> M = structural_simplify(M; allow_symbolic = true);
julia> M = mtkcompile(M; allow_symbolic = true);

julia> unknowns(M)
3-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
Expand Down Expand Up @@ -248,7 +248,7 @@ function stochastic_integral_transform(sys::System, correction_factor)
throw(ArgumentError("""
`$stochastic_integral_transform` expects a system with noise_eqs. If your \
noise is specified using brownian variables, consider calling \
`structural_simplify`.
`mtkcompile`.
"""))
end
name = nameof(sys)
Expand Down
4 changes: 2 additions & 2 deletions src/systems/index_cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,10 @@ See also: [`MTKParameters`](@ref), [`tunable_parameters`](@ref), [`reorder_dimen
function reorder_dimension_by_tunables!(
dest::AbstractArray, sys::AbstractSystem, arr::AbstractArray, syms; dim = 1)
if !iscomplete(sys)
throw(ArgumentError("A completed system is required. Call `complete` or `structural_simplify` on the system."))
throw(ArgumentError("A completed system is required. Call `complete` or `mtkcompile` on the system."))
end
if !has_index_cache(sys) || (ic = get_index_cache(sys)) === nothing
throw(ArgumentError("The system does not have an index cache. Call `complete` or `structural_simplify` on the system with `split = true`."))
throw(ArgumentError("The system does not have an index cache. Call `complete` or `mtkcompile` on the system with `split = true`."))
end
if size(dest) != size(arr)
throw(ArgumentError("Source and destination arrays must have the same size. Got source array with size $(size(arr)) and destination with size $(size(dest))."))
Expand Down
4 changes: 2 additions & 2 deletions src/systems/nonlinear/homotopy_continuation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ function SciMLBase.HomotopyNonlinearFunction{iip, specialize}(
p = nothing, fraction_cancel_fn = SymbolicUtils.simplify_fractions, cse = true,
kwargs...) where {iip, specialize}
if !iscomplete(sys)
error("A completed `System` is required. Call `complete` or `structural_simplify` on the system before creating a `HomotopyContinuationFunction`")
error("A completed `System` is required. Call `complete` or `mtkcompile` on the system before creating a `HomotopyContinuationFunction`")
end
transformation = PolynomialTransformation(sys)
if transformation isa NotPolynomialError
Expand Down Expand Up @@ -552,7 +552,7 @@ function HomotopyContinuationProblem{iip, spec}(
sys::System, u0map, pmap = SciMLBase.NullParameters();
kwargs...) where {iip, spec}
if !iscomplete(sys)
error("A completed `System` is required. Call `complete` or `structural_simplify` on the system before creating a `HomotopyContinuationProblem`")
error("A completed `System` is required. Call `complete` or `mtkcompile` on the system before creating a `HomotopyContinuationProblem`")
end
f, u0, p = process_SciMLProblem(
HomotopyNonlinearFunction{iip, spec}, sys, u0map, pmap; kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/systems/parameter_buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependent systems. It is only required if the symbolic expressions also use the
variable of the system.

This requires that `complete` has been called on the system (usually via
`structural_simplify` or `@mtkbuild`) and the keyword `split = true` was passed (which is
`mtkcompile` or `@mtkcompile`) and the keyword `split = true` was passed (which is
the default behavior).
"""
function MTKParameters(
Expand Down
2 changes: 1 addition & 1 deletion src/systems/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ end

function Base.showerror(io::IO, err::SystemNotCompleteError)
print(io, """
A completed system is required. Call `complete` or `structural_simplify` on the \
A completed system is required. Call `complete` or `mtkcompile` on the \
system before creating a `$(err.obj)`.
""")
end
Expand Down
Loading
Loading