-
-
Notifications
You must be signed in to change notification settings - Fork 161
Description
Hi,
First off, love the package, it's extremely useful and sleek. I had a question about an error that I'm sure is user-caused but I can't figure out from the docs how to fix it.
I added a discrete callback to a model I have been working on and its broken the training loop because the DiffEqSensitivity.FakeIntegrator type is designed to be immutable. How should I properly define the callback's affect function psg! so that I can change the integrator state? Here are the two callbacks (the first of which I have used previously without issue), the second of which is linked to the error,
psg_t = [48.0, 96.0]
dead(u,t,integrator) = any(u .< 1e-8)
function die!(integrator); integrator.u[integrator.u .< 1e-8] .= 0; end
death_cb = ContinuousCallback(dead, die!, save_positions = (false,false))
psg_time(u,t,integrator) = t ∈ psg_t
function psg!(integrator); integrator.u *= 0.05; end # 1:20 culture dilution
psg_cb = DiscreteCallback(psg_time, psg!, save_positions = (false,false))
cbset = CallbackSet(death_cb, psg_cb)
and later on in the loss function my solve call is,
sol = DifferentialEquations.solve(prob, Tsit5(), u0 = x0, p=p_comb, saveat=24, callback=cbset, tstops=psg_t)
Here is the error and the first two stacks of the trace:
ERROR: setfield! immutable struct of type FakeIntegrator cannot be changed Stacktrace: [1] setproperty! at ./Base.jl:34 [inlined] [2] psg!(::DiffEqSensitivity.FakeIntegrator{Array{ReverseDiff.TrackedReal{Float64,Float64,ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}}},1},ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}},ReverseDiff.TrackedReal{Float64,Float64,ReverseDiff.TrackedArray{Float64,Float64,1,Array{Float64,1},Array{Float64,1}}}}) at /Users/willsharpless/Documents/Julia/PostBin_Analysis_v3.jl:40