diff --git a/src/systems/abstractsystem.jl b/src/systems/abstractsystem.jl index 7ab80b8e92..dec4650b83 100644 --- a/src/systems/abstractsystem.jl +++ b/src/systems/abstractsystem.jl @@ -1280,7 +1280,8 @@ end function is_array_of_symbolics(x) symbolic_type(x) == ArraySymbolic() && return true symbolic_type(x) == ScalarSymbolic() && return false - x isa AbstractArray && any(y -> symbolic_type(y) != NotSymbolic() || is_array_of_symbolics(y), x) + x isa AbstractArray && + any(y -> symbolic_type(y) != NotSymbolic() || is_array_of_symbolics(y), x) end function namespace_expr( diff --git a/src/systems/diffeqs/abstractodesystem.jl b/src/systems/diffeqs/abstractodesystem.jl index 0b25808485..f690d5749b 100644 --- a/src/systems/diffeqs/abstractodesystem.jl +++ b/src/systems/diffeqs/abstractodesystem.jl @@ -854,13 +854,15 @@ function process_DEProblem(constructor, sys::AbstractODESystem, u0map, parammap; end end defs = defaults(sys) - guesses = merge(ModelingToolkit.guesses(sys), isempty(guesses) ? Dict() : todict(guesses)) + guesses = merge( + ModelingToolkit.guesses(sys), isempty(guesses) ? Dict() : todict(guesses)) solvablepars = [p - for p in parameters(sys) - if is_parameter_solvable(p, parammap, defs, guesses)] + for p in parameters(sys) + if is_parameter_solvable(p, parammap, defs, guesses)] # ModelingToolkit.get_tearing_state(sys) !== nothing => Requires structural_simplify first if sys isa ODESystem && build_initializeprob && - (((implicit_dae || !isempty(missingvars) || !isempty(solvablepars) || !isempty(setobserved)) && + (((implicit_dae || !isempty(missingvars) || !isempty(solvablepars) || + !isempty(setobserved)) && ModelingToolkit.get_tearing_state(sys) !== nothing) || !isempty(initialization_equations(sys))) && t !== nothing if eltype(u0map) <: Number diff --git a/src/systems/diffeqs/odesystem.jl b/src/systems/diffeqs/odesystem.jl index a4fa52fa13..ca0f6c8058 100644 --- a/src/systems/diffeqs/odesystem.jl +++ b/src/systems/diffeqs/odesystem.jl @@ -237,7 +237,7 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps; "`default_u0` and `default_p` are deprecated. Use `defaults` instead.", :ODESystem, force = true) end - defaults = Dict{Any,Any}(todict(defaults)) + defaults = Dict{Any, Any}(todict(defaults)) var_to_name = Dict() process_variables!(var_to_name, defaults, dvs′) process_variables!(var_to_name, defaults, ps′) diff --git a/src/systems/model_parsing.jl b/src/systems/model_parsing.jl index 9232bcec6e..08fc71657f 100644 --- a/src/systems/model_parsing.jl +++ b/src/systems/model_parsing.jl @@ -157,9 +157,11 @@ function update_kwargs_and_metadata!(dict, kwargs, a, def, indices, type, var, if !isnothing(meta) && haskey(meta, VariableUnit) uvar = gensym() push!(where_types, uvar) - push!(kwargs, Expr(:kw, :($a::Union{Nothing, Missing, $NoValue, $uvar}), NO_VALUE)) + push!(kwargs, + Expr(:kw, :($a::Union{Nothing, Missing, $NoValue, $uvar}), NO_VALUE)) else - push!(kwargs, Expr(:kw, :($a::Union{Nothing, Missing, $NoValue, $type}), NO_VALUE)) + push!(kwargs, + Expr(:kw, :($a::Union{Nothing, Missing, $NoValue, $type}), NO_VALUE)) end dict[:kwargs][getname(var)] = Dict(:value => def, :type => type) else diff --git a/src/systems/nonlinear/initializesystem.jl b/src/systems/nonlinear/initializesystem.jl index 798ddff30b..dfeb5e79fb 100644 --- a/src/systems/nonlinear/initializesystem.jl +++ b/src/systems/nonlinear/initializesystem.jl @@ -124,7 +124,7 @@ function generate_initializesystem(sys::ODESystem; elseif check_defguess error("Invalid setup: parameter $(p) has no default value, initial value, or guess") end - # `missing` passed to `ODEProblem`, and (either an equation using default or a guess) + # `missing` passed to `ODEProblem`, and (either an equation using default or a guess) elseif _val1 === missing if _val2 !== nothing && _val2 !== missing push!(eqs_ics, varp ~ _val2) @@ -134,8 +134,8 @@ function generate_initializesystem(sys::ODESystem; elseif check_defguess error("Invalid setup: parameter $(p) has no default value, initial value, or guess") end - # No value passed to `ODEProblem`, but a default and a guess are present - # _val2 !== missing is implied by it falling this far in the elseif chain + # No value passed to `ODEProblem`, but a default and a guess are present + # _val2 !== missing is implied by it falling this far in the elseif chain elseif _val1 === nothing && _val2 !== nothing && _val3 !== nothing push!(eqs_ics, varp ~ _val2) push!(u0, varp => _val3) @@ -176,7 +176,8 @@ function is_parameter_solvable(p, pmap, defs, guesses) _val3 = get(guesses, p, nothing) # either (missing is a default or was passed to the ODEProblem) or (nothing was passed to # the ODEProblem and it has a default and a guess) - return (_val1 === missing || _val2 === missing) || (_val1 === nothing && _val2 !== nothing && _val3 !== nothing) + return (_val1 === missing || _val2 === missing) || + (_val1 === nothing && _val2 !== nothing && _val3 !== nothing) end function SciMLBase.remake_initializeprob(sys::ODESystem, odefn, u0, t0, p) diff --git a/test/initializationsystem.jl b/test/initializationsystem.jl index 9afb8cea31..4a4cfddb94 100644 --- a/test/initializationsystem.jl +++ b/test/initializationsystem.jl @@ -562,7 +562,8 @@ sol = solve(oprob_2nd_order_2, Rosenbrock23()) # retcode: Success @test solve(prob, Tsit5()).ps[sym] ≈ val end function test_initializesystem(sys, u0map, pmap, p, equation) - isys = ModelingToolkit.generate_initializesystem(sys; u0map, pmap, guesses = ModelingToolkit.guesses(sys)) + isys = ModelingToolkit.generate_initializesystem( + sys; u0map, pmap, guesses = ModelingToolkit.guesses(sys)) @test is_variable(isys, p) @test equation in equations(isys) || (0 ~ -equation.rhs) in equations(isys) end @@ -609,7 +610,8 @@ sol = solve(oprob_2nd_order_2, Rosenbrock23()) # retcode: Success test_parameter(prob2, p, 2.0) # No `missing`, default and guess - @mtkbuild sys = ODESystem([D(x) ~ x * q, D(y) ~ y * p], t; defaults = [p => 2q], guesses = [p => 0.0]) + @mtkbuild sys = ODESystem( + [D(x) ~ x * q, D(y) ~ y * p], t; defaults = [p => 2q], guesses = [p => 0.0]) delete!(pmap, p) prob = ODEProblem(sys, u0map, (0.0, 1.0), pmap) test_parameter(prob, p, 2.0) @@ -627,7 +629,8 @@ sol = solve(oprob_2nd_order_2, Rosenbrock23()) # retcode: Success @test prob.ps[p] ≈ 3.0 @test prob.f.initializeprob === nothing # Default overridden by ODEProblem, guess provided - @mtkbuild sys = ODESystem([D(x) ~ q * x, D(y) ~ y * p], t; defaults = [p => 2q], guesses = [p => 1.0]) + @mtkbuild sys = ODESystem( + [D(x) ~ q * x, D(y) ~ y * p], t; defaults = [p => 2q], guesses = [p => 1.0]) prob = ODEProblem(sys, u0map, (0.0, 1.0), _pmap) @test prob.ps[p] ≈ 3.0 @test prob.f.initializeprob === nothing