Skip to content

Commit 9346cbb

Browse files
committed
Merge remote-tracking branch 'origin/master' into release-15.0.4
2 parents 2044ee8 + 0b15ca1 commit 9346cbb

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

test/network_analysis/conservation_laws.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ end
339339
# the values of relevant quantities are correct after each step.
340340
# Generally, if `Γ` has not been explicitly updated, it will be updated to acomodate new species
341341
# values. If it has been explicitly updated, the corresponding eliminated quantity will have its
342-
# value updated to acomodate new Γ/species values (also, the eliminated species's value can not longer be changed).
342+
# value updated to acomodate new Γ/species values (however, we have to manually designate this by setting it to `nothing`).
343343
# Also checks that quantities are correctly updated in integrators and solutions derived from problems.
344344
let
345345
# Prepares the problem inputs and computes the conservation equation.
@@ -362,7 +362,7 @@ let
362362
# - Only that species and the conservation constant have their values updated.
363363
# The `≈` is because sometimes the computed values will not be fully exact.
364364
for _ = 1:3
365-
# Updates X2, checks the values of all species and Γ, then sets which is the old problem.
365+
# Updates X2, checks the values of all species and Γ, then resets `prob_old`.
366366
X2_new = rand(rng, 1.0:10.0)
367367
prob_new = remake(prob_old; u0 = [:X2 => X2_new])
368368
@test prob_old[:X1] prob_new[:X1]
@@ -371,7 +371,7 @@ let
371371
@test substitute(conserved_quantity, Dict([X1 => prob_old[X1], X2 => X2_new, X3 => prob_old[X3]])) prob_new.ps[][1]
372372
prob_old = prob_new
373373

374-
# Updates X3, checks the values of all species and Γ, then sets which is the old problem.
374+
# Updates X3, checks the values of all species and Γ, then resets `prob_old`.
375375
X3_new = rand(rng, 1.0:10.0)
376376
prob_new = remake(prob_old; u0 = [:X3 => X3_new])
377377
@test prob_old[:X1] prob_new[:X1]
@@ -398,35 +398,37 @@ let
398398
# Similarly, but now also updates the conservation constant. Here, once Γ has been updated:
399399
# - The conservation law constant will be kept fixed, and secondary updates are made to the
400400
# eliminated species.
401-
# Assumes that X3 is the eliminated species.
401+
# Assumes that X3 is the eliminated species. In most updates, designate its as `nothing` (to
402+
# ensure that its value is updated to acommodate the new conservation law).
402403
# The random Γ is ensured to be large enough not to generate negative values in the eliminated species.
403404
for _ in 1:3
404-
# Updates Γ, checks the values of all species and Γ, then sets which is the old problem.
405+
# Updates Γ, checks the values of all species and Γ, then resets `prob_old`.
405406
Γ_new = substitute(conserved_quantity, Dict([X1 => prob_old[X1], X2 => prob_old[X2], X3 => 0])) + rand(rng, 0.0:5.0)
406-
prob_new = remake(prob_old; p = [ => [Γ_new]])
407+
prob_new = remake(prob_old; u0 = [:X3 => nothing], p = [ => [Γ_new]])
407408
@test prob_old[:X1] prob_new[:X1]
408409
@test prob_old[:X2] prob_new[:X2]
409410
@test Γ_new prob_new.ps[][1]
410411
@test substitute(conserved_quantity, Dict([X1 => prob_old[X1], X2 => prob_old[X2], X3 => prob_new[X3]])) prob_new.ps[][1]
411412
prob_old = prob_new
412413

413-
# Updates X1 (non-eliminated species), checks the values of all species and Γ, then sets which is the old problem.
414-
# Note that now, `X3` will have its value modified (not and `Γ` remains unchanged).
414+
# Updates X1 (non-eliminated species), checks the values of all species and Γ, then resets `prob_old`.
415+
# Note that now, `X3` will have its value modified (and `Γ` remains unchanged).
415416
X1_new = rand(rng, 1.0:10.0)
416-
prob_new = remake(prob_old; u0 = [:X1 => X1_new])
417+
prob_new = remake(prob_old; u0 = [:X1 => X1_new, :X3 => nothing])
417418
@test X1_new prob_new[:X1]
418419
@test prob_old[:X2] prob_new[:X2]
419420
@test prob_old.ps[][1] prob_new.ps[][1]
420421
@test substitute(conserved_quantity, Dict([X1 => X1_new, X2 => prob_old[X2], X3 => prob_new[X3]])) prob_new.ps[][1]
421422
prob_old = prob_new
422423

423-
# Updates X3 (the eliminated species). Right now, this will have no effect on `X3` (or the system).
424+
# Updates X3 (the eliminated species). Since we reset Γ, this has its value modified to
425+
# accommodate the new value of X3.
424426
X3_new = rand(rng, 1.0:10.0)
425-
prob_new = remake(prob_old; u0 = [:X3 => X3_new])
427+
prob_new = remake(prob_old; u0 = [:X3 => X3_new], p = [ => nothing])
426428
@test prob_old[:X1] prob_new[:X1]
427429
@test prob_old[:X2] prob_new[:X2]
428-
@test prob_old[:X3] prob_new[:X3]
429-
@test prob_old.ps[][1] prob_new.ps[][1]
430+
@test X3_new prob_new[:X3]
431+
@test substitute(conserved_quantity, Dict([X1 => prob_old[X1], X2 => prob_old[X2], X3 => X3_new])) prob_new.ps[][1]
430432
prob_old = prob_new
431433

432434
# Checks that integrator and solutions have identical content to problem.

test/upstream/mtk_structure_indexing.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,17 @@ let
353353
prob6 = remake(prob1, u0 = [Y2 => 40.0], p = [k1 => 0.4])
354354
prob7 = remake(prob1, u0 = [X1 => 10.0, X2 => 20.0], p = [V0 => 50.0])
355355
prob8 = remake(prob1, u0 = [W => 60.0])
356-
prob9 = remake(prob2; p ==> [10.0, 20.0]])
357-
prob10 = remake(prob1; u0 = [Y1 => 20.0], p ==> [20.0, 30.0], k1 => 0.4])
356+
prob9 = remake(prob2; u0 = [X2 => nothing, Y2 => nothing],
357+
p ==> [10.0, 20.0]])
358+
prob10 = remake(prob1; u0 = [Y1 => 20.0, Y2 => nothing, X2 => nothing],
359+
p ==> [20.0, 30.0], k1 => 0.4])
358360
prob11 = remake(prob10, u0 = [X1 => 10.0], p = [k2 => 0.5])
359361

360362
# Creates a testing function.
361363
function test_vals(prob, us_correct::Dict, ps_correct::Dict)
362364
integ = init(prob, solver)
363365
sol = solve(prob, solver)
366+
@test SciMLBase.successful_retcode(sol)
364367
for u in keys(us_correct)
365368
@test prob[u] == us_correct[u]
366369
@test integ[u] == us_correct[u]
@@ -399,9 +402,6 @@ let
399402
test_vals(prob8,
400403
Dict(X1 => 1.0, X2 => 2.0, Y1 => 3.0, Y2 => 4.0, V => 3.0, W => 60.0),
401404
Dict(k1 => 0.1, k2 => 0.2, V0 => 3.0, v => 3.0, w => 60.0, Γ[1] => 3.0, Γ[2] => 7.0))
402-
test_vals(prob8,
403-
Dict(X1 => 1.0, X2 => 2.0, Y1 => 3.0, Y2 => 4.0, V => 3.0, W => 60.0),
404-
Dict(k1 => 0.1, k2 => 0.2, V0 => 3.0, v => 3.0, w => 60.0, Γ[1] => 3.0, Γ[2] => 7.0))
405405
test_vals(prob9,
406406
Dict(X1 => 10.0, X2 => 0.0, Y1 => 3.0, Y2 => 17.0, V => 3.0, W => 6.0),
407407
Dict(k1 => 0.1, k2 => 0.2, V0 => 3.0, v => 3.0, w => 6.0, Γ[1] => 10.0, Γ[2] => 20.0))

0 commit comments

Comments
 (0)