# What does "user\_cache: method has not been implemented for the integrator" mean?

**URL:** <https://discourse.julialang.org/t/what-does-user-cache-method-has-not-been-implemented-for-the-integrator-mean/19233>\
**Category:** New to Julia\
**Tags:** diffeq, error\
**Created:** [January 3, 2019, 2:30pm UTC](https://discourse.julialang.org/t/what-does-user-cache-method-has-not-been-implemented-for-the-integrator-mean/19233 "2019-01-03T14:30:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [January 3, 2019, 2:30pm UTC](https://discourse.julialang.org/t/what-does-user-cache-method-has-not-been-implemented-for-the-integrator-mean/19233/1 "2019-01-03T14:30:05Z")

</div>

I have been working through the example of a [Discrete Callback](http://docs.juliadiffeq.org/latest/features/diffeq_arrays.html#Example:-A-Control-Problem-1) that I need to adapt for my code but Atom generates an error. I cannot find a definition of user\_cache so I need your help. I am an introductory Julia user using Julia v.1, on Windows 10 and have updated all packages.

The error is:

> user\_cache: method has not been implemented for the integrator

The example code is

```julia
using DifferentialEquations
mutable struct SimType{T} <: DEDataVector{T}
    x::Array{T,1}
    f1::T
end
function f(du,u,p,t)
    du[1] = -0.5*u[1] + u.f1
    du[2] = -0.5*u[2]
end
const tstop1 = [5.]
const tstop2 = [8.]

function condition(u,t,integrator)
  t in tstop1
end

function condition2(u,t,integrator)
  t in tstop2
end
function affect!(integrator)
  for c in user_cache(integrator)
    c.f1 = 1.5
  end
end

function affect2!(integrator)
  for c in user_cache(integrator)
    c.f1 = -1.5
  end
end
save_positions = (true,true)

cb = DiscreteCallback(condition, affect!, save_positions=save_positions)

save_positions = (false,true)

cb2 = DiscreteCallback(condition2, affect2!, save_positions=save_positions)

cbs = CallbackSet(cb,cb2)
u0 = SimType([10.0;10.0], 0.0)
prob = ODEProblem(f,u0,(0.0,10.0))
const tstop = [5.;8.]
sol = solve(prob,Tsit5(),callback = cbs, tstops=tstop)

```

I need to understand what is happening so I can [put a callback](https://discourse.julialang.org/t/is-there-a-way-to-run-differential-equations-to-a-specific-point-and-then-change-input-values-continue-running-and-graph-it-together/19232/2) into my code.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 5, 2019, 5:17am UTC](https://discourse.julialang.org/t/what-does-user-cache-method-has-not-been-implemented-for-the-integrator-mean/19233/2 "2019-01-05T05:17:12Z")

</div>

Those docs need to be updated. It should be `full_cache` now.

---

<div class="post-metadata">

**Author:** ![asprionj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asprionj/32/6856_2.png) [@asprionj](https://discourse.julialang.org/u/asprionj)\
**Post date:** [April 13, 2020, 10:31pm UTC](https://discourse.julialang.org/t/what-does-user-cache-method-has-not-been-implemented-for-the-integrator-mean/19233/3 "2020-04-13T22:31:41Z")

</div>

There’s problems with that approach, though. First, when using `autodiff`, the type constraint on the “user-defined” fields of the data do not match, i.e. only one of the fields is a dual at a time. So, using e.g. `Trapezoid()` instead of `Tsit5` as solver, I get the error:

```julia
MethodError: no method matching SimType(::Array{ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.UJacobianWrapper{ODEFunction{true,typeof(f),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Float64,DiffEqBase.NullParameters},Float64}(),Float64,2},1}, ::Float64)
Closest candidates are:
  SimType(::Array{T,1}, !Matched::T) where T ... 

```

I remember there is a way of solving this, I read it somewhere some time ago. But, IMO, that’s rather complicated for a “standard user”. Is there any better way?

Ok, so let’s turn off `autodiff` by using `Trapezoid(autodiff=false)`. I then get:

```julia
MethodError: no method matching SimType(::Array{Float64,2}, ::Float64)
Closest candidates are:
  SimType(!Matched::Array{T,1}, ::T) where T ... 

```

So, somehow, this (and many other solvers) try to initialise a 2D array…?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [April 14, 2020, 3:34pm UTC](https://discourse.julialang.org/t/what-does-user-cache-method-has-not-been-implemented-for-the-integrator-mean/19233/4 "2020-04-14T15:34:43Z")

</div>

> [@asprionj](#):
>
> I remember there is a way of solving this, I read it somewhere some time ago. But, IMO, that’s rather complicated for a “standard user”. Is there any better way?

You can do [https://docs.sciml.ai/latest/basics/faq/#I-get-Dual-number-errors-when-I-solve-my-ODE-with-Rosenbrock-or-SDIRK-methods-1](https://docs.sciml.ai/latest/basics/faq/#I-get-Dual-number-errors-when-I-solve-my-ODE-with-Rosenbrock-or-SDIRK-methods-1) , but that’s a very different issue. I think the issue of how to handle explicit algebraic variables is much deeper, and I’ll respond in your other thread.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 19, 2020, 7:09pm UTC](https://discourse.julialang.org/t/what-does-user-cache-method-has-not-been-implemented-for-the-integrator-mean/19233/5 "2020-07-19T19:09:13Z")

</div>

Updated: [Frequently Asked Questions · DifferentialEquations.jl](https://diffeq.sciml.ai/latest/basics/faq/#I-get-Dual-number-errors-when-I-solve-my-ODE-with-Rosenbrock-or-SDIRK-methods-1)
