Skip to content

Commit

Permalink
Merge branch 'master' into remove_glmakie_in_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsas authored Dec 28, 2024
2 parents 6240467 + 30ce040 commit 01c5080
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion test/reactionsystem_core/coupled_equation_crn_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
52 changes: 26 additions & 26 deletions test/upstream/mtk_problem_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()))
Expand All @@ -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]
Expand Down Expand Up @@ -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),
Expand All @@ -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]),
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()))
Expand Down
54 changes: 27 additions & 27 deletions test/upstream/mtk_structure_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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).
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -233,17 +233,17 @@ 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
@test sol[XY][1] == sol[model.XY][1] == sol[:XY][1] == 9
@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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 01c5080

Please sign in to comment.