Skip to content

Commit c11452c

Browse files
Move interface tests to OrdinaryDiffEqDifferentiation and OrdinaryDiffEqNonlinearSolve
Move tests from the global test suite to their respective subpackages so they only run when the relevant subpackage changes, reducing CI cost. Tests moved to OrdinaryDiffEqDifferentiation: - differentiation_traits_tests.jl (from InterfaceI) - autodiff_error_tests.jl (from InterfaceIV) - nojac_tests.jl (from InterfaceIII) Tests moved to OrdinaryDiffEqNonlinearSolve: - linear_nonlinear_tests.jl (from InterfaceII) - linear_solver_tests.jl (from InterfaceII) - linear_solver_split_ode_tests.jl (from InterfaceII) - mass_matrix_tests.jl (from InterfaceII) - wprototype_tests.jl (from InterfaceII) - dae_initialization_tests.jl (from InterfaceV) - checkinit_tests.jl (from InterfaceII) Tests kept in global suite (require special envs): - autosparse_detection_tests.jl (SparseConnectivityTracer dep conflict) - gpu_autodiff_interface_tests.jl (GPU env) - nonfulldiagonal_sparse.jl (ComponentArrays dep) - AD tests (Enzyme/Zygote/Mooncake env) - ModelingToolkit tests (downstream dep) Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 345aaf0 commit c11452c

15 files changed

+1670
-12
lines changed

lib/OrdinaryDiffEqDifferentiation/Project.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ uuid = "4302a76b-040a-498a-8c04-15b101fed76b"
44
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>", "Yingbo Ma <mayingbo5@gmail.com>"]
55

66
[targets]
7-
test = ["DiffEqDevTools", "OrdinaryDiffEqSDIRK", "Random", "SafeTestsets", "Test", "SparseArrays", "Pkg"]
7+
test = ["DiffEqDevTools", "OrdinaryDiffEqBDF", "OrdinaryDiffEqRosenbrock", "OrdinaryDiffEqSDIRK", "Random", "RecursiveFactorization", "SafeTestsets", "Test", "SparseArrays", "Pkg"]
88

99
[compat]
1010
Pkg = "1"
@@ -22,7 +22,10 @@ ConstructionBase = "1.5.8"
2222
LinearAlgebra = "1.10"
2323
SciMLBase = "2.141"
2424
OrdinaryDiffEqCore = "3"
25+
OrdinaryDiffEqBDF = "1"
26+
OrdinaryDiffEqRosenbrock = "1"
2527
OrdinaryDiffEqSDIRK = "1"
28+
RecursiveFactorization = "0.2, 1"
2629
SparseArrays = "1.10"
2730
ConcreteStructs = "0.2"
2831
Aqua = "0.8.11"
@@ -69,12 +72,21 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
6972
DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
7073
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
7174
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
75+
OrdinaryDiffEqBDF = "6ad6398a-0878-4a85-9266-38940aa047c8"
76+
OrdinaryDiffEqRosenbrock = "43230ef6-c299-4910-a778-202eb28ce4ce"
7277
OrdinaryDiffEqSDIRK = "2d112036-d095-4a1e-ab9a-08536f3ecdbf"
78+
RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4"
7379
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
7480

7581
[sources.OrdinaryDiffEqCore]
7682
path = "../OrdinaryDiffEqCore"
7783

84+
[sources.OrdinaryDiffEqBDF]
85+
path = "../OrdinaryDiffEqBDF"
86+
87+
[sources.OrdinaryDiffEqRosenbrock]
88+
path = "../OrdinaryDiffEqRosenbrock"
89+
7890
[sources.OrdinaryDiffEqSDIRK]
7991
path = "../OrdinaryDiffEqSDIRK"
8092

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using OrdinaryDiffEqRosenbrock, OrdinaryDiffEqSDIRK, OrdinaryDiffEqBDF, Test, ADTypes
2+
using OrdinaryDiffEqDifferentiation
3+
4+
const a = Float64[1.0]
5+
6+
function lorenz(u, p, t)
7+
du1 = 10.0(u[2] - u[1])
8+
a[1] = u[2]
9+
du2 = u[1] * (28.0 - u[3]) - u[2]
10+
du3 = u[1] * u[2] - (8 / 3) * u[3]
11+
return [du1, du2, du3]
12+
end
13+
u0 = [1.0; 0.0; 0.0]
14+
tspan = (0.0, 1.0)
15+
prob = ODEProblem(lorenz, u0, tspan)
16+
@test_throws OrdinaryDiffEqDifferentiation.FirstAutodiffJacError solve(prob, Rosenbrock23())
17+
18+
function lorenz(u, p, t)
19+
du1 = 10.0(u[2] - u[1])
20+
a[1] = t
21+
du2 = u[1] * (28.0 - u[3]) - u[2]
22+
du3 = u[1] * u[2] - (8 / 3) * u[3]
23+
return [du1, du2, du3]
24+
end
25+
@test_throws OrdinaryDiffEqDifferentiation.FirstAutodiffTgradError solve(
26+
prob, Rosenbrock23()
27+
)
28+
29+
function lorenz!(du, u, p, t)
30+
du[1] = 10.0(u[2] - u[1])
31+
a[1] = u[2]
32+
du[2] = u[1] * (28.0 - u[3]) - u[2]
33+
return du[3] = u[1] * u[2] - (8 / 3) * u[3]
34+
end
35+
u0 = [1.0; 0.0; 0.0]
36+
tspan = (0.0, 1.0)
37+
prob = ODEProblem(lorenz!, u0, tspan)
38+
@test_throws OrdinaryDiffEqDifferentiation.FirstAutodiffJacError solve(prob, Rosenbrock23())
39+
40+
function lorenz2!(du, u, p, t)
41+
du[1] = 10.0(u[2] - u[1])
42+
a[1] = t
43+
du[2] = u[1] * (28.0 - u[3]) - u[2]
44+
return du[3] = u[1] * u[2] - (8 / 3) * u[3]
45+
end
46+
prob = ODEProblem(lorenz2!, u0, tspan)
47+
@test_throws OrdinaryDiffEqDifferentiation.FirstAutodiffTgradError solve(
48+
prob, Rosenbrock23()
49+
)
50+
51+
## Test that nothing is using duals when autodiff=AutoFiniteDiff()
52+
## https://discourse.julialang.org/t/rodas4-using-dual-number-for-time-with-autodiff-false/98256
53+
54+
for alg in [
55+
Rosenbrock23(autodiff = AutoFiniteDiff()),
56+
Rodas4(autodiff = AutoFiniteDiff()),
57+
Rodas5(autodiff = AutoFiniteDiff()),
58+
QNDF(autodiff = AutoFiniteDiff()),
59+
TRBDF2(autodiff = AutoFiniteDiff()),
60+
KenCarp4(autodiff = AutoFiniteDiff()),
61+
]
62+
u = [0.0, 0.0]
63+
function f1(u, p, t)
64+
#display(typeof(t))
65+
du = zeros(2)
66+
du[1] = 0.1 * u[1] + 0.2 * u[2]
67+
du[2] = 0.1 * t
68+
return du
69+
end
70+
prob = ODEProblem(f1, u, (0.0, 1.0))
71+
sol = solve(prob, alg)
72+
73+
function f2(du, u, p, t)
74+
#display(typeof(t))
75+
du2 = zeros(2)
76+
du2[1] = 0.1 * u[1] + 0.2 * u[2]
77+
du2[2] = 0.1 * t
78+
return du .= du2
79+
end
80+
prob = ODEProblem(f2, u, (0.0, 1.0))
81+
sol = solve(prob, alg)
82+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using OrdinaryDiffEqRosenbrock, Test, ADTypes
2+
3+
jac_called = Ref(false)
4+
tgrad_called = Ref(false)
5+
6+
function Lotka(du, u, p, t)
7+
du[1] = u[1] - u[1] * u[2] # REPL[7], line 3:
8+
du[2] = -3 * u[2] + 1 * u[1] * u[2]
9+
return nothing
10+
end
11+
12+
function Lotka_jac(J, u, p, t)
13+
jac_called.x = true
14+
J[1, 1] = 1.0 - u[2]
15+
J[1, 2] = -u[1]
16+
J[2, 1] = 1 * u[2]
17+
J[2, 2] = -3 + u[1]
18+
return nothing
19+
end
20+
21+
function Lotka_tgrad(grad, u, p, t)
22+
tgrad_called.x = true
23+
grad[1] = 1 * 0
24+
grad[2] = 1 * 0
25+
return nothing
26+
end
27+
28+
Lotka_f = ODEFunction(Lotka, jac = Lotka_jac, tgrad = Lotka_tgrad)
29+
prob = ODEProblem(Lotka_f, ones(2), (0.0, 10.0))
30+
31+
good_sol = solve(prob, Rosenbrock23())
32+
33+
@test jac_called[]
34+
@test tgrad_called[]
35+
36+
prob2 = ODEProblem(Lotka, ones(2), (0.0, 10.0))
37+
38+
sol = solve(prob2, Rosenbrock23(autodiff = AutoForwardDiff()))
39+
@test (good_sol[:, end], sol[:, end], rtol = 1.0e-2)
40+
41+
sol = solve(prob2, Rosenbrock23(autodiff = AutoForwardDiff(chunksize = 1)))
42+
@test (good_sol[:, end], sol[:, end], rtol = 1.0e-2)
43+
44+
sol = solve(prob2, Rosenbrock23(autodiff = AutoFiniteDiff()))
45+
@test (good_sol[:, end], sol[:, end], rtol = 1.0e-2)

0 commit comments

Comments
 (0)