It works when you specify the algorithm:
using DifferentialEquations
using Plots
const α = -0.3
function f(du,u,p,t)
for i in 1:length(u)
du[i] = α*u[i]
end
end
function condition(u,t,integrator) # Event when event_f(u,t) == 0
minimum(u)-0.01
end
function affect!(integrator)
u = integrator.u
#resize!(integrator,length(u)-1) # This works
deleteat!(integrator, length(u)) # This errors
nothing
end
callback = ContinuousCallback(condition,affect!)
u0 = [5, 3, 1]
tspan = (0.0,20.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob,Tsit5(),callback=callback)
plot(sol.t,map((x)->length(x),sol[:]),lw=3,
ylabel="Number of Cells",xlabel="Time")
The issue seems to be that if you use an automatic stiffness detection algorithm then, since they have some shared cache variables, it’s deleting from those shared cache variables twice. Could you file a bug report so we can track and get this fixed? It shouldn’t effect your usage if you select an algorithm, but it would be nice to fix it sooner or later.