Skip to content

Commit d78b814

Browse files
refactor: change problem constructors to XProblem(sys, op[, tspan])
1 parent a049d76 commit d78b814

18 files changed

+84
-90
lines changed

src/problems/bvproblem.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ If the `System` has algebraic equations, like `x(t)^2 + y(t)^2`, the resulting
4444
`BVProblem` must be solved using BVDAE solvers, such as Ascher.
4545
"""
4646
@fallback_iip_specialize function SciMLBase.BVProblem{iip, spec}(
47-
sys::System, u0map, tspan, parammap = SciMLBase.NullParameters();
47+
sys::System, op, tspan;
4848
check_compatibility = true, cse = true,
4949
checkbounds = false, eval_expression = false, eval_module = @__MODULE__,
5050
expression = Val{false}, guesses = Dict(), callback = nothing,
@@ -55,22 +55,23 @@ If the `System` has algebraic equations, like `x(t)^2 + y(t)^2`, the resulting
5555

5656
# Systems without algebraic equations should use both fixed values + guesses
5757
# for initialization.
58-
_u0map = has_alg_eqs(sys) ? u0map : merge(Dict(u0map), Dict(guesses))
58+
_op = has_alg_eqs(sys) ? op : merge(Dict(op), Dict(guesses))
5959

6060
fode, u0, p = process_SciMLProblem(
61-
ODEFunction{iip, spec}, sys, _u0map, parammap; guesses,
61+
ODEFunction{iip, spec}, sys, _op; guesses,
6262
t = tspan !== nothing ? tspan[1] : tspan, check_compatibility = false, cse,
6363
checkbounds, time_dependent_init = false, expression, kwargs...)
6464

6565
dvs = unknowns(sys)
6666
stidxmap = Dict([v => i for (i, v) in enumerate(dvs)])
67-
u0_idxs = has_alg_eqs(sys) ? collect(1:length(dvs)) : [stidxmap[k] for (k, v) in u0map]
67+
u0_idxs = has_alg_eqs(sys) ? collect(1:length(dvs)) :
68+
[stidxmap[k] for (k, v) in op if haskey(stidxmap, k)]
6869
fbc = generate_boundary_conditions(
6970
sys, u0, u0_idxs, tspan[1]; expression = Val{false},
7071
wrap_gfw = Val{true}, cse, checkbounds)
7172

72-
if (length(constraints(sys)) + length(u0map) > length(dvs))
73-
@warn "The BVProblem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by u0map) exceeds the total number of states. The BVP solvers will default to doing a nonlinear least-squares optimization."
73+
if (length(constraints(sys)) + length(op) > length(dvs))
74+
@warn "The BVProblem is overdetermined. The total number of conditions (# constraints + # fixed initial values given by op) exceeds the total number of states. The BVP solvers will default to doing a nonlinear least-squares optimization."
7475
end
7576

7677
kwargs = process_kwargs(sys; expression, kwargs...)

src/problems/daeproblem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@
6262
end
6363

6464
@fallback_iip_specialize function SciMLBase.DAEProblem{iip, spec}(
65-
sys::System, du0map, u0map, tspan, parammap = SciMLBase.NullParameters();
65+
sys::System, op, tspan;
6666
callback = nothing, check_length = true, eval_expression = false,
6767
eval_module = @__MODULE__, check_compatibility = true,
6868
expression = Val{false}, kwargs...) where {iip, spec}
6969
check_complete(sys, DAEProblem)
7070
check_compatibility && check_compatible_system(DAEProblem, sys)
7171

72-
f, du0, u0, p = process_SciMLProblem(DAEFunction{iip, spec}, sys, u0map, parammap;
73-
du0map, t = tspan !== nothing ? tspan[1] : tspan, check_length, eval_expression,
72+
f, du0, u0, p = process_SciMLProblem(DAEFunction{iip, spec}, sys, op;
73+
t = tspan !== nothing ? tspan[1] : tspan, check_length, eval_expression,
7474
eval_module, check_compatibility, implicit_dae = true, expression, kwargs...)
7575

7676
kwargs = process_kwargs(sys; expression, callback, eval_expression, eval_module,

src/problems/ddeproblem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
end
4343

4444
@fallback_iip_specialize function SciMLBase.DDEProblem{iip, spec}(
45-
sys::System, u0map, tspan, parammap = SciMLBase.NullParameters();
45+
sys::System, op, tspan;
4646
callback = nothing, check_length = true, cse = true, checkbounds = false,
4747
eval_expression = false, eval_module = @__MODULE__, check_compatibility = true,
4848
u0_constructor = identity, expression = Val{false}, kwargs...) where {iip, spec}
4949
check_complete(sys, DDEProblem)
5050
check_compatibility && check_compatible_system(DDEProblem, sys)
5151

52-
f, u0, p = process_SciMLProblem(DDEFunction{iip, spec}, sys, u0map, parammap;
52+
f, u0, p = process_SciMLProblem(DDEFunction{iip, spec}, sys, op;
5353
t = tspan !== nothing ? tspan[1] : tspan, check_length, cse, checkbounds,
5454
eval_expression, eval_module, check_compatibility, symbolic_u0 = true,
5555
expression, u0_constructor, kwargs...)

src/problems/discreteproblem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@
3939
end
4040

4141
@fallback_iip_specialize function SciMLBase.DiscreteProblem{iip, spec}(
42-
sys::System, u0map, tspan, parammap = SciMLBase.NullParameters();
42+
sys::System, op, tspan;
4343
check_compatibility = true, expression = Val{false}, kwargs...) where {iip, spec}
4444
check_complete(sys, DiscreteProblem)
4545
check_compatibility && check_compatible_system(DiscreteProblem, sys)
4646

4747
dvs = unknowns(sys)
4848
u0map = to_varmap(u0map, dvs)
4949
add_toterms!(u0map; replace = true)
50-
f, u0, p = process_SciMLProblem(DiscreteFunction{iip, spec}, sys, u0map, parammap;
50+
f, u0, p = process_SciMLProblem(DiscreteFunction{iip, spec}, sys, op;
5151
t = tspan !== nothing ? tspan[1] : tspan, check_compatibility, expression,
5252
kwargs...)
5353

src/problems/implicitdiscreteproblem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@
4343
end
4444

4545
@fallback_iip_specialize function SciMLBase.ImplicitDiscreteProblem{iip, spec}(
46-
sys::System, u0map, tspan, parammap = SciMLBase.NullParameters();
46+
sys::System, op, tspan;
4747
check_compatibility = true, expression = Val{false}, kwargs...) where {iip, spec}
4848
check_complete(sys, ImplicitDiscreteProblem)
4949
check_compatibility && check_compatible_system(ImplicitDiscreteProblem, sys)
5050

5151
dvs = unknowns(sys)
52-
u0map = to_varmap(u0map, dvs)
53-
add_toterms!(u0map; replace = true)
52+
op = to_varmap(op, dvs)
53+
add_toterms!(op; replace = true)
5454
f, u0, p = process_SciMLProblem(
55-
ImplicitDiscreteFunction{iip, spec}, sys, u0map, parammap;
55+
ImplicitDiscreteFunction{iip, spec}, sys, op;
5656
t = tspan !== nothing ? tspan[1] : tspan, check_compatibility,
5757
expression, kwargs...)
5858

src/problems/initializationproblem.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ initial conditions for the given DAE.
119119

120120
filter_missing_values!(u0map)
121121
filter_missing_values!(parammap)
122-
u0map = merge(ModelingToolkit.guesses(sys), todict(guesses), u0map)
122+
op = merge(ModelingToolkit.guesses(sys), todict(guesses), u0map, parammap)
123123

124124
TProb = if neqs == nunknown && isempty(unassigned_vars)
125125
if use_scc && neqs > 0
@@ -135,8 +135,7 @@ initial conditions for the given DAE.
135135
else
136136
NonlinearLeastSquaresProblem
137137
end
138-
TProb{iip}(isys, u0map, parammap; kwargs...,
139-
build_initializeprob = false, is_initializeprob = true)
138+
TProb{iip}(isys, op; kwargs..., build_initializeprob = false, is_initializeprob = true)
140139
end
141140

142141
const INCOMPLETE_INITIALIZATION_MESSAGE = """

src/problems/intervalnonlinearproblem.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function SciMLBase.IntervalNonlinearProblem(
3333
check_compatibility && check_compatible_system(IntervalNonlinearProblem, sys)
3434

3535
u0map = unknowns(sys) .=> uspan[1]
36-
f, u0, p = process_SciMLProblem(IntervalNonlinearFunction, sys, u0map, parammap;
36+
op = anydict([unknowns(sys)[1] => uspan[1]])
37+
merge!(op, to_varmap(parammap, parameters(sys)))
38+
f, u0, p = process_SciMLProblem(IntervalNonlinearFunction, sys, op;
3739
check_compatibility, expression, kwargs...)
3840

3941
kwargs = process_kwargs(sys; kwargs...)

src/problems/jumpproblem.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@fallback_iip_specialize function JumpProcesses.JumpProblem{iip, spec}(
2-
sys::System, u0map, tspan::Union{Tuple, Nothing}, pmap = SciMLBase.NullParameters();
2+
sys::System, op, tspan::Union{Tuple, Nothing};
33
check_compatibility = true, eval_expression = false, eval_module = @__MODULE__,
44
checkbounds = false, cse = true, aggregator = JumpProcesses.NullAggregator(),
55
callback = nothing, rng = nothing, kwargs...) where {iip, spec}
@@ -13,16 +13,16 @@
1313
if (has_vrjs || has_eqs)
1414
if has_eqs && has_noise
1515
prob = SDEProblem{iip, spec}(
16-
sys, u0map, tspan, pmap; check_compatibility = false,
16+
sys, op, tspan; check_compatibility = false,
1717
build_initializeprob = false, checkbounds, cse, check_length = false,
1818
kwargs...)
1919
elseif has_eqs
2020
prob = ODEProblem{iip, spec}(
21-
sys, u0map, tspan, pmap; check_compatibility = false,
21+
sys, op, tspan; check_compatibility = false,
2222
build_initializeprob = false, checkbounds, cse, check_length = false,
2323
kwargs...)
2424
else
25-
_, u0, p = process_SciMLProblem(EmptySciMLFunction{iip}, sys, u0map, pmap;
25+
_, u0, p = process_SciMLProblem(EmptySciMLFunction{iip}, sys, op;
2626
t = tspan === nothing ? nothing : tspan[1], tofloat = false,
2727
check_length = false, build_initializeprob = false)
2828
observedfun = ObservedFunctionCache(sys; eval_expression, eval_module,
@@ -32,7 +32,7 @@
3232
prob = ODEProblem{true}(df, u0, tspan, p; kwargs...)
3333
end
3434
else
35-
_f, u0, p = process_SciMLProblem(EmptySciMLFunction{iip}, sys, u0map, pmap;
35+
_f, u0, p = process_SciMLProblem(EmptySciMLFunction{iip}, sys, op;
3636
t = tspan === nothing ? nothing : tspan[1], tofloat = false, check_length = false, build_initializeprob = false, cse)
3737
f = DiffEqBase.DISCRETE_INPLACE_DEFAULT
3838

src/problems/nonlinearproblem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@
5757
end
5858

5959
@fallback_iip_specialize function SciMLBase.NonlinearProblem{iip, spec}(
60-
sys::System, u0map, parammap = SciMLBase.NullParameters(); expression = Val{false},
60+
sys::System, op; expression = Val{false},
6161
check_length = true, check_compatibility = true, kwargs...) where {iip, spec}
6262
check_complete(sys, NonlinearProblem)
6363
if is_time_dependent(sys)
6464
sys = NonlinearSystem(sys)
6565
end
6666
check_compatibility && check_compatible_system(NonlinearProblem, sys)
6767

68-
f, u0, p = process_SciMLProblem(NonlinearFunction{iip, spec}, sys, u0map, parammap;
68+
f, u0, p = process_SciMLProblem(NonlinearFunction{iip, spec}, sys, op;
6969
check_length, check_compatibility, expression, kwargs...)
7070

7171
kwargs = process_kwargs(sys; kwargs...)
@@ -75,12 +75,12 @@ end
7575
end
7676

7777
@fallback_iip_specialize function SciMLBase.NonlinearLeastSquaresProblem{iip, spec}(
78-
sys::System, u0map, parammap = DiffEqBase.NullParameters(); check_length = false,
78+
sys::System, op; check_length = false,
7979
check_compatibility = true, expression = Val{false}, kwargs...) where {iip, spec}
8080
check_complete(sys, NonlinearLeastSquaresProblem)
8181
check_compatibility && check_compatible_system(NonlinearLeastSquaresProblem, sys)
8282

83-
f, u0, p = process_SciMLProblem(NonlinearFunction{iip}, sys, u0map, parammap;
83+
f, u0, p = process_SciMLProblem(NonlinearFunction{iip}, sys, op;
8484
check_length, expression, kwargs...)
8585

8686
kwargs = process_kwargs(sys; kwargs...)

src/problems/odeproblem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@
6565
end
6666

6767
@fallback_iip_specialize function SciMLBase.ODEProblem{iip, spec}(
68-
sys::System, u0map, tspan, parammap = SciMLBase.NullParameters();
68+
sys::System, op, tspan;
6969
callback = nothing, check_length = true, eval_expression = false,
7070
expression = Val{false}, eval_module = @__MODULE__, check_compatibility = true,
7171
kwargs...) where {iip, spec}
7272
check_complete(sys, ODEProblem)
7373
check_compatibility && check_compatible_system(ODEProblem, sys)
7474

75-
f, u0, p = process_SciMLProblem(ODEFunction{iip, spec}, sys, u0map, parammap;
75+
f, u0, p = process_SciMLProblem(ODEFunction{iip, spec}, sys, op;
7676
t = tspan !== nothing ? tspan[1] : tspan, check_length, eval_expression,
7777
eval_module, expression, check_compatibility, kwargs...)
7878

@@ -98,12 +98,12 @@ Generates an SteadyStateProblem from a `System` of ODEs and allows for automatic
9898
symbolically calculating numerical enhancements.
9999
"""
100100
@fallback_iip_specialize function DiffEqBase.SteadyStateProblem{iip, spec}(
101-
sys::System, u0map, parammap; check_length = true, check_compatibility = true,
101+
sys::System, op; check_length = true, check_compatibility = true,
102102
expression = Val{false}, kwargs...) where {iip, spec}
103103
check_complete(sys, SteadyStateProblem)
104104
check_compatibility && check_compatible_system(SteadyStateProblem, sys)
105105

106-
f, u0, p = process_SciMLProblem(ODEFunction{iip}, sys, u0map, parammap;
106+
f, u0, p = process_SciMLProblem(ODEFunction{iip}, sys, op;
107107
steady_state = true, check_length, check_compatibility, expression,
108108
force_initialization_time_independent = true, kwargs...)
109109

0 commit comments

Comments
 (0)