# ArgumentError: Converting an instance of ReverseDiff.TrackedReal{Float64, Float32, Nothing} to Float32 is not defined

Hello all, I am very new to Julia, just started using it a week ago (was mainly a Python user). I started off with the code example at DiffEqFlux documentation and modified it bit by bit (making sure that it’s still working and doing what I want it to do) to suit my own needs. Below is the code I got to, which throws an error that I can’t understand for the life of me (also shown below).

``````using DiffEqFlux, OrdinaryDiffEq, Flux, Optim, Plots, Trapz

function base_system(u::Vector{Float32}, p::Vector{Float32})

out = Vector{Float32}(rand(11,))

out[1] = -0.800*u[1]*u[2]  +  0.240*u[3]  -  0.800*u[1]*u[4]  +  0.160*u[5]  -  0.247*u[1]*u[6]  +  0.524*u[7]  -  0.150*u[1]*u[8]  +  0.015*u[9]  +  0.043*u[8]  -  0.300*u[1]*u[10]  +  0.300*u[11]  +  0.0194*u[10]

out[2] = -0.800*u[1]*u[2]  +  0.240*u[3]
out[3] =  0.800*u[1]*u[2]  -  0.240*u[3]

out[4] = -0.800*u[1]*u[4]  +  0.160*u[5]
out[5] =  0.800*u[1]*u[4]  -  0.160*u[5]

out[6] = -0.247*u[1]*u[6]  +  0.524*u[7]
out[7] =  0.247*u[1]*u[6]  -  0.524*u[7]

out[8] = -0.150*u[1]*u[8]  +  (0.015  +  0.012)*u[9]
out[9] =  0.150*u[1]*u[8]  -  (0.015  +  0.012)*u[9]

out[10]= -0.300*u[1]*u[10] +  (0.300  +  0.600)*u[11]
out[11]=  0.300*u[1]*u[10] -  (0.300  +  0.600)*u[11]

return out

end

function base_dudt(du, u, p, t)

du[:] = base_system(u, p)

end

function partial_system(u, p)

k4f = p[2]
k4b = p[1] * p[2]
k4p = p[3]
k4l = p[4]

out = Vector{Float32}(rand(9,))

out[1] = -0.800*u[1]*u[2]  +  0.240*u[3]  -  0.800*u[1]*u[4]  +  0.160*u[5]  -  0.247*u[1]*u[6]  +  0.524*u[7]  -  k4f*u[1]*u[9]  +  k4b*u[8]  + k4l*u[9]

out[2] = -0.800*u[1]*u[2]  +  0.240*u[3]
out[3] =  0.800*u[1]*u[2]  -  0.240*u[3]

out[4] = -0.800*u[1]*u[4]  +  0.160*u[5]
out[5] =  0.800*u[1]*u[4]  -  0.160*u[5]

out[6] = -0.247*u[1]*u[6]  +  0.524*u[7]
out[7] =  0.247*u[1]*u[6]  -  0.524*u[7]

out[8] =  k4f*u[1]*u[8]  -  (k4b  +  k4p)*u[9]
out[9] = -k4f*u[1]*u[8]  +  (k4b  +  k4p)*u[9]

return out

end

partial_model = function (du, u, p, t)

du[1:9] = partial_system(u[1:9], p[end-4:end])

len1 = DiffEqFlux.paramlength(FastDense(59, 50))
len2 = DiffEqFlux.paramlength(FastDense(50, 2))

du[10:end] = FastDense(59, 50, tanh)(u, p[1:len1])

X_stuff = FastDense(50, 2, Flux.sigmoid)(u[10:end], p[(1+len1):(len1+len2)])

du[9] = du[9] + X_stuff[1] - X_stuff[2] * u[9]

end

num_pts = 1001
tspan = Float32[0.0, 100.0]
t = range(tspan[1],tspan[2],length=num_pts)

####################################################
#################### BASE SETUP ####################
####################################################

u0 	= Float32[10; 14.5; 5.50; 0.00; 0.00; 75.0; 4.00; 1.80; 1.10; 18.3; 0.70]
params  = Float32[]

prob    = ODEProblem(base_dudt, u0, tspan)
ode_sol = Array(solve(prob, DP5(), p=params, saveat=t))

#####################################################
#################### MODEL SETUP ###################
#####################################################

layers = [FastDense(59, 50), FastDense(50, 2)]

params = Float32[]

for i in layers
append!(params, initial_params(i))
end

kinect_init = Vector{Float32}(rand(4,))
append!(params, kinect_init * 1e-1)

u0 	= Vector{Float32}(rand(59,))
u0[1:9]	= Float32[10; 14.5; 5.50; 0.00; 0.00; 75.0; 4.00; 0.00; 0.00]

model_prob = ODEProblem(partial_model, u0, tspan)

function predict_n_ode()
Array(solve(model_prob, DP5(), u0=u0, p=params, saveat=t))
end

pred = predict_n_ode()

function loss_n_ode()

pred = predict_n_ode()
loss = sum(abs2, ode_sol[3,:] .- pred[3,:])

end

cb = function (;doplot=false) #callback function to observe training
pred = predict_n_ode()
println(sum(abs2, ode_sol[3,:] .- pred[3,:]))
# plot current prediction against data
pl = scatter(t,ode_sol[3,:],label="data")
scatter!(pl,t,pred[3,:],label="prediction")
display(plot(pl))
return false
end

cb()

data = Iterators.repeated((), 1000)
res1 = Flux.train!(loss_n_ode, Flux.params(params), data, ADAM(0.05), cb = cb)
``````

In short, I am trying combine a known part of a system of ODEs that describes a dynamical system with another part modeled as neural ODEs and then train neural ODEs. When I run the above code I get the following error:

``````ERROR: LoadError: ArgumentError: Converting an instance of ReverseDiff.TrackedReal{Float64, Float32, Nothing} to Float32 is not defined. Please use `ReverseDiff.value` instead.
Stacktrace:
[1] convert(#unused#::Type{Float32}, t::ReverseDiff.TrackedReal{Float64, Float32, Nothing})
@ ReverseDiff ~/.julia/packages/ReverseDiff/E4Tzn/src/tracked.jl:261
[2] setindex!(A::Vector{Float32}, x::ReverseDiff.TrackedReal{Float64, Float32, Nothing}, i1::Int64)
@ Base ./array.jl:843
[3] partial_system(u::ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}, p::ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}})
@ Main /disk/scratch/s1788788/NODE_work/node_example.jl:80
[4] (::var"#1#2")(du::Vector{ReverseDiff.TrackedReal{Float32, Float32, ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}}}, u::ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}, p::ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}, t::ReverseDiff.TrackedReal{Float32, Float32, ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}})
@ Main /disk/scratch/s1788788/NODE_work/node_example.jl:104
[5] (::ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing})(::Vector{ReverseDiff.TrackedReal{Float32, Float32, ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}}}, ::Vararg{Any, N} where N)
@ SciMLBase ~/.julia/packages/SciMLBase/n3U0M/src/scimlfunctions.jl:334
[6] (::DiffEqSensitivity.var"#110#125"{ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}})(u::ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}, p::ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}, t::ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}})
[7] ReverseDiff.GradientTape(f::Function, input::Tuple{Vector{Float32}, Vector{Float32}, Vector{Float32}}, cfg::ReverseDiff.GradientConfig{Tuple{ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}, ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}, ReverseDiff.TrackedArray{Float32, Float32, 1, Vector{Float32}, Vector{Float32}}}})
@ ReverseDiff ~/.julia/packages/ReverseDiff/E4Tzn/src/api/tape.jl:207
@ ReverseDiff ~/.julia/packages/ReverseDiff/E4Tzn/src/api/tape.jl:204
[9] adjointdiffcache(g::DiffEqSensitivity.var"#df#233"{Matrix{Float32}, Colon}, sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, discrete::Bool, sol::ODESolution{Float32, 2, Vector{Vector{Float32}}, Nothing, Nothing, Vector{Float32}, Vector{Vector{Vector{Float32}}}, ODEProblem{Vector{Float32}, Tuple{Float32, Float32}, true, Vector{Float32}, ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, DP5, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float32}}, Vector{Float32}, Vector{Vector{Vector{Float32}}}, OrdinaryDiffEq.DP5Cache{Vector{Float32}, Vector{Float32}, Vector{Float32}, OrdinaryDiffEq.DP5ConstantCache{Float32, Float32}}}, DiffEqBase.DEStats}, dg::Nothing, f::ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}; quad::Bool, noiseterm::Bool)
[10] DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction(g::Function, sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, discrete::Bool, sol::ODESolution{Float32, 2, Vector{Vector{Float32}}, Nothing, Nothing, Vector{Float32}, Vector{Vector{Vector{Float32}}}, ODEProblem{Vector{Float32}, Tuple{Float32, Float32}, true, Vector{Float32}, ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, DP5, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float32}}, Vector{Float32}, Vector{Vector{Vector{Float32}}}, OrdinaryDiffEq.DP5Cache{Vector{Float32}, Vector{Float32}, Vector{Float32}, OrdinaryDiffEq.DP5ConstantCache{Float32, Float32}}}, DiffEqBase.DEStats}, dg::Nothing, f::Function, checkpoints::Vector{Float32}, tols::NamedTuple{(:reltol, :abstol), Tuple{Float64, Float64}}, tstops::Nothing; noiseterm::Bool)
[11] DiffEqSensitivity.ODEInterpolatingAdjointSensitivityFunction(g::Function, sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, discrete::Bool, sol::ODESolution{Float32, 2, Vector{Vector{Float32}}, Nothing, Nothing, Vector{Float32}, Vector{Vector{Vector{Float32}}}, ODEProblem{Vector{Float32}, Tuple{Float32, Float32}, true, Vector{Float32}, ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, DP5, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float32}}, Vector{Float32}, Vector{Vector{Vector{Float32}}}, OrdinaryDiffEq.DP5Cache{Vector{Float32}, Vector{Float32}, Vector{Float32}, OrdinaryDiffEq.DP5ConstantCache{Float32, Float32}}}, DiffEqBase.DEStats}, dg::Nothing, f::Function, checkpoints::Vector{Float32}, tols::NamedTuple{(:reltol, :abstol), Tuple{Float64, Float64}}, tstops::Nothing)
[12] ODEAdjointProblem(sol::ODESolution{Float32, 2, Vector{Vector{Float32}}, Nothing, Nothing, Vector{Float32}, Vector{Vector{Vector{Float32}}}, ODEProblem{Vector{Float32}, Tuple{Float32, Float32}, true, Vector{Float32}, ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, DP5, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float32}}, Vector{Float32}, Vector{Vector{Vector{Float32}}}, OrdinaryDiffEq.DP5Cache{Vector{Float32}, Vector{Float32}, Vector{Float32}, OrdinaryDiffEq.DP5ConstantCache{Float32, Float32}}}, DiffEqBase.DEStats}, sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, g::DiffEqSensitivity.var"#df#233"{Matrix{Float32}, Colon}, t::Vector{Float32}, dg::Nothing; checkpoints::Vector{Float32}, callback::Nothing, reltol::Float64, abstol::Float64, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
[13] _adjoint_sensitivities(sol::ODESolution{Float32, 2, Vector{Vector{Float32}}, Nothing, Nothing, Vector{Float32}, Vector{Vector{Vector{Float32}}}, ODEProblem{Vector{Float32}, Tuple{Float32, Float32}, true, Vector{Float32}, ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, DP5, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float32}}, Vector{Float32}, Vector{Vector{Vector{Float32}}}, OrdinaryDiffEq.DP5Cache{Vector{Float32}, Vector{Float32}, Vector{Float32}, OrdinaryDiffEq.DP5ConstantCache{Float32, Float32}}}, DiffEqBase.DEStats}, sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, alg::DP5, g::DiffEqSensitivity.var"#df#233"{Matrix{Float32}, Colon}, t::Vector{Float32}, dg::Nothing; abstol::Float64, reltol::Float64, checkpoints::Vector{Float32}, corfunc_analytical::Nothing, callback::Nothing, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ DiffEqSensitivity ~/.julia/packages/DiffEqSensitivity/eq2wv/src/sensitivity_interface.jl:17
[14] adjoint_sensitivities(::ODESolution{Float32, 2, Vector{Vector{Float32}}, Nothing, Nothing, Vector{Float32}, Vector{Vector{Vector{Float32}}}, ODEProblem{Vector{Float32}, Tuple{Float32, Float32}, true, Vector{Float32}, ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, DP5, OrdinaryDiffEq.InterpolationData{ODEFunction{true, var"#1#2", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Vector{Float32}}, Vector{Float32}, Vector{Vector{Vector{Float32}}}, OrdinaryDiffEq.DP5Cache{Vector{Float32}, Vector{Float32}, Vector{Float32}, OrdinaryDiffEq.DP5ConstantCache{Float32, Float32}}}, DiffEqBase.DEStats}, ::DP5, ::Vararg{Any, N} where N; sensealg::InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, kwargs::Base.Iterators.Pairs{Symbol, Nothing, Tuple{Symbol}, NamedTuple{(:callback,), Tuple{Nothing}}})
@ DiffEqSensitivity ~/.julia/packages/DiffEqSensitivity/eq2wv/src/sensitivity_interface.jl:6
[15] (::DiffEqSensitivity.var"#adjoint_sensitivity_backpass#232"{Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, DP5, InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, Vector{Float32}, Vector{Float32}, Tuple{}, Colon, NamedTuple{(), Tuple{}}})(Δ::Matrix{Float32})
@ DiffEqSensitivity ~/.julia/packages/DiffEqSensitivity/eq2wv/src/concrete_solve.jl:231
[16] ZBack
@ ~/.julia/packages/Zygote/BCfwJ/src/compiler/chainrules.jl:168 [inlined]
[17] (::Zygote.var"#kw_zpullback#40"{DiffEqSensitivity.var"#adjoint_sensitivity_backpass#232"{Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, DP5, InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, Vector{Float32}, Vector{Float32}, Tuple{}, Colon, NamedTuple{(), Tuple{}}}})(dy::Matrix{Float32})
@ Zygote ~/.julia/packages/Zygote/BCfwJ/src/compiler/chainrules.jl:194
[18] #203
@ ~/.julia/packages/Zygote/BCfwJ/src/lib/lib.jl:203 [inlined]
[19] (::Zygote.var"#1733#back#205"{Zygote.var"#203#204"{Tuple{NTuple{6, Nothing}, Tuple{Nothing}}, Zygote.var"#kw_zpullback#40"{DiffEqSensitivity.var"#adjoint_sensitivity_backpass#232"{Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, DP5, InterpolatingAdjoint{0, true, Val{:central}, ReverseDiffVJP{false}, Bool}, Vector{Float32}, Vector{Float32}, Tuple{}, Colon, NamedTuple{(), Tuple{}}}}}})(Δ::Matrix{Float32})
[20] Pullback
@ ~/.julia/packages/DiffEqBase/OPDgm/src/solve.jl:73 [inlined]
[21] (::typeof(∂(#solve#43)))(Δ::Matrix{Float32})
@ Zygote ~/.julia/packages/Zygote/BCfwJ/src/compiler/interface2.jl:0
[22] (::Zygote.var"#203#204"{Tuple{NTuple{6, Nothing}, Tuple{Nothing}}, typeof(∂(#solve#43))})(Δ::Matrix{Float32})
@ Zygote ~/.julia/packages/Zygote/BCfwJ/src/lib/lib.jl:203
[23] (::Zygote.var"#1733#back#205"{Zygote.var"#203#204"{Tuple{NTuple{6, Nothing}, Tuple{Nothing}}, typeof(∂(#solve#43))}})(Δ::Matrix{Float32})
[24] Pullback
@ ~/.julia/packages/DiffEqBase/OPDgm/src/solve.jl:68 [inlined]
[25] (::typeof(∂(solve##kw)))(Δ::Matrix{Float32})
@ Zygote ~/.julia/packages/Zygote/BCfwJ/src/compiler/interface2.jl:0
[26] Pullback
@ /disk/scratch/s1788788/NODE_work/node_example.jl:166 [inlined]
[27] (::typeof(∂(predict_n_ode)))(Δ::Matrix{Float32})
@ Zygote ~/.julia/packages/Zygote/BCfwJ/src/compiler/interface2.jl:0
[28] Pullback
@ /disk/scratch/s1788788/NODE_work/node_example.jl:175 [inlined]
[29] (::typeof(∂(loss_n_ode)))(Δ::Float32)
@ Zygote ~/.julia/packages/Zygote/BCfwJ/src/compiler/interface2.jl:0
[30] #203
@ ~/.julia/packages/Zygote/BCfwJ/src/lib/lib.jl:203 [inlined]
[31] #1733#back
[32] Pullback
@ ~/.julia/packages/Flux/ZnXxS/src/optimise/train.jl:105 [inlined]
[33] (::Zygote.var"#84#85"{Params, typeof(∂(#39)), Zygote.Context})(Δ::Float32)
@ Zygote ~/.julia/packages/Zygote/BCfwJ/src/compiler/interface.jl:343
@ Zygote ~/.julia/packages/Zygote/BCfwJ/src/compiler/interface.jl:76
[35] macro expansion
@ ~/.julia/packages/Flux/ZnXxS/src/optimise/train.jl:104 [inlined]
[36] macro expansion
@ ~/.julia/packages/Juno/n6wyj/src/progress.jl:134 [inlined]
[37] train!(loss::Function, ps::Params, data::Base.Iterators.Take{Base.Iterators.Repeated{Tuple{}}}, opt::ADAM; cb::var"#3#5")
@ Flux.Optimise ~/.julia/packages/Flux/ZnXxS/src/optimise/train.jl:102
[38] top-level scope
@ /disk/scratch/s1788788/NODE_work/node_example.jl:212
in expression starting at /disk/scratch/s1788788/NODE_work/node_example.jl:212
``````

I have next to zero idea what the error means, other than there being some incorrect conversion (that I don’t believe I am doing). Any hints or tips (both in terms of general Julia programming and regarding the error) are much appreciated, can try to provide additional information if required.

I’m getting

``````ERROR: LoadError: UndefVarError: base_dudt not defined
``````

For automatic differentiation, this will not be a Vector{Float32}. Instead, just create “type-matching” arrays. For example, `out = similar(u)`.

2 Likes

Many thanks for the comment, I tried your suggestion and it’s actually the solution, it fixed the error (I still can’t really comprehend why). Could you elaborate a bit on your point that “For automatic differentiation, this will not be a Vector{Float32}”? Why not, if I explicitly set it as Vector{Float32}?

The computation will not take place in Float32. Here, it’s using a tape-building type to generate a backpass, so it’s `TrackedReal`/`TrackedArray`, hence the error. In general, writing code generically can allow a lot of performance tricks anyways, so it’s a good style to keep aware of.