# How can I check if step!() was successful?

**URL:** <https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581>\
**Category:** General Usage\
**Tags:** question, package, differentialequation\
**Created:** [February 5, 2025, 2:55pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581 "2025-02-05T14:55:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [February 5, 2025, 2:55pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581/1 "2025-02-05T14:55:31Z")

</div>

In my code I have the line:

```julia
  OrdinaryDiffEqCore.step!(integrator, dt, true)

```

Normally it works, but sometimes it doesn’t. How can I check if an error occurred, and if yes which one?

The integrator was created using:

```julia
solver = DFBDF(autodiff=AutoFiniteDiff(), max_order=Val{s.set.max_order}())  
differential_vars = ones(Bool, length(y0))
prob = DAEProblem{true}(residual!, yd0, y0, tspan, s; differential_vars)
integrator = OrdinaryDiffEqCore.init(prob, solver; abstol=abstol, reltol=s.set.rel_tol, save_everystep=false)

```

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 5, 2025, 3:03pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581/2 "2025-02-05T15:03:21Z")

</div>

`SciMLBase.successful_retcode(integrator.sol)` works. We could make `step!` return a bool for whether it succeeds.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [February 5, 2025, 3:13pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581/3 "2025-02-05T15:13:07Z")

</div>

OK, I get the following error:

```julia
julia> integrator.sol.retcode
ReturnCode.InitialFailure = 8

```

What could be the reason?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 5, 2025, 3:16pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581/4 "2025-02-05T15:16:21Z")

</div>

This means that initialization didn’t succeed. A DAE is of the form `0 = f(du, u, p, t)` so when you call `init` on a DAE, the solver needs to make the initial conditions satisfy this. The default initialization alg is `BrownFullBasicInit` [Mass Matrix and Fully Implicit DAE Solvers · DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/solvers/dae_solve/#Initialization-Schemes) explains (briefly) what the different options are.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [February 5, 2025, 3:19pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581/5 "2025-02-05T15:19:32Z")

</div>

To which function do I have to supply this: `For all OrdinaryDiffEq.jl methods, an initialization scheme can be set with a common keyword argument initializealg. `?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 5, 2025, 3:22pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581/6 "2025-02-05T15:22:31Z")

</div>

`init`

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [February 5, 2025, 3:28pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581/7 "2025-02-05T15:28:48Z")

</div>

Not yet working:

```julia
   integrator = OrdinaryDiffEqCore.init(prob, solver; abstol=abstol, reltol=s.set.rel_tol, save_everystep=false, initializealg=OrdinaryDiffEqCore.ShampineCollocationInit)

```

Gives the error:

```julia
Failed to precompile KiteModels [b94af626-7959-4878-9336-2adc27959007] to "/home/ufechner/.julia/compiled/v1.10/KiteModels/jl_0YvmuR".
ERROR: LoadError: MethodError: no method matching _initialize_dae!(::OrdinaryDiffEqCore.ODEIntegrator{OrdinaryDiffEqBDF.DFBDF{4, 0, ADTypes.AutoFiniteDiff{Val{:forward}, Val{:forward}, Val{:hcentral}, Nothing, Nothing}, Nothing, OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}(), true, nothing, Nothing, Nothing}, true, Vector{Float64}, Vector{Float64}, Float64, KiteModels.KPS3{Float64, StaticArraysCore.MVector{3, Float64}, 7}, Float64, Float64, Float64, Float64, Vector{Vector{Float64}}, SciMLBase.DAESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Nothing, Vector{Float64}, SciMLBase.DAEProblem{Vector{Float64}, Vector{Float64}, Tuple{Float64, Float64}, true, KiteModels.KPS3{Float64, StaticArraysCore.MVector{3, Float64}, 7}, SciMLBase.DAEFunction{true, SciMLBase.FullSpecialize, typeof(KiteModels.residual!), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}, Vector{Bool}}, OrdinaryDiffEqBDF.DFBDF{4, 0, ADTypes.AutoFiniteDiff{Val{:forward}, Val{:forward}, Val{:hcentral}, Nothing, Nothing}, Nothing, OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, typeof(OrdinaryDiffEqCore.DEFAULT_PRECS), Val{:forward}(), true, nothing, Nothing, Nothing}, OrdinaryDiffEqCore.InterpolationData{SciMLBase.DAEFunction{true, SciMLBase.FullSpecialize, typeof(KiteModels.residual!), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing}, Vector{Vector{Float64}}, Vector{Float64}, Vector{Vector{Vector{Float64}}}, Nothing, OrdinaryDiffEqBDF.DFBDFCache{5, OrdinaryDiffEqNonlinearSolve.NLSolver{OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, true, Vector{Float64}, Float64, Nothing, Float64, OrdinaryDiffEqNonlinearSolve.NLNewtonCache{Vector{Float64}, Float64, Float64, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEqNonlinearSolve.DAEResidualJacobianWrapper{false, SciMLBase.DAEFunction{true, SciMLBase.FullSpecialize, typeof(KiteModels.residual!), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing}, KiteModels.KPS3{Float64, StaticArraysCore.MVector{3, Float64}, 7}, Vector{Float64}, Vector{Float64}, Int64, Float64, Vector{Float64}, Vector{Float64}, Float64}, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, LinearSolve.LinearCache{Matrix{Float64}, Vector{Float64}, Vector{Float64}, SciMLBase.NullParameters, LinearSolve.DefaultLinearSolver, LinearSolve.DefaultLinearSolverInit{LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, LinearAlgebra.QRCompactWY{Float64, Matrix{Float64}, Matrix{Float64}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, Tuple{LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, Vector{Int64}}, Nothing, Nothing, Nothing, LinearAlgebra.SVD{Float64, Float64, Matrix{Float64}, Vector{Float64}}, LinearAlgebra.Cholesky{Float64, Matrix{Float64}}, LinearAlgebra.Cholesky{Float64, Matrix{Float64}}, Tuple{LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int32}}, Base.RefValue{Int32}}, Tuple{LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, Base.RefValue{Int64}}, LinearAlgebra.QRPivoted{Float64, Matrix{Float64}, Vector{Float64}, Vector{Int64}}, Nothing, Nothing}, LinearSolve.InvPreconditioner{LinearAlgebra.Diagonal{Float64, Vector{Float64}}}, LinearAlgebra.Diagonal{Float64, Vector{Float64}}, Float64, Bool, LinearSolve.LinearSolveAdjoint{Missing}}}, Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}, Matrix{Float64}, StaticArraysCore.SMatrix{5, 6, Rational{Int64}, 30}, Float64, Vector{Float64}, Vector{Float64}}, Vector{Bool}}, SciMLBase.DEStats, Vector{Vector{Vector{Float64}}}, Nothing}, SciMLBase.DAEFunction{true, SciMLBase.FullSpecialize, typeof(KiteModels.residual!), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing}, OrdinaryDiffEqBDF.DFBDFCache{5, OrdinaryDiffEqNonlinearSolve.NLSolver{OrdinaryDiffEqNonlinearSolve.NLNewton{Rational{Int64}, Rational{Int64}, Rational{Int64}, Rational{Int64}}, true, Vector{Float64}, Float64, Nothing, Float64, OrdinaryDiffEqNonlinearSolve.NLNewtonCache{Vector{Float64}, Float64, Float64, Vector{Float64}, Matrix{Float64}, Matrix{Float64}, OrdinaryDiffEqNonlinearSolve.DAEResidualJacobianWrapper{false, SciMLBase.DAEFunction{true, SciMLBase.FullSpecialize, typeof(KiteModels.residual!), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing}, KiteModels.KPS3{Float64, StaticArraysCore.MVector{3, Float64}, 7}, Vector{Float64}, Vector{Float64}, Int64, Float64, Vector{Float64}, Vector{Float64}, Float64}, FiniteDiff.JacobianCache{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, UnitRange{Int64}, Nothing, Val{:forward}(), Float64}, LinearSolve.LinearCache{Matrix{Float64}, Vector{Float64}, Vector{Float64}, SciMLBase.NullParameters, LinearSolve.DefaultLinearSolver, LinearSolve.DefaultLinearSolverInit{LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, LinearAlgebra.QRCompactWY{Float64, Matrix{Float64}, Matrix{Float64}}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, Tuple{LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, Vector{Int64}}, Nothing, Nothing, Nothing, LinearAlgebra.SVD{Float64, Float64, Matrix{Float64}, Vector{Float64}}, LinearAlgebra.Cholesky{Float64, Matrix{Float64}}, LinearAlgebra.Cholesky{Float64, Matrix{Float64}}, Tuple{LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int32}}, Base.RefValue{Int32}}, Tuple{LinearAlgebra.LU{Float64, Matrix{Float64}, Vector{Int64}}, Base.RefValue{Int64}}, LinearAlgebra.QRPivoted{Float64, Matrix{Float64}, Vector{Float64}, Vector{Int64}}, Nothing, Nothing}, LinearSolve.InvPreconditioner{LinearAlgebra.Diagonal{Float64, Vector{Float64}}}, LinearAlgebra.Diagonal{Float64, Vector{Float64}}, Float64, Bool, LinearSolve.LinearSolveAdjoint{Missing}}}, Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}, Matrix{Float64}, StaticArraysCore.SMatrix{5, 6, Rational{Int64}, 30}, Float64, Vector{Float64}, Vector{Float64}}, OrdinaryDiffEqCore.DEOptions{Float64, Float64, Float64, Float64, OrdinaryDiffEqCore.PIController{Rational{Int64}}, typeof(DiffEqBase.ODE_DEFAULT_NORM), typeof(LinearAlgebra.opnorm), Nothing, SciMLBase.CallbackSet{Tuple{}, Tuple{}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, DataStructures.BinaryHeap{Float64, DataStructures.FasterForward}, Nothing, Nothing, Int64, Tuple{}, Tuple{}, Tuple{}}, Vector{Float64}, Float64, Nothing, UnionAll, Vector{Bool}}, ::SciMLBase.DAEProblem{Vector{Float64}, Vector{Float64}, Tuple{Float64, Float64}, true, KiteModels.KPS3{Float64, StaticArraysCore.MVector{3, Float64}, 7}, SciMLBase.DAEFunction{true, SciMLBase.FullSpecialize, typeof(KiteModels.residual!), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}, Vector{Bool}}, ::Type{OrdinaryDiffEqCore.ShampineCollocationInit}, ::Val{true})

Closest candidates are:
  _initialize_dae!(::Any, ::SciMLBase.DAEProblem, ::OrdinaryDiffEqCore.ShampineCollocationInit, ::Val{true})
   @ OrdinaryDiffEqNonlinearSolve ~/.julia/packages/OrdinaryDiffEqNonlinearSolve/4nSEo/src/initialize_dae.jl:227
  _initialize_dae!(::Any, ::SciMLBase.DAEProblem, ::OrdinaryDiffEqCore.BrownFullBasicInit, ::Val{true})
   @ OrdinaryDiffEqNonlinearSolve ~/.julia/packages/OrdinaryDiffEqNonlinearSolve/4nSEo/src/initialize_dae.jl:517
  _initialize_dae!(::Any, ::SciMLBase.DAEProblem, ::OrdinaryDiffEqCore.DefaultInit, ::Val{true})
   @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/33WQj/src/initialize_dae.jl:83
  ...

```

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 5, 2025, 3:36pm UTC](https://discourse.julialang.org/t/how-can-i-check-if-step-was-successful/125581/8 "2025-02-05T15:36:32Z")

</div>

the docs clearly need some help :). It should be `integrator = OrdinaryDiffEqCore.init(prob, solver; abstol=abstol, reltol=s.set.rel_tol, save_everystep=false, initializealg=OrdinaryDiffEqCore.ShampineCollocationInit())`
