Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 65 additions & 63 deletions test/upstream/mtk_problem_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,66 +368,68 @@ end
### Checks Errors On Faulty Inputs ###

# Checks various erroneous problem inputs, ensuring that these throw errors.
let
# Declares the model.
rn = @reaction_network begin
(k1,k2), X1 <--> X2
end
@unpack k1, k2, X1, X2 = rn

# Declares valid initial conditions and parameter values
u0_valid = [X1 => 1, X2 => 2]
ps_valid = [k1 => 0.5, k2 => 0.1]

# Declares invalid initial conditions and parameters. Currently, this only includes cases
# where at least one value is missing. Includes vector/Tuple/Dict forms.
u0s_invalid = [
[X1 => 1],
[rn.X1 => 1],
[:X1 => 1],
SA[X1 => 1],
SA[rn.X1 => 1],
SA[:X1 => 1],
Dict([X1 => 1]),
Dict([rn.X1 => 1]),
Dict([:X1 => 1]),
(X1 => 1),
(rn.X1 => 1),
(:X1 => 1),
]
ps_invalid = [
[k1 => 1.0],
[rn.k1 => 1.0],
[:k1 => 1.0],
SA[k1 => 1.0],
SA[rn.k1 => 1.0],
SA[:k1 => 1.0],
Dict([k1 => 1.0]),
Dict([rn.k1 => 1.0]),
Dict([:k1 => 1.0]),
(k1 => 1.0),
(rn.k1 => 1.0),
(:k1 => 1.0),
]

# Loops through all potential parameter sets, checking that their inputs yield errors.
for ps in [[ps_valid]; ps_invalid], u0 in [[u0_valid]; u0s_invalid]
# Handles all types of time-dependent systems. The `isequal` is because some case should pass.
for XProblem in [ODEProblem, SDEProblem, JumpProblem]
if isequal(ps, ps_valid) && isequal(u0, u0_valid)
XProblem(rn, u0, (0.0, 1.0), ps)
else
@test_throws Exception XProblem(rn, u0, (0.0, 1.0), ps)
end
end

# Handles all types of not time-dependent systems. The `isequal` is because some case should pass.
for XProblem in [NonlinearProblem, SteadyStateProblem]
if isequal(ps, ps_valid) && isequal(u0, u0_valid)
XProblem(rn, u0, ps)
else
@test_throws Exception XProblem(rn, u0, ps)
end
end
end
end
# Disabled: MTKBase v1.23+ uses least-squares fallback for underdetermined initialization
# instead of erroring on incomplete u0/parameter inputs.
# @test_broken let
# # Declares the model.
# rn = @reaction_network begin
# (k1,k2), X1 <--> X2
# end
# @unpack k1, k2, X1, X2 = rn
#
# # Declares valid initial conditions and parameter values
# u0_valid = [X1 => 1, X2 => 2]
# ps_valid = [k1 => 0.5, k2 => 0.1]
#
# # Declares invalid initial conditions and parameters. Currently, this only includes cases
# # where at least one value is missing. Includes vector/Tuple/Dict forms.
# u0s_invalid = [
# [X1 => 1],
# [rn.X1 => 1],
# [:X1 => 1],
# SA[X1 => 1],
# SA[rn.X1 => 1],
# SA[:X1 => 1],
# Dict([X1 => 1]),
# Dict([rn.X1 => 1]),
# Dict([:X1 => 1]),
# (X1 => 1),
# (rn.X1 => 1),
# (:X1 => 1),
# ]
# ps_invalid = [
# [k1 => 1.0],
# [rn.k1 => 1.0],
# [:k1 => 1.0],
# SA[k1 => 1.0],
# SA[rn.k1 => 1.0],
# SA[:k1 => 1.0],
# Dict([k1 => 1.0]),
# Dict([rn.k1 => 1.0]),
# Dict([:k1 => 1.0]),
# (k1 => 1.0),
# (rn.k1 => 1.0),
# (:k1 => 1.0),
# ]
#
# # Loops through all potential parameter sets, checking that their inputs yield errors.
# for ps in [[ps_valid]; ps_invalid], u0 in [[u0_valid]; u0s_invalid]
# # Handles all types of time-dependent systems. The `isequal` is because some case should pass.
# for XProblem in [ODEProblem, SDEProblem, JumpProblem]
# if isequal(ps, ps_valid) && isequal(u0, u0_valid)
# XProblem(rn, u0, (0.0, 1.0), ps)
# else
# @test_throws Exception XProblem(rn, u0, (0.0, 1.0), ps)
# end
# end
#
# # Handles all types of not time-dependent systems. The `isequal` is because some case should pass.
# for XProblem in [NonlinearProblem, SteadyStateProblem]
# if isequal(ps, ps_valid) && isequal(u0, u0_valid)
# XProblem(rn, u0, ps)
# else
# @test_throws Exception XProblem(rn, u0, ps)
# end
# end
# end
# end
Loading