Skip to content

Commit 2ac4a3c

Browse files
committed
Use isapprox(x1, x2; atol=1e-10) instead of high solver tolerances
1 parent e230b8c commit 2ac4a3c

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

test/miscellaneous_tests/nonlinear_solve.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ let
2525
nl_prob = NonlinearProblem(steady_state_network_1, u0, p)
2626

2727
# Solves it using standard algorithm and simulation based algorithm.
28-
sol1 = solve(nl_prob; abstol=1e-15, reltol=1e-15).u
29-
sol2 = solve(nl_prob, DynamicSS(Tsit5(); abstol=1e-15, reltol=1e-15); abstol=1e-15, reltol=1e-15).u
28+
sol1 = solve(nl_prob; abstol=1e-12, reltol=1e-12).u
29+
sol2 = solve(nl_prob, DynamicSS(Rosenbrock23(); abstol=1e-12, reltol=1e-12); abstol=1e-12, reltol=1e-12).u
3030

3131
# Tests solutions are correct.
32-
@test abs.(sol1[1] - p[1] / p[2]) < 1e-8
33-
@test abs.(sol1[2]^3 / factorial(3) - p[3] / p[4]) < 1e-8
34-
@test abs.(sol1[3] * sol1[4] - p[5] / p[6]) < 1e-8
35-
@test sol1 sol2
32+
@test isapprox(sol1[1], p[1] / p[2]; atol=1e-10)
33+
@test isapprox(sol1[2]^3 / factorial(3), p[3] / p[4]; atol=1e-10)
34+
@test isapprox(sol1[3] * sol1[4], p[5] / p[6]; atol=1e-10)
35+
@test isapprox(sol1, sol2; atol=1e-10)
3636
end
3737

3838
# Creates a system with multiple steady states.
@@ -52,8 +52,8 @@ let
5252
nl_prob = NonlinearProblem(steady_state_network_2, u0, p)
5353

5454
# Solves it using standard algorithm and simulation based algorithm.
55-
sol1 = solve(nl_prob; abstol=1e-18, reltol=1e-18).u
56-
sol2 = solve(nl_prob, DynamicSS(Tsit5(); abstol=1e-18, reltol=1e-18); abstol=1e-18, reltol=1e-18).u
55+
sol1 = solve(nl_prob; abstol=1e-12, reltol=1e-12).u
56+
sol2 = solve(nl_prob, DynamicSS(Rosenbrock23(); abstol=1e-12, reltol=1e-12); abstol=1e-12, reltol=1e-12).u
5757

5858
# Computes NonlinearFunction (manually and automatically).
5959
nfunc = NonlinearFunction(convert(NonlinearSystem, steady_state_network_2))
@@ -64,10 +64,10 @@ let
6464
end
6565

6666
# Tests solutions are correct.
67-
@test nfunc(sol1, last.(p))[1] 0.0
68-
@test nfunc(sol2, last.(p))[1] 0.0
69-
@test nf_manual(sol1, last.(p)) 0.0
70-
@test nf_manual(sol2, last.(p)) 0.0
67+
@test isapprox(nfunc(sol1, last.(p))[1], 0.0; atol=1e-10)
68+
@test isapprox(nfunc(sol2, last.(p))[1], 0.0; atol=1e-10)
69+
@test isapprox(nf_manual(sol1, last.(p)), 0.0; atol=1e-10)
70+
@test isapprox(nf_manual(sol2, last.(p)), 0.0; atol=1e-10)
7171
end
7272

7373
# Checks for system with conservation laws.
@@ -88,11 +88,11 @@ let
8888
nl_prob_2 = NonlinearProblem(steady_state_network_3, u0, p)
8989

9090
# Solves it using standard algorithm and simulation based algorithm.
91-
sol1 = solve(nl_prob_1; abstol=1e-18, reltol=1e-18)
92-
sol2 = solve(nl_prob_2, DynamicSS(Tsit5(); abstol=1e-18, reltol=1e-18); abstol=1e-18, reltol=1e-18)
91+
sol1 = solve(nl_prob_1; abstol=1e-12, reltol=1e-12)
92+
sol2 = solve(nl_prob_2, DynamicSS(Rosenbrock23(); abstol=1e-12, reltol=1e-12); abstol=1e-12, reltol=1e-12)
9393

9494
# Checks output using NonlinearFunction.
9595
nfunc = NonlinearFunction(convert(NonlinearSystem, steady_state_network_3))
96-
@test all(nfunc([sol1[X], sol1[Y], sol1[Y2], sol1[XY2]], last.(p)) .≈ 0.0)
97-
@test all(nfunc([sol2[X], sol2[Y], sol2[Y2], sol2[XY2]], last.(p)) .≈ 0.0)
96+
@test isapprox(nfunc([sol1[X], sol1[Y], sol1[Y2], sol1[XY2]], last.(p)), [0.0, 0.0, 0.0, 0.0]; atol=1e-10)
97+
@test isapprox(nfunc([sol2[X], sol2[Y], sol2[Y2], sol2[XY2]], last.(p)), [0.0, 0.0, 0.0, 0.0]; atol=1e-10)
9898
end

0 commit comments

Comments
 (0)