@@ -45,29 +45,24 @@ sol = solve(prob2, Rosenbrock23(autodiff = AutoFiniteDiff()))
4545@test ≈ (good_sol[:, end ], sol[:, end ], rtol = 1.0e-2 )
4646
4747# Regression test for issue #3232:
48- # OrdinaryDiffEqLinearExponentialAlgorithm subtypes (MagnusGL6, etc.)
49- # have no `autodiff` field; _alg_autodiff and prepare_alg must not crash.
50- using OrdinaryDiffEqDifferentiation: _alg_autodiff
51- using OrdinaryDiffEqCore: OrdinaryDiffEqLinearExponentialAlgorithm
52- using DiffEqBase: prepare_alg
53-
54- struct MockMagnusAlg <: OrdinaryDiffEqLinearExponentialAlgorithm
55- krylov:: Bool
56- m:: Int
57- iop:: Int
58- end
59-
60- @testset " LinearExponentialAlgorithm autodiff traits (issue #3232)" begin
61- mock = MockMagnusAlg (false , 30 , 0 )
62-
63- # _alg_autodiff must return Val{false}() instead of accessing alg.autodiff
64- @test _alg_autodiff (mock) == Val {false} ()
65-
66- # prepare_alg must return the algorithm unchanged (no AD preparation needed)
67- u0 = ones (2 )
68- mock_prob = ODEProblem ((du, u, p, t) -> du .= 0 , u0, (0.0 , 1.0 ))
69- @test prepare_alg (mock, u0, nothing , mock_prob) === mock
70-
71- # forwarddiffs_model must return false
72- @test SciMLBase. forwarddiffs_model (mock) == false
48+ # MagnusGL6 (and all OrdinaryDiffEqLinearExponentialAlgorithm subtypes)
49+ # have no `autodiff` field. When OrdinaryDiffEqDifferentiation is loaded,
50+ # _alg_autodiff must not crash by trying to access alg.autodiff.
51+ using OrdinaryDiffEqLinear
52+ using SciMLOperators: MatrixOperator
53+
54+ @testset " MagnusGL6 solve with Differentiation loaded (issue #3232)" begin
55+ function update_func! (A, u, p, t)
56+ A[1 , 1 ] = cos (t)
57+ A[2 , 1 ] = sin (t)
58+ A[1 , 2 ] = - sin (t)
59+ A[2 , 2 ] = cos (t)
60+ end
61+ A = MatrixOperator (ones (2 , 2 ), update_func! = update_func!)
62+ prob = ODEProblem (A, ones (2 ), (1.0 , 6.0 ))
63+
64+ # This would crash with FieldError before the fix
65+ sol = solve (prob, MagnusGL6 (), dt = 1 / 10 )
66+ @test sol. retcode == ReturnCode. Success
67+ @test length (sol. t) > 1
7368end
0 commit comments