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