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
2 changes: 1 addition & 1 deletion ext/MTKFMIExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ function (wrapper::Union{FMI2InstanceWrapper, FMI3InstanceWrapper})(
y = outputs_buffer, y_refs = wrapper.output_value_references
)
wrapper.res_buffer[1:length(states_buffer)] .= states_buffer
wrapper.res_buffer[length(states_buffer)+1:end] .= outputs_buffer
wrapper.res_buffer[(length(states_buffer) + 1):end] .= outputs_buffer
return wrapper.res_buffer
end

Expand Down
11 changes: 8 additions & 3 deletions ext/MTKOrdinaryDiffEqBDFExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ using ModelingToolkit: t_nounits, D_nounits
@parameters a = 1.0 b = 1.0
@variables x(t_nounits) y(t_nounits)
prob = ODEProblem(
mtkcompile(System([D_nounits(x) ~ a * y, D_nounits(y) ~ -b * x],
t_nounits; name = :precompile_bdf)),
[x => 1.0, y => 0.0], (0.0, 1.0))
mtkcompile(
System(
[D_nounits(x) ~ a * y, D_nounits(y) ~ -b * x],
t_nounits; name = :precompile_bdf
)
),
[x => 1.0, y => 0.0], (0.0, 1.0)
)
@compile_workload begin
solve(prob, FBDF())
end
Expand Down
11 changes: 8 additions & 3 deletions ext/MTKOrdinaryDiffEqDefaultExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ using ModelingToolkit: t_nounits, D_nounits
@parameters a = 1.0 b = 1.0
@variables x(t_nounits) y(t_nounits)
prob = ODEProblem(
mtkcompile(System([D_nounits(x) ~ a * y, D_nounits(y) ~ -b * x],
t_nounits; name = :precompile_default)),
[x => 1.0, y => 0.0], (0.0, 1.0))
mtkcompile(
System(
[D_nounits(x) ~ a * y, D_nounits(y) ~ -b * x],
t_nounits; name = :precompile_default
)
),
[x => 1.0, y => 0.0], (0.0, 1.0)
)
@compile_workload begin
solve(prob)
end
Expand Down
11 changes: 8 additions & 3 deletions ext/MTKOrdinaryDiffEqRosenbrockExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ using ModelingToolkit: t_nounits, D_nounits
@parameters a = 1.0 b = 1.0
@variables x(t_nounits) y(t_nounits)
prob = ODEProblem(
mtkcompile(System([D_nounits(x) ~ a * y, D_nounits(y) ~ -b * x],
t_nounits; name = :precompile_rosenbrock)),
[x => 1.0, y => 0.0], (0.0, 1.0))
mtkcompile(
System(
[D_nounits(x) ~ a * y, D_nounits(y) ~ -b * x],
t_nounits; name = :precompile_rosenbrock
)
),
[x => 1.0, y => 0.0], (0.0, 1.0)
)
@compile_workload begin
solve(prob, Rodas5P())
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ModelingToolkitBase/ext/MTKCasADiDynamicOptExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function MTK.set_variable_bounds!(m::CasADiModel, sys, pmap, tf, tunable_params,
subject_to!(m.model, m.P[i] >= lo)
subject_to!(m.model, m.P[i] <= hi)
end
if !isnothing(tf_bounds)
return if !isnothing(tf_bounds)
subject_to!(m.model, m.tₛ >= tf_bounds[1])
subject_to!(m.model, m.tₛ <= tf_bounds[2])
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ModelingToolkitBase/ext/MTKInfiniteOptExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function MTK.set_variable_bounds!(m::InfiniteOptModel, sys, pmap, tf, tunable_pa
set_lower_bound(m.P[i], lo)
set_upper_bound(m.P[i], hi)
end
if !isnothing(tf_bounds)
return if !isnothing(tf_bounds)
set_lower_bound(m.tₛ, tf_bounds[1])
set_upper_bound(m.tₛ, tf_bounds[2])
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ModelingToolkitBase/ext/MTKPyomoDynamicOptExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function MTK.set_variable_bounds!(m::PyomoDynamicOptModel, sys, pmap, tf, tunabl
MTK.add_constraint!(m, p_var ≳ lo)
MTK.add_constraint!(m, p_var ≲ hi)
end
if !isnothing(tf_bounds)
return if !isnothing(tf_bounds)
tₛ_sym = pysym_getproperty(m.model_sym, :tₛ)
MTK.add_constraint!(m, tₛ_sym ≳ tf_bounds[1])
MTK.add_constraint!(m, tₛ_sym ≲ tf_bounds[2])
Expand Down
4 changes: 2 additions & 2 deletions lib/ModelingToolkitBase/ext/MTKTrackerExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function MTKBase.promote_type_with_nothing(::Type{Tracker.TrackedReal{T}}, x::Tr
end

function MTKBase.promote_with_nothing(::Type{Tracker.TrackedReal{T}}, x::Tracker.TrackedArray{T}) where {T}
return x
return x
end

function MTKBase.__iip_u0_ad_wrapper(u0::Tracker.TrackedVector)
convert(Vector{eltype(u0)}, u0)
return convert(Vector{eltype(u0)}, u0)
end

end
2 changes: 1 addition & 1 deletion lib/ModelingToolkitBase/src/ModelingToolkitBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ $(DocStringExtensions.README)
module ModelingToolkitBase

if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_methods"))
@eval Base.Experimental.@compiler_options max_methods=1
@eval Base.Experimental.@compiler_options max_methods = 1
end

using PrecompileTools, Reexport
Expand Down
1 change: 0 additions & 1 deletion lib/ModelingToolkitBase/src/derivative_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,3 @@ for T in [:DerivativeDict, :ExpandDerivativeDict]

end
end

9 changes: 6 additions & 3 deletions lib/ModelingToolkitBase/src/problems/jumpproblem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
check_complete(sys, JumpProblem)
check_compatibility && check_compatible_system(JumpProblem, sys)
if haskey(kwargs, :tstops)
throw(ArgumentError(
"Passing `tstops` directly to `JumpProblem(::System, ...)` is not supported. " *
"Define tstops on the `System` via the `tstops` keyword instead."))
throw(
ArgumentError(
"Passing `tstops` directly to `JumpProblem(::System, ...)` is not supported. " *
"Define tstops on the `System` via the `tstops` keyword instead."
)
)
end

has_vrjs = any(x -> x isa VariableRateJump, jumps(sys))
Expand Down
6 changes: 3 additions & 3 deletions lib/ModelingToolkitBase/src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ Returns true if the parameter `p` is of the form `Initial(x)`.
"""
function isinitial(p::SymbolicT)
p, _ = split_indexed_var(p)
Moshi.Match.@match p begin
return Moshi.Match.@match p begin
BSImpl.Term(; f) => f isa Initial
_ => false
end
Expand Down Expand Up @@ -2975,7 +2975,7 @@ sys = mtkcompile(sys)
```
"""
macro mtkcompile(exprs...)
_named_and_call(mtkcompile, exprs)
return _named_and_call(mtkcompile, exprs)
end

"""
Expand All @@ -2995,7 +2995,7 @@ sys = complete(sys)
```
"""
macro mtkcomplete(exprs...)
_named_and_call(complete, exprs)
return _named_and_call(complete, exprs)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion lib/ModelingToolkitBase/src/systems/analysis_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ function apply_transformation(tf::Break, sys::AbstractSystem)
if tf.outputs_to_params
namespace = namespace_hierarchy(getname(out_var))
insert!(namespace, 1, nameof(breaksys))
breaksys, _ = modify_nested_subsystem(breaksys, @view(namespace[1:end-1])) do apsys
breaksys, _ = modify_nested_subsystem(breaksys, @view(namespace[1:(end - 1)])) do apsys
new_dvs = copy(get_unknowns(apsys))
var_in_apsys = getvar(apsys, namespace[end]; namespace = false)
deleteat!(new_dvs, findfirst(isequal(var_in_apsys), new_dvs)::Int)
Expand Down
22 changes: 11 additions & 11 deletions lib/ModelingToolkitBase/src/systems/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1125,10 +1125,10 @@ function generate_callback(cbs::Vector{SymbolicContinuousCallback}, sys; kwargs.
eqs = reduce(vcat, eqs)

@static if pkgversion(SciMLBase) < v"3"
affect = VectorAffect(eq2affect, compiled.affects)
affect = VectorAffect(eq2affect, compiled.affects)
affect_neg = VectorAffect(eq2affect, compiled.affect_negs)
initialize = wrap_vector_optional_affect(compiled.inits, SciMLBase.INITIALIZE_DEFAULT)
finalize = wrap_vector_optional_affect(compiled.finals, SciMLBase.FINALIZE_DEFAULT)
finalize = wrap_vector_optional_affect(compiled.finals, SciMLBase.FINALIZE_DEFAULT)

return VectorContinuousCallback(
trigger, affect, affect_neg, length(eqs); initialize, finalize,
Expand All @@ -1137,9 +1137,9 @@ function generate_callback(cbs::Vector{SymbolicContinuousCallback}, sys; kwargs.
initialize_save_discretes = cbs[1].initialize_save_discretes
)
else
affect = VectorAffect(eq2affect, compiled.affects, compiled.affect_negs)
affect = VectorAffect(eq2affect, compiled.affects, compiled.affect_negs)
initialize = wrap_vector_optional_affect(compiled.inits, SciMLBase.INITIALIZE_DEFAULT)
finalize = wrap_vector_optional_affect(compiled.finals, SciMLBase.FINALIZE_DEFAULT)
finalize = wrap_vector_optional_affect(compiled.finals, SciMLBase.FINALIZE_DEFAULT)

return VectorContinuousCallback(
trigger, affect, length(eqs); initialize, finalize,
Expand Down Expand Up @@ -1234,7 +1234,7 @@ function generate_callback(cb, sys; tspan = nothing, kwargs...)
)

initialize = isnothing(cb.initialize) ? init : InitFinalizeWrapper(init)
finalize = isnothing(cb.finalize) ? final : InitFinalizeWrapper(final)
finalize = isnothing(cb.finalize) ? final : InitFinalizeWrapper(final)

saved_clock_partitions = if is_split(sys)
get(get_index_cache(sys).callback_to_clocks, cb, ())
Expand Down Expand Up @@ -1493,14 +1493,14 @@ Base.@nospecializeinfer function compile_implicit_affect(
dvs_to_access = unknowns(affsys)
ps_to_access = [unPre(p) for p in parameters(affsys)]

affu_getter = getsym(sys, dvs_to_access)
affp_getter = getsym(sys, ps_to_access)
affu_getter = getsym(sys, dvs_to_access)
affp_getter = getsym(sys, ps_to_access)
affu_setter! = setsym(affsys, unknowns(affsys))
affp_setter! = setsym(affsys, parameters(affsys))
u_setter! = setsym(sys, dvs_to_update)
p_setter! = setsym(sys, ps_to_update)
u_getter = getsym(affsys, dvs_to_update)
p_getter = getsym(affsys, ps_to_update)
u_setter! = setsym(sys, dvs_to_update)
p_setter! = setsym(sys, ps_to_update)
u_getter = getsym(affsys, dvs_to_update)
p_getter = getsym(affsys, ps_to_update)

affprob = ImplicitDiscreteProblem(
affsys, op, (0, 0);
Expand Down
12 changes: 7 additions & 5 deletions lib/ModelingToolkitBase/src/systems/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function generate_jacobian(
end

function assert_jac_length(arr::SparseMatrixCSC, I::Vector{<:Integer}, J::Vector{<:Integer})
@assert findnz(arr)[1:2] == (I, J)
return @assert findnz(arr)[1:2] == (I, J)
end

function assert_jac_length_header(sys)
Expand Down Expand Up @@ -1103,8 +1103,10 @@ end
function assemble_maj(majv::Vector{U}, unknowntoid, pmapper) where {U <: MassActionJump}
rs = [numericrstoich(maj.reactant_stoch, unknowntoid) for maj in majv]
ns = [numericnstoich(maj.net_stoch, unknowntoid) for maj in majv]
return MassActionJump(rs, ns; param_mapper = pmapper, nocopy = true,
scale_rates = false, rescale_rates_on_update = false)
return MassActionJump(
rs, ns; param_mapper = pmapper, nocopy = true,
scale_rates = false, rescale_rates_on_update = false
)
end

function numericrstoich(mtrs::Vector{Pair{V, W}}, unknowntoid) where {V, W}
Expand Down Expand Up @@ -1389,8 +1391,8 @@ Base.@nospecializeinfer function build_explicit_observed_function(
p_start + wrap_delays, length(args) - length(rps) + 1 + wrap_delays, is_split(sys),
),
}(
oop, iip
)
oop, iip
)
return (return_inplace isa Val{true} || return_inplace isa Bool && return_inplace) ? (f, f) : f
end

Expand Down
Loading
Loading