-
-
Notifications
You must be signed in to change notification settings - Fork 233
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Just trying to enumerate cases where remake fails and where there are some dependency between variables/parameters. Not 100% sure everything is declared correctly should work (and if not, would be useful to know so I can adjust my workflows). However, I have tried various versions, and I do think you always run into some errors one way or another.
If someone tells me what should/shout not work I can rework, and then we can incorporate into the tests to ensure stuff works.
using ModelingToolkit, OrdinaryDiffEq, Test
using ModelingToolkit: t_nounits as t, D_nounits as D
# Defines the model.
@parameters k1 k2 V0
@variables X1(t) X2(t) Y1(t) Y2(t) V(t) = V0 W(t)
@parameters v = V w = W Γ[1:2] = missing [guess = [1.0, 1.0]]
eqs = [
D(X1) ~ k1 * (Γ[1] - X1) - k2 * X1,
D(Y1) ~ k1 * (Γ[2] - Y1) - k2 * Y1,
D(V) ~ 1 - V,
D(W) ~ 1 - W,
]
observed = [X2 ~ Γ[1] - X1, Y2 ~ Γ[2] - Y1]
@mtkbuild osys = ODESystem(eqs, t, [X1, X2, Y1, Y2, V, W], [k1, k2, V0, v, w, Γ]; observed)
# Create the`ODEProblem`s.
u0 = [X1 => 1.0, X2 => 2.0, Y1 => 3.0, Y2 => 4.0, V => 5.0, W => 6.0]
ps = [k1 => 0.1, k2 => 0.2, V0 => 3.0]
oprob1 = ODEProblem(osys, u0, 1.0, ps)
oprob2 = remake(oprob1, u0 = [X1 => 10.0])
oprob3 = remake(oprob2, u0 = [X2 => 20.0])
oprob4 = remake(oprob1, u0 = [X2 => 20.0, Y1 => 30.0])
oprob5 = remake(oprob1, u0 = [X1 => 10.0, X2 => 20.0])
oprob6 = remake(oprob1, u0 = [Y2 => 40.0], p = [k1 => 0.4])
oprob7 = remake(oprob1, u0 = [X1 => 10.0, X2 => 20.0], p = [V0 => 50.0])
oprob8 = remake(oprob1, u0 = [W => 60.0])
# Creates a testing function.
function test_vals(prob, us_correct::Dict, ps_correct::Dict)
integ = init(prob)
for u in keys(us_correct)
@test prob[u] == us_correct[u]
@test integ[u] == us_correct[u]
end
for p in keys(ps_correct)
@test prob.ps[p] == ps_correct[p]
@test integ.ps[p] == ps_correct[p]
end
end
# Tests oprob1 without using test function.
@test oprob1[X1] == 1.0
@test oprob1[X2] == 2.0
@test oprob1[Y1] == 3.0
@test oprob1[Y2] == 4.0
@test oprob1[V] == 5.0
@test oprob1[W] == 6.0
@test oprob1.ps[k1] == 0.1
@test oprob1.ps[k2] == 0.2
@test oprob1.ps[V0] == 3.0
@test oprob1.ps[v] == 5.0
@test oprob1.ps[w] == 6.0
@test oprob1.ps[Γ[1]] == 3.0
@test oprob1.ps[Γ[2]] == 7.0
integ1 = init(oprob1)
@test integ1[X1] == 1.0
@test integ1[X2] == 2.0
@test integ1[Y1] == 3.0
@test integ1[Y2] == 4.0
@test integ1[V] == 5.0
@test integ1[W] == 6.0
@test integ1.ps[k1] == 0.1
@test integ1.ps[k2] == 0.2
@test integ1.ps[V0] == 3.0
@test integ1.ps[v] == 5.0
@test integ1.ps[w] == 6.0
@test integ1.ps[Γ[1]] == 3.0
@test integ1.ps[Γ[2]] == 7.0
# Test remaining `ODEProblems`.
test_vals(oprob1,
Dict(X1 => 1.0, X2 => 2.0, Y1 => 3.0, Y2 => 4.0, V => 5.0, W => 6.0),
Dict(k1 => 0.1, k2 => 0.2, V0 => 5.0, v => 5.0, w => 6.0, Γ[1] => 3.0, Γ[2] => 7.0))
test_vals(oprob2,
Dict(X1 => 10.0, X2 => 2.0, Y1 => 3.0, Y2 => 4.0, V => 5.0, W => 6.0),
Dict(k1 => 0.1, k2 => 0.2, V0 => 5.0, v => 5.0, w => 6.0, Γ[1] => 12.0, Γ[2] => 7.0))
test_vals(oprob3,
Dict(X1 => 10.0, X2 => 20.0, Y1 => 3.0, Y2 => 4.0, V => 5.0, W => 6.0),
Dict(k1 => 0.1, k2 => 0.2, V0 => 5.0, v => 5.0, w => 6.0, Γ[1] => 30.0, Γ[2] => 7.0))
test_vals(oprob4,
Dict(X1 => 1.0, X2 => 20.0, Y1 => 30.0, Y2 => 4.0, V => 5.0, W => 6.0),
Dict(k1 => 0.1, k2 => 0.2, V0 => 5.0, v => 5.0, w => 6.0, Γ[1] => 21.0, Γ[2] => 34.0))
test_vals(oprob5,
Dict(X1 => 10.0, X2 => 20.0, Y1 => 3.0, Y2 => 4.0, V => 5.0, W => 6.0),
Dict(k1 => 0.1, k2 => 0.2, V0 => 5.0, v => 5.0, w => 6.0, Γ[1] => 30.0, Γ[2] => 7.0))
test_vals(oprob6,
Dict(X1 => 1.0, X2 => 2.0, Y1 => 30.0, Y2 => 40.0, V => 5.0, W => 6.0),
Dict(k1 => 0.4, k2 => 0.2, V0 => 5.0, v => 5.0, w => 6.0, Γ[1] => 3.0, Γ[2] => 43.0))
test_vals(oprob7,
Dict(X1 => 10.0, X2 => 20.0, Y1 => 3.0, Y2 => 40.0, V => 50.0, W => 6.0),
Dict(k1 => 0.4, k2 => 0.2, V0 => 50.0, v => 55.0, w => 6.0, Γ[1] => 30.0, Γ[2] => 7.0))
test_vals(oprob8,
Dict(X1 => 1.0, X2 => 2.0, Y1 => 3.0, Y2 => 4.0, V => 5.0, W => 60.0),
Dict(k1 => 0.1, k2 => 0.2, V0 => 50.0, v => 50.0, w => 60.0, Γ[1] => 30.0, Γ[2] => 7.0))Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working