Skip to content

Commit 9cd90cf

Browse files
committed
modify cons law tests
1 parent 0a0c800 commit 9cd90cf

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/network_analysis/conservation_laws.jl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,55 @@ let
227227
@test all(sol2[osys.X1 + osys.X2] .== 4.0)
228228
end
229229

230+
# Tests system problem updating when conservation laws are eliminated.
231+
# Checks that the correct values are used after the conservation law species are updated.
232+
# Here is an issue related to the broken tests: https://github.com/SciML/Catalyst.jl/issues/952
233+
let
234+
# Create model and fetch the conservation parameter (Γ).
235+
t = default_t()
236+
@parameters k1 k2
237+
@species X1(t) X2(t)
238+
rxs = [
239+
Reaction(k1, [X1], [X2]),
240+
Reaction(k2, [X2], [X1])
241+
]
242+
@named rs = ReactionSystem(rxs, t)
243+
osys = convert(ODESystem, complete(rs); remove_conserved = true, remove_conserved_warn = false)
244+
osys = complete(osys)
245+
@unpack Γ = osys
246+
247+
# Creates an `ODEProblem`.
248+
u0 = [X1 => 1.0, X2 => 2.0]
249+
ps = [k1 => 0.1, k2 => 0.2]
250+
oprob = ODEProblem(osys, u0, (0.0, 1.0), ps)
251+
252+
# Check `ODEProblem` content.
253+
@test oprob[X1] == 1.0
254+
@test oprob[X2] == 2.0
255+
@test oprob.ps[k1] == 0.1
256+
@test oprob.ps[k2] == 0.2
257+
@test oprob.ps[Γ[1]] == 3.0
258+
259+
# Currently, any kind of updating of species or the conservation parameter(s) is not possible.
260+
261+
# Update problem parameters using `remake`.
262+
oprob_new = remake(oprob; p = [k1 => 0.3, k2 => 0.4])
263+
@test oprob_new[k1] == 0.3
264+
@test oprob_new[k2] == 0.4
265+
integrator = init(oprob_new, Tsit5())
266+
@test integrator[k1] == 0.3
267+
@test integrator[k2] == 0.4
268+
269+
# Update problem parameters using direct indexing.
270+
oprob[k1] = 0.5
271+
oprob[k2] = 0.6
272+
@test oprob_new[k1] == 0.5
273+
@test oprob_new[k2] == 0.6
274+
integrator = init(oprob_new, Tsit5())
275+
@test integrator[k1] == 0.5
276+
@test integrator[k2] == 0.6
277+
end
278+
230279
### Other Tests ###
231280

232281
# Checks that `JumpSystem`s with conservation laws cannot be generated.

0 commit comments

Comments
 (0)