Skip to content

Commit

Permalink
fixup! test: test remaking of initialization problem
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Sep 6, 2024
1 parent f62a340 commit 8080def
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions test/initializationsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -509,33 +509,47 @@ end
pmap[p] = 2q
prob = ODEProblem(sys, u0map, (0.0, 1.0), pmap)
test_parameter(prob, p, 2.0)
prob2 = remake(prob; u0 = u0map, p = pmap)
prob2.ps[p] = 0.0
test_parameter(prob2, p, 2.0)
# `missing` default, provided guess
@mtkbuild sys = ODESystem(
[D(x) ~ x, p ~ x + y], t; defaults = [p => missing], guesses = [p => 0.0])
prob = ODEProblem(sys, u0map, (0.0, 1.0))
test_parameter(prob, p, 2.0)
test_initializesystem(sys, u0map, pmap, p, 0 ~ p - x - y)
prob2 = remake(prob; u0 = u0map, p = pmap)
prob2.ps[p] = 0.0
test_parameter(prob2, p, 2.0)

# `missing` to ODEProblem, equation from default
@mtkbuild sys = ODESystem([D(x) ~ x * q, D(y) ~ y * p], t; defaults = [p => 2q])
pmap[p] = missing
prob = ODEProblem(sys, u0map, (0.0, 1.0), pmap)
test_parameter(prob, p, 2.0)
test_initializesystem(sys, u0map, pmap, p, 0 ~ 2q - p)
prob2 = remake(prob; u0 = u0map, p = pmap)
prob2.ps[p] = 0.0
test_parameter(prob2, p, 2.0)
# `missing` to ODEProblem, provided guess
@mtkbuild sys = ODESystem(
[D(x) ~ x, p ~ x + y], t; guesses = [p => 0.0])
prob = ODEProblem(sys, u0map, (0.0, 1.0), pmap)
test_parameter(prob, p, 2.0)
test_initializesystem(sys, u0map, pmap, p, 0 ~ x + y - p)
prob2 = remake(prob; u0 = u0map, p = pmap)
prob2.ps[p] = 0.0
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])
delete!(pmap, p)
prob = ODEProblem(sys, u0map, (0.0, 1.0), pmap)
test_parameter(prob, p, 2.0)
test_initializesystem(sys, u0map, pmap, p, 0 ~ 2q - p)
prob2 = remake(prob; u0 = u0map, p = pmap)
prob2.ps[p] = 0.0
test_parameter(prob2, p, 2.0)

# Should not be solved for:

Expand Down Expand Up @@ -591,7 +605,7 @@ end

@testset "Re-creating initialization problem on remake" begin
@variables x(t) y(t)
@parameters p
@parameters p q
@mtkbuild sys = ODESystem(
[D(x) ~ x, p ~ x + y], t; defaults = [p => missing], guesses = [x => 0.0, p => 0.0])
prob = ODEProblem(sys, [x => 1.0, y => 1.0], (0.0, 1.0))
Expand All @@ -608,12 +622,4 @@ end
@test solve(prob4, Tsit5()).retcode == ReturnCode.InitialFailure
prob5 = remake(prob)
@test init(prob, Tsit5()).ps[p] 2.0

@mtkbuild sys = ODESystem([D(x) ~ x, p ~ x + y], t; guesses = [p => 0.0])
prob = ODEProblem(sys, [x => 1.0, y => 1.0], (0.0, 1.0), [p => 2.0])
# No value for `p`, not `missing`
@test_throws ModelingToolkit.MissingParametersError remake(
prob; u0 = [x => 1.0, y => 3x])
prob2 = remake(prob; u0 = [x => 1.0, y => 2x + exp(t)], p = [p => missing])
@test init(prob2, Tsit5()).ps[p] 4.0
end

0 comments on commit 8080def

Please sign in to comment.