Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up initializesystem for hierarchical models #2403

Merged
merged 48 commits into from Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5ca99eb
Fix up initializesystem for hierarchical models
ChrisRackauckas Dec 29, 2023
4717aee
Handle overdetermined systems gracefully when `fully_determined = false`
YingboMa Jan 2, 2024
6d6d3fa
Setup guesses(sys) and passing override dictionaries
ChrisRackauckas Feb 24, 2024
1440304
Add NonlinearLeastSquaresProblem building
ChrisRackauckas Feb 24, 2024
ee77fb2
Build the initialization system generation into structural simplifica…
ChrisRackauckas Feb 24, 2024
6f960db
InitializationProblem works
ChrisRackauckas Feb 24, 2024
0f3ba28
Test the initialization problem
ChrisRackauckas Feb 24, 2024
aafddc9
format
ChrisRackauckas Feb 24, 2024
4702426
Automate tagging of the initialization system to the ODEProblem
ChrisRackauckas Feb 26, 2024
c443ac7
Fix guess and initial condition length checking
ChrisRackauckas Feb 26, 2024
67f6f24
Bump ordinarydiffeq
ChrisRackauckas Feb 26, 2024
7c0c423
format
ChrisRackauckas Feb 26, 2024
fb4b987
stop initialize on clocks
ChrisRackauckas Feb 26, 2024
16ce722
format
ChrisRackauckas Feb 26, 2024
7a84444
fix direct structural simplification for initialization systems
ChrisRackauckas Feb 26, 2024
ae4be0f
format
ChrisRackauckas Feb 26, 2024
dcffe8f
check for io first
ChrisRackauckas Feb 26, 2024
78b5832
format
ChrisRackauckas Feb 26, 2024
6e336ba
Properly drop from defaults
ChrisRackauckas Feb 26, 2024
dfee0ef
handle the Vector{Float} case
ChrisRackauckas Feb 27, 2024
f62163a
handle nothing equations case
ChrisRackauckas Feb 27, 2024
80ece19
handle no structural simplify
ChrisRackauckas Feb 27, 2024
97c1d9d
new error
ChrisRackauckas Feb 27, 2024
8521ddb
Remove scalarization in NonlinearSystem
ChrisRackauckas Feb 27, 2024
2efc30a
Try other tests
ChrisRackauckas Feb 27, 2024
9df0b4b
remove old initialize
ChrisRackauckas Feb 27, 2024
3d41e04
see if the non array tests all pass
ChrisRackauckas Feb 27, 2024
0763874
fix reduction test
ChrisRackauckas Feb 27, 2024
deaa824
better fix
ChrisRackauckas Feb 27, 2024
456478f
only build initialization if simplified
ChrisRackauckas Feb 27, 2024
a5e275d
reenable mass matrix test
ChrisRackauckas Feb 27, 2024
f85b219
format
ChrisRackauckas Feb 27, 2024
f2559ab
Update test/odesystem.jl
ChrisRackauckas Feb 27, 2024
7970cc1
let all tests run
ChrisRackauckas Feb 27, 2024
33c361e
Merge branch 'initializesystem' of https://github.com/SciML/ModelingT…
ChrisRackauckas Feb 27, 2024
3ea493a
handle dds and t
ChrisRackauckas Feb 27, 2024
734e195
format
ChrisRackauckas Feb 27, 2024
90ceeda
update initialization problem usage for t0
ChrisRackauckas Feb 27, 2024
920fcc2
Remove early caching initialization system
ChrisRackauckas Feb 27, 2024
0b6edee
guesses
ChrisRackauckas Feb 27, 2024
d78c680
handle empty parammap
ChrisRackauckas Feb 27, 2024
79eca95
format
ChrisRackauckas Feb 27, 2024
ab935d7
Fix schedule setting
ChrisRackauckas Feb 27, 2024
2ccf8fa
a few fixes
ChrisRackauckas Feb 28, 2024
9cf1768
Fix test cases
ChrisRackauckas Feb 28, 2024
537fb7c
format
ChrisRackauckas Feb 28, 2024
56421fb
return drop_expr
ChrisRackauckas Feb 28, 2024
c78321f
Fix warning
ChrisRackauckas Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Expand Up @@ -89,12 +89,12 @@ Libdl = "1"
LinearAlgebra = "1"
MLStyle = "0.4.17"
NaNMath = "0.3, 1"
OrdinaryDiffEq = "6"
OrdinaryDiffEq = "6.72.0"
PrecompileTools = "1"
RecursiveArrayTools = "2.3, 3"
Reexport = "0.2, 1"
RuntimeGeneratedFunctions = "0.5.9"
SciMLBase = "2.0.1"
SciMLBase = "2.28.0"
SciMLStructures = "1.0"
Serialization = "1"
Setfield = "0.7, 0.8, 1"
Expand Down
9 changes: 4 additions & 5 deletions src/ModelingToolkit.jl
Expand Up @@ -137,19 +137,18 @@ include("systems/model_parsing.jl")
include("systems/connectors.jl")
include("systems/callbacks.jl")

include("systems/nonlinear/nonlinearsystem.jl")
include("systems/diffeqs/odesystem.jl")
include("systems/diffeqs/sdesystem.jl")
include("systems/diffeqs/abstractodesystem.jl")
include("systems/nonlinear/modelingtoolkitize.jl")
include("systems/nonlinear/initializesystem.jl")
include("systems/diffeqs/first_order_transform.jl")
include("systems/diffeqs/modelingtoolkitize.jl")
include("systems/diffeqs/basic_transformations.jl")

include("systems/jumps/jumpsystem.jl")

include("systems/nonlinear/nonlinearsystem.jl")
include("systems/nonlinear/modelingtoolkitize.jl")
include("systems/nonlinear/initializesystem.jl")

include("systems/optimization/constraints_system.jl")
include("systems/optimization/optimizationsystem.jl")
include("systems/optimization/modelingtoolkitize.jl")
Expand Down Expand Up @@ -253,7 +252,7 @@ export toexpr, get_variables
export simplify, substitute
export build_function
export modelingtoolkitize
export initializesystem
export initializesystem, generate_initializesystem

export @variables, @parameters, @constants, @brownian
export @named, @nonamespace, @namespace, extend, compose, complete
Expand Down
2 changes: 1 addition & 1 deletion src/bipartite_graph.jl
Expand Up @@ -423,7 +423,7 @@ return `false` may not be matched.
"""
function maximal_matching(g::BipartiteGraph, srcfilter = vsrc -> true,
dstfilter = vdst -> true, ::Type{U} = Unassigned) where {U}
matching = Matching{U}(ndsts(g))
matching = Matching{U}(max(nsrcs(g), ndsts(g)))
foreach(Iterators.filter(srcfilter, 𝑠vertices(g))) do vsrc
construct_augmenting_path!(matching, g, vsrc, dstfilter)
end
Expand Down
16 changes: 13 additions & 3 deletions src/systems/abstractsystem.jl
Expand Up @@ -537,6 +537,9 @@
if split && has_index_cache(sys)
@set! sys.index_cache = IndexCache(sys)
end
if isdefined(sys, :initializesystem) && get_initializesystem(sys) !== nothing
@set! sys.initializesystem = complete(get_initializesystem(sys); split)
end
isdefined(sys, :complete) ? (@set! sys.complete = true) : sys
end

Expand All @@ -551,6 +554,7 @@
:var_to_name
:ctrls
:defaults
:guesses
:observed
:tgrad
:jac
Expand All @@ -571,6 +575,7 @@
:connections
:preface
:torn_matching
:initializesystem
:tearing_state
:substitutions
:metadata
Expand Down Expand Up @@ -933,6 +938,10 @@
vcat(parameters(sys), dependent_parameters(sys))
end

function guesses(sys::AbstractSystem)
get_guesses(sys)

Check warning on line 942 in src/systems/abstractsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/abstractsystem.jl#L941-L942

Added lines #L941 - L942 were not covered by tests
end

# required in `src/connectors.jl:437`
parameters(_) = []

Expand Down Expand Up @@ -2259,14 +2268,15 @@
end

"""
missing_variable_defaults(sys::AbstractSystem, default = 0.0)
missing_variable_defaults(sys::AbstractSystem, default = 0.0; subset = unknowns(sys))

returns a `Vector{Pair}` of variables set to `default` which are missing from `get_defaults(sys)`. The `default` argument can be a single value or vector to set the missing defaults respectively.
"""
function missing_variable_defaults(sys::AbstractSystem, default = 0.0)
function missing_variable_defaults(

Check warning on line 2275 in src/systems/abstractsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/abstractsystem.jl#L2275

Added line #L2275 was not covered by tests
sys::AbstractSystem, default = 0.0; subset = unknowns(sys))
varmap = get_defaults(sys)
varmap = Dict(Symbolics.diff2term(value(k)) => value(varmap[k]) for k in keys(varmap))
missingvars = setdiff(unknowns(sys), keys(varmap))
missingvars = setdiff(subset, keys(varmap))

Check warning on line 2279 in src/systems/abstractsystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/abstractsystem.jl#L2279

Added line #L2279 was not covered by tests
ds = Pair[]

n = length(missingvars)
Expand Down
125 changes: 119 additions & 6 deletions src/systems/diffeqs/abstractodesystem.jl
Expand Up @@ -316,6 +316,8 @@
sparsity = false,
analytic = nothing,
split_idxs = nothing,
initializeprob = nothing,
initializeprobmap = nothing,
kwargs...) where {iip, specialize}
if !iscomplete(sys)
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating an `ODEFunction`")
Expand Down Expand Up @@ -487,6 +489,7 @@
end

@set! sys.split_idxs = split_idxs

ODEFunction{iip, specialize}(f;
sys = sys,
jac = _jac === nothing ? nothing : _jac,
Expand All @@ -495,7 +498,9 @@
jac_prototype = jac_prototype,
observed = observedfun,
sparsity = sparsity ? jacobian_sparsity(sys) : nothing,
analytic = analytic)
analytic = analytic,
initializeprob = initializeprob,
initializeprobmap = initializeprobmap)
end

"""
Expand Down Expand Up @@ -525,6 +530,8 @@
sparse = false, simplify = false,
eval_module = @__MODULE__,
checkbounds = false,
initializeprob = nothing,
initializeprobmap = nothing,
kwargs...) where {iip}
if !iscomplete(sys)
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `DAEFunction`")
Expand Down Expand Up @@ -596,7 +603,9 @@
sys = sys,
jac = _jac === nothing ? nothing : _jac,
jac_prototype = jac_prototype,
observed = observedfun)
observed = observedfun,
initializeprob = initializeprob,
initializeprobmap = initializeprobmap)
end

function DiffEqBase.DDEFunction(sys::AbstractODESystem, args...; kwargs...)
Expand Down Expand Up @@ -839,18 +848,45 @@
tofloat = true,
symbolic_u0 = false,
u0_constructor = identity,
guesses = Dict(),
warn_initialize_determined = true,
kwargs...)
eqs = equations(sys)
dvs = unknowns(sys)
ps = full_parameters(sys)
iv = get_iv(sys)

# Append zeros to the variables which are determined by the initialization system
# This essentially bypasses the check for if initial conditions are defined for DAEs
# since they will be checked in the initialization problem's construction
# TODO: make check for if a DAE cheaper than calculating the mass matrix a second time!
ci = infer_clocks!(ClockInference(TearingState(sys)))
# TODO: make it work with clocks
# ModelingToolkit.get_tearing_state(sys) !== nothing => Requires structural_simplify first
if (implicit_dae || calculate_massmatrix(sys) !== I) &&
all(isequal(Continuous()), ci.var_domain) &&
ModelingToolkit.get_tearing_state(sys) !== nothing
if eltype(u0map) <: Number
u0map = unknowns(sys) .=> u0map

Check warning on line 870 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L869-L870

Added lines #L869 - L870 were not covered by tests
end
initializeprob = ModelingToolkit.InitializationProblem(

Check warning on line 872 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L872

Added line #L872 was not covered by tests
sys, u0map, parammap; guesses, warn_initialize_determined)
initializeprobmap = getu(initializeprob, unknowns(sys))

Check warning on line 874 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L874

Added line #L874 was not covered by tests

zerovars = setdiff(unknowns(sys), keys(defaults(sys))) .=> 0.0
trueinit = identity.([zerovars; u0map])

Check warning on line 877 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L876-L877

Added lines #L876 - L877 were not covered by tests
else
initializeprob = nothing
initializeprobmap = nothing
trueinit = u0map
end

if has_index_cache(sys) && get_index_cache(sys) !== nothing
u0, defs = get_u0(sys, u0map, parammap; symbolic_u0)
u0, defs = get_u0(sys, trueinit, parammap; symbolic_u0)
p = MTKParameters(sys, parammap)
else
u0, p, defs = get_u0_p(sys,
u0map,
trueinit,
parammap;
tofloat,
use_union,
Expand Down Expand Up @@ -881,6 +917,8 @@
checkbounds = checkbounds, p = p,
linenumbers = linenumbers, parallel = parallel, simplify = simplify,
sparse = sparse, eval_expression = eval_expression,
initializeprob = initializeprob,
initializeprobmap = initializeprobmap,
kwargs...)
implicit_dae ? (f, du0, u0, p) : (f, u0, p)
end
Expand Down Expand Up @@ -984,13 +1022,14 @@
parammap = DiffEqBase.NullParameters();
callback = nothing,
check_length = true,
warn_initialize_determined = true,
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`")
end
f, u0, p = process_DEProblem(ODEFunction{iip, specialize}, sys, u0map, parammap;
t = tspan !== nothing ? tspan[1] : tspan,
check_length, kwargs...)
check_length, warn_initialize_determined, kwargs...)
cbs = process_events(sys; callback, kwargs...)
inits = []
if has_discrete_subsystems(sys) && (dss = get_discrete_subsystems(sys)) !== nothing
Expand Down Expand Up @@ -1055,13 +1094,14 @@

function DiffEqBase.DAEProblem{iip}(sys::AbstractODESystem, du0map, u0map, tspan,
parammap = DiffEqBase.NullParameters();
warn_initialize_determined = true,
check_length = true, kwargs...) where {iip}
if !iscomplete(sys)
error("A completed system is required. Call `complete` or `structural_simplify` on the system before creating a `DAEProblem`")
end
f, du0, u0, p = process_DEProblem(DAEFunction{iip}, sys, u0map, parammap;
implicit_dae = true, du0map = du0map, check_length,
kwargs...)
warn_initialize_determined, kwargs...)
diffvars = collect_differential_variables(sys)
sts = unknowns(sys)
differential_vars = map(Base.Fix2(in, diffvars), sts)
Expand Down Expand Up @@ -1442,3 +1482,76 @@
end
end
end

struct InitializationProblem{iip, specialization} end

"""
```julia
InitializationProblem{iip}(sys::AbstractODESystem, u0map, tspan,
parammap = DiffEqBase.NullParameters();
version = nothing, tgrad = false,
jac = false,
checkbounds = false, sparse = false,
simplify = false,
linenumbers = true, parallel = SerialForm(),
kwargs...) where {iip}
```

Generates a NonlinearProblem or NonlinearLeastSquaresProblem from an ODESystem
which represents the initialization, i.e. the calculation of the consistent
initial conditions for the given DAE.
"""
function InitializationProblem(sys::AbstractODESystem, args...; kwargs...)
InitializationProblem{true}(sys, args...; kwargs...)

Check warning on line 1505 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1504-L1505

Added lines #L1504 - L1505 were not covered by tests
end

function InitializationProblem(sys::AbstractODESystem,

Check warning on line 1508 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1508

Added line #L1508 was not covered by tests
u0map::StaticArray,
args...;
kwargs...)
InitializationProblem{false, SciMLBase.FullSpecialize}(sys, u0map, args...; kwargs...)

Check warning on line 1512 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1512

Added line #L1512 was not covered by tests
end

function InitializationProblem{true}(sys::AbstractODESystem, args...; kwargs...)
InitializationProblem{true, SciMLBase.AutoSpecialize}(sys, args...; kwargs...)

Check warning on line 1516 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1515-L1516

Added lines #L1515 - L1516 were not covered by tests
end

function InitializationProblem{false}(sys::AbstractODESystem, args...; kwargs...)
InitializationProblem{false, SciMLBase.FullSpecialize}(sys, args...; kwargs...)

Check warning on line 1520 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1519-L1520

Added lines #L1519 - L1520 were not covered by tests
end

function InitializationProblem{iip, specialize}(sys::AbstractODESystem, u0map = [],

Check warning on line 1523 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1523

Added line #L1523 was not covered by tests
parammap = DiffEqBase.NullParameters();
guesses = [],
check_length = true,
warn_initialize_determined = true,
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`")

Check warning on line 1530 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1529-L1530

Added lines #L1529 - L1530 were not covered by tests
end

if isempty(u0map) && get_initializesystem(sys) !== nothing
isys = get_initializesystem(sys)
elseif isempty(u0map) && get_initializesystem(sys) === nothing
isys = structural_simplify(generate_initializesystem(sys); fully_determined = false)

Check warning on line 1536 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1533-L1536

Added lines #L1533 - L1536 were not covered by tests
else
isys = structural_simplify(

Check warning on line 1538 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1538

Added line #L1538 was not covered by tests
generate_initializesystem(sys; u0map); fully_determined = false)
end

neqs = length(equations(isys))
nunknown = length(unknowns(isys))

Check warning on line 1543 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1542-L1543

Added lines #L1542 - L1543 were not covered by tests

if warn_initialize_determined && neqs > nunknown
@warn "Initialization system is overdetermined. $neqs equations for $nunknown unknowns. Initialization will default to using least squares. To suppress this warning pass warn_initialize_determined = false."

Check warning on line 1546 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1545-L1546

Added lines #L1545 - L1546 were not covered by tests
end
if warn_initialize_determined && neqs < nunknown
@warn "Initialization system is underdetermined. $neqs equations for $nunknown unknowns. Initialization will default to using least squares. To suppress this warning pass warn_initialize_determined = false."

Check warning on line 1549 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1548-L1549

Added lines #L1548 - L1549 were not covered by tests
end

if neqs == nunknown
NonlinearProblem(isys, guesses, parammap)

Check warning on line 1553 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1552-L1553

Added lines #L1552 - L1553 were not covered by tests
else
NonlinearLeastSquaresProblem(isys, guesses, parammap)

Check warning on line 1555 in src/systems/diffeqs/abstractodesystem.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/diffeqs/abstractodesystem.jl#L1555

Added line #L1555 was not covered by tests
end
end
28 changes: 23 additions & 5 deletions src/systems/diffeqs/odesystem.jl
Expand Up @@ -88,10 +88,19 @@ struct ODESystem <: AbstractODESystem
"""
defaults::Dict
"""
The guesses to use as the initial conditions for the
initialization system.
"""
guesses::Dict
"""
Tearing result specifying how to solve the system.
"""
torn_matching::Union{Matching, Nothing}
"""
The system for performing the initialization.
"""
initializesystem::Union{Nothing, NonlinearSystem}
"""
Type of the system.
"""
connector_type::Any
Expand Down Expand Up @@ -157,8 +166,8 @@ struct ODESystem <: AbstractODESystem
parent::Any

function ODESystem(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad,
jac, ctrl_jac, Wfact, Wfact_t, name, systems, defaults,
torn_matching, connector_type, preface, cevents,
jac, ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses,
torn_matching, initializesystem, connector_type, preface, cevents,
devents, parameter_dependencies, metadata = nothing, gui_metadata = nothing,
tearing_state = nothing,
substitutions = nothing, complete = false, index_cache = nothing,
Expand All @@ -175,8 +184,8 @@ struct ODESystem <: AbstractODESystem
check_units(u, deqs)
end
new(tag, deqs, iv, dvs, ps, tspan, var_to_name, ctrls, observed, tgrad, jac,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, torn_matching,
connector_type, preface, cevents, devents, parameter_dependencies, metadata,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses, torn_matching,
initializesystem, connector_type, preface, cevents, devents, parameter_dependencies, metadata,
gui_metadata, tearing_state, substitutions, complete, index_cache,
discrete_subsystems, solved_unknowns, split_idxs, parent)
end
Expand All @@ -191,6 +200,8 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
default_u0 = Dict(),
default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)),
guesses = Dict(),
initializesystem = nothing,
connector_type = nothing,
preface = nothing,
continuous_events = nothing,
Expand All @@ -217,6 +228,13 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
var_to_name = Dict()
process_variables!(var_to_name, defaults, dvs′)
process_variables!(var_to_name, defaults, ps′)

sysguesses = [ModelingToolkit.getguess(st) for st in dvs′]
hasaguess = findall(!isnothing, sysguesses)
var_guesses = dvs′[hasaguess] .=> sysguesses[hasaguess]
sysguesses = isempty(var_guesses) ? Dict() : todict(var_guesses)
guesses = merge(sysguesses, todict(guesses))

isempty(observed) || collect_var_to_name!(var_to_name, (eq.lhs for eq in observed))

tgrad = RefValue(EMPTY_TGRAD)
Expand All @@ -234,7 +252,7 @@ function ODESystem(deqs::AbstractVector{<:Equation}, iv, dvs, ps;
parameter_dependencies, ps′)
ODESystem(Threads.atomic_add!(SYSTEM_COUNT, UInt(1)),
deqs, iv′, dvs′, ps′, tspan, var_to_name, ctrl′, observed, tgrad, jac,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, nothing,
ctrl_jac, Wfact, Wfact_t, name, systems, defaults, guesses, nothing, initializesystem,
connector_type, preface, cont_callbacks, disc_callbacks, parameter_dependencies,
metadata, gui_metadata, checks = checks)
end
Expand Down