@@ -83,9 +83,10 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = false)
8383prob = ODEProblem (sys, u0, (0 , 11.5 ), sparse = true , jac = true )
8484@test eltype (prob. f. jac_prototype) == Float32
8585
86+ t = ModelingToolkit. t_nounits
87+ D = ModelingToolkit. D_nounits
88+
8689@testset " W matrix sparsity" begin
87- t = ModelingToolkit. t_nounits
88- D = ModelingToolkit. D_nounits
8990 @parameters g
9091 @variables x (t) y (t) λ (t)
9192 eqs = [D (D (x)) ~ λ * x
@@ -116,3 +117,20 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = true)
116117 @test W! (similar (W_prototype, Float64), u, p, γ, t) ==
117118 0.1 * M + jac! (similar (W_prototype, Float64), u, p, t)
118119end
120+
121+ @testset " Issue#3556: Numerical accuracy" begin
122+ @parameters g
123+ @variables x (t) y (t) [state_priority = 10 ] λ (t)
124+ eqs = [D (D (x)) ~ λ * x
125+ D (D (y)) ~ λ * y - g
126+ x^ 2 + y^ 2 ~ 1 ]
127+ @mtkbuild pend = ODESystem (eqs, t)
128+ prob = ODEProblem (pend, [x => 0.0 , D (x) => 1.0 ], (0.0 , 1.0 ), [g => 1.0 ];
129+ guesses = [y => 1.0 , λ => 1.0 ], jac = true , sparse = true )
130+ J = deepcopy (prob. f. jac_prototype)
131+ prob. f. jac (J, prob. u0, prob. p, 1.0 )
132+ # this currently works but may not continue to do so
133+ # see https://github.com/SciML/ModelingToolkit.jl/pull/3556#issuecomment-2792664039
134+ @test J == prob. f. jac (prob. u0, prob. p, 1.0 )
135+ @test J ≈ prob. f. jac (prob. u0, prob. p, 1.0 )
136+ end
0 commit comments