From 254388091ebd8a396f6d635476ea7d1b321b2bc3 Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Thu, 19 Dec 2024 12:10:55 +0000 Subject: [PATCH 1/3] init --- test/upstream/mtk_problem_inputs.jl | 46 ++++++++++----------- test/upstream/mtk_structure_indexing.jl | 54 ++++++++++++------------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/test/upstream/mtk_problem_inputs.jl b/test/upstream/mtk_problem_inputs.jl index 4997a36dfc..d2c72238e4 100644 --- a/test/upstream/mtk_problem_inputs.jl +++ b/test/upstream/mtk_problem_inputs.jl @@ -3,7 +3,7 @@ ### Prepares Tests ### # Fetch packages -using Catalyst, JumpProcesses, NonlinearSolve, OrdinaryDiffEqTsit5, StaticArrays, SteadyStateDiffEq, +using Catalyst, JumpProcesses, NonlinearSolve, OrdinaryDiffEqTsit5, StaticArrays, SteadyStateDiffEq, StochasticDiffEq, Test # Sets rnd number. @@ -15,7 +15,7 @@ seed = rand(rng, 1:100) ### Basic Tests ### # Prepares a models and initial conditions/parameters (of different forms) to be used as problem inputs. -begin +begin model = @reaction_network begin @species Z(t) = Z0 @parameters k2=0.5 Z0 @@ -97,7 +97,7 @@ begin end # Perform ODE simulations (singular and ensemble). -let +let # Creates normal and ensemble problems. base_oprob = ODEProblem(model, u0_alts[1], tspan, p_alts[1]) base_sol = solve(base_oprob, Tsit5(); saveat = 1.0) @@ -114,7 +114,7 @@ let end # Perform SDE simulations (singular and ensemble). -let +let # Creates normal and ensemble problems. base_sprob = SDEProblem(model, u0_alts[1], tspan, p_alts[1]) base_sol = solve(base_sprob, ImplicitEM(); seed, saveat = 1.0) @@ -131,7 +131,7 @@ let end # Perform jump simulations (singular and ensemble). -let +let # Creates normal and ensemble problems. base_dprob = DiscreteProblem(model, u0_alts[1], tspan, p_alts[1]) base_jprob = JumpProblem(model, base_dprob, Direct(); rng) @@ -159,7 +159,7 @@ let end # Perform steady state simulations (singular and ensemble). -let +let # Creates normal and ensemble problems. base_ssprob = SteadyStateProblem(model, u0_alts[1], p_alts[1]) base_sol = solve(base_ssprob, DynamicSS(Tsit5())) @@ -177,7 +177,7 @@ end ### Vector Species/Parameters Tests ### -begin +begin # Declares the model (with vector species/parameters, with/without default values, and observables). t = default_t() @species (X(t))[1:2] (Y(t))[1:2] = [10.0, 20.0] (XY(t))[1:2] @@ -251,33 +251,33 @@ begin # Declares various ps versions (vector forms only). p_alts_vec = [ # Vectors not providing default values. - [p => [1.0, 2.0]], - [model_vec.p => [1.0, 2.0]], - [:p => [1.0, 2.0]], + [p => [4.0, 5.0]], + [model_vec.p => [4.0, 5.0]], + [:p => [4.0, 5.0]], # Vectors providing default values. [p => [4.0, 5.0], d => [0.2, 0.5]], [model_vec.p => [4.0, 5.0], model_vec.d => [0.2, 0.5]], [:p => [4.0, 5.0], :d => [0.2, 0.5]], # Static vectors not providing default values. - SA[p => [1.0, 2.0]], - SA[model_vec.p => [1.0, 2.0]], - SA[:p => [1.0, 2.0]], + SA[p => [4.0, 5.0]], + SA[model_vec.p => [4.0, 5.0]], + SA[:p => [4.0, 5.0]], # Static vectors providing default values. SA[p => [4.0, 5.0], d => [0.2, 0.5]], SA[model_vec.p => [4.0, 5.0], model_vec.d => [0.2, 0.5]], SA[:p => [4.0, 5.0], :d => [0.2, 0.5]], # Dicts not providing default values. - Dict([p => [1.0, 2.0]]), - Dict([model_vec.p => [1.0, 2.0]]), - Dict([:p => [1.0, 2.0]]), + Dict([p => [4.0, 5.0]]), + Dict([model_vec.p => [4.0, 5.0]]), + Dict([:p => [4.0, 5.0]]), # Dicts providing default values. Dict([p => [4.0, 5.0], d => [0.2, 0.5]]), Dict([model_vec.p => [4.0, 5.0], model_vec.d => [0.2, 0.5]]), Dict([:p => [4.0, 5.0], :d => [0.2, 0.5]]), # Tuples not providing default values. - (p => [1.0, 2.0]), - (model_vec.p => [1.0, 2.0]), - (:p => [1.0, 2.0]), + (p => [4.0, 5.0]), + (model_vec.p => [4.0, 5.0]), + (:p => [4.0, 5.0]), # Tuples providing default values. (p => [4.0, 5.0], d => [0.2, 0.5]), (model_vec.p => [4.0, 5.0], model_vec.d => [0.2, 0.5]), @@ -289,7 +289,7 @@ begin end # Perform ODE simulations (singular and ensemble). -let +let # Creates normal and ensemble problems. base_oprob = ODEProblem(model_vec, u0_alts_vec[1], tspan, p_alts_vec[1]) base_sol = solve(base_oprob, Tsit5(); saveat = 1.0) @@ -307,7 +307,7 @@ let end # Perform SDE simulations (singular and ensemble). -let +let # Creates normal and ensemble problems. base_sprob = SDEProblem(model_vec, u0_alts_vec[1], tspan, p_alts_vec[1]) base_sol = solve(base_sprob, ImplicitEM(); seed, saveat = 1.0) @@ -325,7 +325,7 @@ let end # Perform jump simulations (singular and ensemble). -let +let # Creates normal and ensemble problems. base_dprob = DiscreteProblem(model_vec, u0_alts_vec[1], tspan, p_alts_vec[1]) base_jprob = JumpProblem(model_vec, base_dprob, Direct(); rng) @@ -355,7 +355,7 @@ let end # Perform steady state simulations (singular and ensemble). -let +let # Creates normal and ensemble problems. base_ssprob = SteadyStateProblem(model_vec, u0_alts_vec[1], p_alts_vec[1]) base_sol = solve(base_ssprob, DynamicSS(Tsit5())) diff --git a/test/upstream/mtk_structure_indexing.jl b/test/upstream/mtk_structure_indexing.jl index f5a8bde969..7e65ca6d54 100644 --- a/test/upstream/mtk_structure_indexing.jl +++ b/test/upstream/mtk_structure_indexing.jl @@ -52,7 +52,7 @@ begin nint = init(nprob, NewtonRaphson(); save_everystep = false) @test_broken ssint = init(ssprob, DynamicSS(Tsit5()); save_everystep = false) # https://github.com/SciML/SciMLBase.jl/issues/660 integrators = [oint, sint, jint, nint] - + # Creates solutions. osol = solve(oprob, Tsit5()) ssol = solve(sprob, ImplicitEM(); seed) @@ -63,7 +63,7 @@ begin end # Tests problem indexing and updating. -let +let @test_broken false # A few cases fails for JumpProblem: https://github.com/SciML/ModelingToolkit.jl/issues/2838 for prob in deepcopy([oprob, sprob, dprob, nprob, ssprob, eoprob, esprob, edprob, enprob, essprob]) # Get u values (including observables). @@ -72,8 +72,8 @@ let @test prob[[XY,Y]] == prob[[model.XY,model.Y]] == prob[[:XY,:Y]] == [9, 5] @test prob[(XY,Y)] == prob[(model.XY,model.Y)] == prob[(:XY,:Y)] == (9, 5) @test getu(prob, X)(prob) == getu(prob, model.X)(prob) == getu(prob, :X)(prob) == 4 - @test getu(prob, XY)(prob) == getu(prob, model.XY)(prob) == getu(prob, :XY)(prob) == 9 - @test getu(prob, [XY,Y])(prob) == getu(prob, [model.XY,model.Y])(prob) == getu(prob, [:XY,:Y])(prob) == [9, 5] + @test getu(prob, XY)(prob) == getu(prob, model.XY)(prob) == getu(prob, :XY)(prob) == 9 + @test getu(prob, [XY,Y])(prob) == getu(prob, [model.XY,model.Y])(prob) == getu(prob, [:XY,:Y])(prob) == [9, 5] @test getu(prob, (XY,Y))(prob) == getu(prob, (model.XY,model.Y))(prob) == getu(prob, (:XY,:Y))(prob) == (9, 5) # Set u values. @@ -91,13 +91,13 @@ let @test prob[X] == 70 # Get p values. - @test prob.ps[kp] == prob.ps[model.kp] == prob.ps[:kp] == 1.0 + @test prob.ps[kp] == prob.ps[model.kp] == prob.ps[:kp] == 1.0 @test prob.ps[[k1,k2]] == prob.ps[[model.k1,model.k2]] == prob.ps[[:k1,:k2]] == [0.25, 0.5] @test prob.ps[(k1,k2)] == prob.ps[(model.k1,model.k2)] == prob.ps[(:k1,:k2)] == (0.25, 0.5) @test getp(prob, kp)(prob) == getp(prob, model.kp)(prob) == getp(prob, :kp)(prob) == 1.0 @test getp(prob, [k1,k2])(prob) == getp(prob, [model.k1,model.k2])(prob) == getp(prob, [:k1,:k2])(prob) == [0.25, 0.5] @test getp(prob, (k1,k2))(prob) == getp(prob, (model.k1,model.k2))(prob) == getp(prob, (:k1,:k2))(prob) == (0.25, 0.5) - + # Set p values. prob.ps[kp] = 2.0 @test prob.ps[kp] == 2.0 @@ -115,7 +115,7 @@ let end # Test remake function. -let +let @test_broken false # Cannot check result for JumpProblem: https://github.com/SciML/ModelingToolkit.jl/issues/2838 for prob in deepcopy([oprob, sprob, dprob, nprob, ssprob, eoprob, esprob, edprob, enprob, essprob]) # Remake for all u0s. @@ -153,7 +153,7 @@ let end # Test integrator indexing. -let +let @test_broken false # NOTE: Cannot even create a `ssint` (https://github.com/SciML/SciMLBase.jl/issues/660). for int in deepcopy([oint, sint, jint, nint]) # Get u values. @@ -162,8 +162,8 @@ let @test int[[XY,Y]] == int[[model.XY,model.Y]] == int[[:XY,:Y]] == [9, 5] @test int[(XY,Y)] == int[(model.XY,model.Y)] == int[(:XY,:Y)] == (9, 5) @test getu(int, X)(int) == getu(int, model.X)(int) == getu(int, :X)(int) == 4 - @test getu(int, XY)(int) == getu(int, model.XY)(int) == getu(int, :XY)(int) == 9 - @test getu(int, [XY,Y])(int) == getu(int, [model.XY,model.Y])(int) == getu(int, [:XY,:Y])(int) == [9, 5] + @test getu(int, XY)(int) == getu(int, model.XY)(int) == getu(int, :XY)(int) == 9 + @test getu(int, [XY,Y])(int) == getu(int, [model.XY,model.Y])(int) == getu(int, [:XY,:Y])(int) == [9, 5] @test getu(int, (XY,Y))(int) == getu(int, (model.XY,model.Y))(int) == getu(int, (:XY,:Y))(int) == (9, 5) # Set u values. @@ -181,13 +181,13 @@ let @test int[X] == 70 # Get p values. - @test int.ps[kp] == int.ps[model.kp] == int.ps[:kp] == 1.0 + @test int.ps[kp] == int.ps[model.kp] == int.ps[:kp] == 1.0 @test int.ps[[k1,k2]] == int.ps[[model.k1,model.k2]] == int.ps[[:k1,:k2]] == [0.25, 0.5] @test int.ps[(k1,k2)] == int.ps[(model.k1,model.k2)] == int.ps[(:k1,:k2)] == (0.25, 0.5) @test getp(int, kp)(int) == getp(int, model.kp)(int) == getp(int, :kp)(int) == 1.0 @test getp(int, [k1,k2])(int) == getp(int, [model.k1,model.k2])(int) == getp(int, [:k1,:k2])(int) == [0.25, 0.5] @test getp(int, (k1,k2))(int) == getp(int, (model.k1,model.k2))(int) == getp(int, (:k1,:k2))(int) == (0.25, 0.5) - + # Set p values. int.ps[kp] = 2.0 @test int.ps[kp] == 2.0 @@ -206,7 +206,7 @@ end # Test solve's save_idxs argument. # Currently, `save_idxs` is broken with symbolic stuff (https://github.com/SciML/ModelingToolkit.jl/issues/1761). -let +let for (prob, solver) in zip(deepcopy([oprob, sprob, jprob]), [Tsit5(), ImplicitEM(), SSAStepper()]) # Save single variable @@ -218,7 +218,7 @@ let @test_broken solve(prob, solver; seed, save_idxs=X)[X][1] == 4 @test_broken solve(prob, solver; seed, save_idxs=model.X)[X][1] == 4 @test_broken solve(prob, solver; seed, save_idxs=:X)[X][1] == 4 - end + end # Save observable. @test_broken solve(prob, solver; seed, save_idxs=XY)[XY][1] == 9 @@ -233,7 +233,7 @@ let end # Tests solution indexing. -let +let for sol in deepcopy([osol, ssol, jsol]) # Get u values. @test sol[X][1] == sol[model.X][1] == sol[:X][1] == 4 @@ -241,9 +241,9 @@ let @test sol[[XY,Y]][1] == sol[[model.XY,model.Y]][1] == sol[[:XY,:Y]][1] == [9, 5] @test sol[(XY,Y)][1] == sol[(model.XY,model.Y)][1] == sol[(:XY,:Y)][1] == (9, 5) @test getu(sol, X)(sol)[1] == getu(sol, model.X)(sol)[1] == getu(sol, :X)(sol)[1] == 4 - @test getu(sol, XY)(sol)[1] == getu(sol, model.XY)(sol)[1] == getu(sol, :XY)(sol)[1] == 9 - @test getu(sol, [XY,Y])(sol)[1] == getu(sol, [model.XY,model.Y])(sol)[1] == getu(sol, [:XY,:Y])(sol)[1] == [9, 5] - @test getu(sol, (XY,Y))(sol)[1] == getu(sol, (model.XY,model.Y))(sol)[1] == getu(sol, (:XY,:Y))(sol)[1] == (9, 5) + @test getu(sol, XY)(sol)[1] == getu(sol, model.XY)(sol)[1] == getu(sol, :XY)(sol)[1] == 9 + @test getu(sol, [XY,Y])(sol)[1] == getu(sol, [model.XY,model.Y])(sol)[1] == getu(sol, [:XY,:Y])(sol)[1] == [9, 5] + @test getu(sol, (XY,Y))(sol)[1] == getu(sol, (model.XY,model.Y))(sol)[1] == getu(sol, (:XY,:Y))(sol)[1] == (9, 5) # Get u values via idxs and functional call. @test sol(0.0; idxs=X) == sol(0.0; idxs=model.X) == sol(0.0; idxs=:X) == 4 @@ -252,7 +252,7 @@ let @test_broken sol(0.0; idxs = (XY,Y)) == sol(0.0; idxs = (model.XY,model.Y)) == sol(0.0; idxs = (:XY,:Y)) == (9, 5) # https://github.com/SciML/SciMLBase.jl/issues/711 # Get p values. - @test sol.ps[kp] == sol.ps[model.kp] == sol.ps[:kp] == 1.0 + @test sol.ps[kp] == sol.ps[model.kp] == sol.ps[:kp] == 1.0 @test sol.ps[[k1,k2]] == sol.ps[[model.k1,model.k2]] == sol.ps[[:k1,:k2]] == [0.25, 0.5] @test sol.ps[(k1,k2)] == sol.ps[(model.k1,model.k2)] == sol.ps[(:k1,:k2)] == (0.25, 0.5) @test getp(sol, kp)(sol) == getp(sol, model.kp)(sol) == getp(sol, :kp)(sol) == 1.0 @@ -271,7 +271,7 @@ let @test getu(sol, X)(sol) == getu(sol, model.X)(sol)[1] == getu(sol, :X)(sol) @test getu(sol, XY)(sol) == getu(sol, model.XY)(sol)[1] == getu(sol, :XY)(sol) @test getu(sol, [XY,Y])(sol) == getu(sol, [model.XY,model.Y])(sol) == getu(sol, [:XY,:Y])(sol) - @test_broken getu(sol, (XY,Y))(sol) == getu(sol, (model.XY,model.Y))(sol) == getu(sol, (:XY,:Y))(sol)[1] # https://github.com/SciML/SciMLBase.jl/issues/710 + @test getu(sol, (XY,Y))(sol) == getu(sol, (model.XY,model.Y))(sol) == getu(sol, (:XY,:Y))(sol) # Get p values. @test sol.ps[kp] == sol.ps[model.kp] == sol.ps[:kp] @@ -285,7 +285,7 @@ let end # Tests plotting. -let +let for sol in deepcopy([osol, jsol, ssol]) # Single variable. @test length(plot(sol; idxs = X).series_list) == 1 @@ -310,7 +310,7 @@ let @test length(plot(sol; idxs = (model.XY, model.Y)).series_list) == 1 @test length(plot(sol; idxs = (:X, :Y)).series_list) == 1 @test length(plot(sol; idxs = (:XY, :Y)).series_list) == 1 - end + end end @@ -365,27 +365,27 @@ let @test jint.cb.condition.ma_jumps.scaled_rates[1] == 30.0 reset_aggregated_jumps!(jint) @test jint.cb.condition.ma_jumps.scaled_rates[1] == 8.0 - + jint.ps[rn.p1] = 5.0 @test jint.cb.condition.ma_jumps.scaled_rates[1] == 8.0 reset_aggregated_jumps!(jint) @test jint.cb.condition.ma_jumps.scaled_rates[1] == 10.0 - + jint.ps[:p1] = 6.0 @test jint.cb.condition.ma_jumps.scaled_rates[1] == 10.0 reset_aggregated_jumps!(jint) @test jint.cb.condition.ma_jumps.scaled_rates[1] == 12.0 - + setp(jint, p1)(jint, 7.0) @test jint.cb.condition.ma_jumps.scaled_rates[1] == 12.0 reset_aggregated_jumps!(jint) @test jint.cb.condition.ma_jumps.scaled_rates[1] == 14.0 - + setp(jint, rn.p1)(jint, 8.0) @test jint.cb.condition.ma_jumps.scaled_rates[1] == 14.0 reset_aggregated_jumps!(jint) @test jint.cb.condition.ma_jumps.scaled_rates[1] == 16.0 - + setp(jint, :p1)(jint, 3.0) @test jint.cb.condition.ma_jumps.scaled_rates[1] == 16.0 reset_aggregated_jumps!(jint) From 89c94a0b06e666c6735fa48bb911756ca57560cc Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Thu, 19 Dec 2024 12:49:58 +0000 Subject: [PATCH 2/3] tuple update --- test/upstream/mtk_problem_inputs.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/upstream/mtk_problem_inputs.jl b/test/upstream/mtk_problem_inputs.jl index d2c72238e4..83f5ea52a8 100644 --- a/test/upstream/mtk_problem_inputs.jl +++ b/test/upstream/mtk_problem_inputs.jl @@ -235,11 +235,11 @@ begin Dict([model_vec.X[1] => 1.0, model_vec.X[2] => 2.0, model_vec.Y[1] => 10.0, model_vec.Y[2] => 20.0]), Dict([:X => [1.0, 2.0], :Y => [10.0, 20.0]]), # Tuples not providing default values. - (X => [1.0, 2.0]), + (X => [1.0, 2.0],), (X[1] => 1.0, X[2] => 2.0), - (model_vec.X => [1.0, 2.0]), + (model_vec.X => [1.0, 2.0],), (model_vec.X[1] => 1.0, model_vec.X[2] => 2.0), - (:X => [1.0, 2.0]), + (:X => [1.0, 2.0],), # Tuples providing default values. (X => [1.0, 2.0], Y => [10.0, 20.0]), (X[1] => 1.0, X[2] => 2.0, Y[1] => 10.0, Y[2] => 20.0), @@ -275,9 +275,9 @@ begin Dict([model_vec.p => [4.0, 5.0], model_vec.d => [0.2, 0.5]]), Dict([:p => [4.0, 5.0], :d => [0.2, 0.5]]), # Tuples not providing default values. - (p => [4.0, 5.0]), - (model_vec.p => [4.0, 5.0]), - (:p => [4.0, 5.0]), + (p => [4.0, 5.0],), + (model_vec.p => [4.0, 5.0],), + (:p => [4.0, 5.0],), # Tuples providing default values. (p => [4.0, 5.0], d => [0.2, 0.5]), (model_vec.p => [4.0, 5.0], model_vec.d => [0.2, 0.5]), From 9596d4a5aa7d720296e0049eee58c6c727c5f4a0 Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Thu, 19 Dec 2024 18:14:55 +0000 Subject: [PATCH 3/3] update now working test --- test/reactionsystem_core/coupled_equation_crn_systems.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/reactionsystem_core/coupled_equation_crn_systems.jl b/test/reactionsystem_core/coupled_equation_crn_systems.jl index 9968eb05f3..0fe55c7c87 100644 --- a/test/reactionsystem_core/coupled_equation_crn_systems.jl +++ b/test/reactionsystem_core/coupled_equation_crn_systems.jl @@ -228,7 +228,7 @@ let Reaction(d, [X], []), Reaction(d, [X], nothing, [2], nothing), D(V) ~ X - v*V, - W^2 ~ log(V) + X + W^2 ~ log(V) + X ] @named coupled_rs = ReactionSystem(eqs, t) @@ -456,7 +456,7 @@ end # Checks that a coupled SDE + algebraic equations works. # Checks that structural_simplify is required to simulate coupled SDE + algebraic equations. -@test_broken let # SDEs are currently broken with structural simplify (https://github.com/SciML/ModelingToolkit.jl/issues/2614). +let # SDEs are currently broken with structural simplify (https://github.com/SciML/ModelingToolkit.jl/issues/2614). # Creates coupled reactions system. @parameters p d k1 k2 @species X(t) @@ -480,7 +480,7 @@ end # Checks the algebraic equation holds. sprob = SDEProblem(coupled_rs, u0, tspan, ps; structural_simplify = true) ssol = solve(sprob, ImplicitEM()) - @test 2 .+ ps[:k1] * ssol[:A] == 3 .+ ps[:k2] * ssol[:X] + @test_broken 2 .+ ps[k1] * ssol[:A] == 3 .+ ps[k2] * ssol[:X] end