@@ -3,10 +3,11 @@ using Test
33
44mirk_ad_group () = get (ENV , " BOUNDARYVALUEDIFFEQ_MIRK_AD_GROUP" , " ALL" )
55run_mirk_ad_group (group) = mirk_ad_group () in (" ALL" , group)
6+ mirk_ad_backend () = get (ENV , " BOUNDARYVALUEDIFFEQ_MIRK_AD_BACKEND" , " ALL" )
7+ run_mirk_ad_backend (backend) = mirk_ad_backend () in (" ALL" , backend)
68
79@testset " Different AD compatibility" begin
810 using BoundaryValueDiffEqMIRK
9- using ForwardDiff, Enzyme, Mooncake
1011
1112 if run_mirk_ad_group (" MULTIPOINT_GRID" )
1213 @testset " Test different AD on multipoint BVP" begin
@@ -23,22 +24,38 @@ run_mirk_ad_group(group) = mirk_ad_group() in ("ALL", group)
2324 u0 = [pi / 2 , pi / 2 ]
2425 tspan = (0.0 , pi / 2 )
2526 prob = BVProblem (simplependulum!, bc!, u0, tspan)
26- jac_alg_forwarddiff = BVPJacobianAlgorithm (
27- bc_diffmode = AutoSparse (AutoForwardDiff ()), nonbc_diffmode = AutoForwardDiff ()
28- )
29- jac_alg_enzyme = BVPJacobianAlgorithm (
30- bc_diffmode = AutoSparse (
31- AutoEnzyme (
32- mode = Enzyme. Reverse, function_annotation = Enzyme. Duplicated
27+
28+ if run_mirk_ad_backend (" FORWARDDIFF" )
29+ using ForwardDiff
30+ jac_alg = BVPJacobianAlgorithm (
31+ bc_diffmode = AutoSparse (AutoForwardDiff ()), nonbc_diffmode = AutoForwardDiff ()
32+ )
33+ sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.05 )
34+ @test SciMLBase. successful_retcode (sol)
35+ end
36+ if run_mirk_ad_backend (" ENZYME" )
37+ using Enzyme
38+ jac_alg = BVPJacobianAlgorithm (
39+ bc_diffmode = AutoSparse (
40+ AutoEnzyme (
41+ mode = Enzyme. Reverse, function_annotation = Enzyme. Duplicated
42+ )
43+ ),
44+ nonbc_diffmode = AutoEnzyme (
45+ mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated
3346 )
34- ),
35- nonbc_diffmode = AutoEnzyme (mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated)
36- )
37- jac_alg_mooncake = BVPJacobianAlgorithm (
38- bc_diffmode = AutoSparse (AutoMooncake (; config = nothing )),
39- nonbc_diffmode = AutoEnzyme (mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated)
40- )
41- for jac_alg in [jac_alg_forwarddiff, jac_alg_enzyme, jac_alg_mooncake]
47+ )
48+ sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.05 )
49+ @test SciMLBase. successful_retcode (sol)
50+ end
51+ if run_mirk_ad_backend (" MOONCAKE" )
52+ using Enzyme, Mooncake
53+ jac_alg = BVPJacobianAlgorithm (
54+ bc_diffmode = AutoSparse (AutoMooncake (; config = nothing )),
55+ nonbc_diffmode = AutoEnzyme (
56+ mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated
57+ )
58+ )
4259 sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.05 )
4360 @test SciMLBase. successful_retcode (sol)
4461 end
@@ -60,22 +77,38 @@ run_mirk_ad_group(group) = mirk_ad_group() in ("ALL", group)
6077 u0 = [pi / 2 , pi / 2 ]
6178 tspan = (0.0 , pi / 2 )
6279 prob = BVProblem (simplependulum!, bc!, u0, tspan)
63- jac_alg_forwarddiff = BVPJacobianAlgorithm (
64- bc_diffmode = AutoSparse (AutoForwardDiff ()), nonbc_diffmode = AutoForwardDiff ()
65- )
66- jac_alg_enzyme = BVPJacobianAlgorithm (
67- bc_diffmode = AutoSparse (
68- AutoEnzyme (
69- mode = Enzyme. Reverse, function_annotation = Enzyme. Duplicated
80+
81+ if run_mirk_ad_backend (" FORWARDDIFF" )
82+ using ForwardDiff
83+ jac_alg = BVPJacobianAlgorithm (
84+ bc_diffmode = AutoSparse (AutoForwardDiff ()), nonbc_diffmode = AutoForwardDiff ()
85+ )
86+ sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.05 )
87+ @test SciMLBase. successful_retcode (sol)
88+ end
89+ if run_mirk_ad_backend (" ENZYME" )
90+ using Enzyme
91+ jac_alg = BVPJacobianAlgorithm (
92+ bc_diffmode = AutoSparse (
93+ AutoEnzyme (
94+ mode = Enzyme. Reverse, function_annotation = Enzyme. Duplicated
95+ )
96+ ),
97+ nonbc_diffmode = AutoEnzyme (
98+ mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated
7099 )
71- ),
72- nonbc_diffmode = AutoEnzyme (mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated)
73- )
74- jac_alg_mooncake = BVPJacobianAlgorithm (
75- bc_diffmode = AutoSparse (AutoMooncake (; config = nothing )),
76- nonbc_diffmode = AutoEnzyme (mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated)
77- )
78- for jac_alg in [jac_alg_forwarddiff, jac_alg_enzyme, jac_alg_mooncake]
100+ )
101+ sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.05 )
102+ @test SciMLBase. successful_retcode (sol)
103+ end
104+ if run_mirk_ad_backend (" MOONCAKE" )
105+ using Enzyme, Mooncake
106+ jac_alg = BVPJacobianAlgorithm (
107+ bc_diffmode = AutoSparse (AutoMooncake (; config = nothing )),
108+ nonbc_diffmode = AutoEnzyme (
109+ mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated
110+ )
111+ )
79112 sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.05 )
80113 @test SciMLBase. successful_retcode (sol)
81114 end
@@ -103,22 +136,34 @@ run_mirk_ad_group(group) = mirk_ad_group() in ("ALL", group)
103136 odef!, (boundary_two_point_a!, boundary_two_point_b!),
104137 u0, tspan; bcresid_prototype, nlls = Val (false )
105138 )
106- jac_alg_forwarddiff = BVPJacobianAlgorithm (AutoSparse (AutoForwardDiff ()))
107- jac_alg_enzyme = BVPJacobianAlgorithm (
108- AutoSparse (
109- AutoEnzyme (
110- mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated
139+
140+ if run_mirk_ad_backend (" FORWARDDIFF" )
141+ using ForwardDiff
142+ jac_alg = BVPJacobianAlgorithm (AutoSparse (AutoForwardDiff ()))
143+ sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.01 )
144+ @test SciMLBase. successful_retcode (sol)
145+ end
146+ if run_mirk_ad_backend (" ENZYME" )
147+ using Enzyme
148+ jac_alg = BVPJacobianAlgorithm (
149+ AutoSparse (
150+ AutoEnzyme (
151+ mode = Enzyme. Forward, function_annotation = Enzyme. Duplicated
152+ )
111153 )
112154 )
113- )
114- jac_alg_mooncake = BVPJacobianAlgorithm (
115- AutoSparse (
116- AutoMooncake (;
117- config = nothing
155+ sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.01 )
156+ @test SciMLBase. successful_retcode (sol)
157+ end
158+ if run_mirk_ad_backend (" MOONCAKE" )
159+ using Mooncake
160+ jac_alg = BVPJacobianAlgorithm (
161+ AutoSparse (
162+ AutoMooncake (;
163+ config = nothing
164+ )
118165 )
119166 )
120- )
121- for jac_alg in [jac_alg_forwarddiff, jac_alg_enzyme, jac_alg_mooncake]
122167 sol = solve (prob, MIRK4 (; jac_alg = jac_alg), dt = 0.01 )
123168 @test SciMLBase. successful_retcode (sol)
124169 end
0 commit comments