@@ -4,6 +4,7 @@ using Zygote
44using  SymbolicIndexingInterface
55using  SciMLStructures
66using  OrdinaryDiffEq
7+ using  NonlinearSolve
78using  SciMLSensitivity
89using  ForwardDiff
910using  ChainRulesCore
@@ -103,3 +104,23 @@ vals = (1.0f0, 3ones(Float32, 3))
103104tangent =  rand_tangent (ps)
104105fwd, back =  ChainRulesCore. rrule (remake_buffer, sys, ps, idxs, vals)
105106@inferred  back (tangent)
107+ 
108+ @testset  " Dual type promotion in remake with dummy derivatives"   begin  #  https://github.com/SciML/ModelingToolkit.jl/issues/3336
109+     #  Throw ball straight up into the air
110+     @variables  y (t)
111+     eqs =  [D (D (y)) ~  - 9.81 ]
112+     initialization_eqs =  [y^ 2  ~  0 ] #  initialize y = 0 in a way that builds an initialization problem
113+     @named  sys =  ODESystem (eqs, t; initialization_eqs)
114+     sys =  structural_simplify (sys)
115+ 
116+     #  Find initial throw velocity that reaches exactly 10 m after 1 s
117+     dprob0 =  ODEProblem (sys, [D (y) =>  NaN ], (0.0 , 1.0 ), []; guesses =  [y =>  0.0 ])
118+     function  f (ics, _)
119+         dprob =  remake (dprob0, u0 =  Dict (D (y) =>  ics[1 ]))
120+         dsol =  solve (dprob, Tsit5 ())
121+         return  [dsol[y][end ] -  10.0 ]
122+     end 
123+     nprob =  NonlinearProblem (f, [1.0 ])
124+     nsol =  solve (nprob, NewtonRaphson ())
125+     @test  nsol[1 ] ≈  10.0  /  1.0  +  9.81  *  1.0  /  2  #  anal free fall solution is y = v0*t - g*t^2/2 -> v0 = y/t + g*t/2
126+ end 
0 commit comments