Skip to content

Commit 79d3aa8

Browse files
committed
update conservation law tests with new missing statenments in remake
1 parent 62df70d commit 79d3aa8

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
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.

0 commit comments

Comments
 (0)