Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neural SDE example fails on convert(::Type{Float64}, x::Tracker.TrackedReal{Float64}) #1109

Closed
John-Boik opened this issue Sep 7, 2024 · 2 comments
Labels

Comments

@John-Boik
Copy link

John-Boik commented Sep 7, 2024

Note: I have deleted my original post and replaced it with the note here. My post concerned the tutorial Neural Stochastic Differential Equations. But I realize now that it is outdated, and the new tutorial to follow is Neural Stochastic Differential Equations With Method of Moments.

When I tried to run the new tutorial, I received the same error as before, the first few lines of which are:

ERROR: LoadError: MethodError: no method matching Float64(::Tracker.TrackedReal{Float64})

Closest candidates are:
  (::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat
   @ Base rounding.jl:207
  (::Type{T})(::T) where T<:Number
   @ Core boot.jl:792
  Float64(::IrrationalConstants.Log4π)
   @ IrrationalConstants ~/.julia/packages/IrrationalConstants/vp5v4/src/macro.jl:112
  ...

Stacktrace:
  [1] convert(::Type{Float64}, x::Tracker.TrackedReal{Float64})
    @ Base ./number.jl:7
  [2] setindex!(A::Vector{Float64}, x::Tracker.TrackedReal{Float64}, i1::Int64)
    @ Base ./array.jl:1021
  [3] copyto_unaliased!
    @ ./abstractarray.jl:1094 [inlined]
  [4] copyto!(dest::Vector{Float64}, src::Tracker.TrackedVector{Float64, Vector{Float64}})
    @ Base ./abstractarray.jl:1068
  [5] copyto!
    @ ~/.julia/packages/ComponentArrays/xO4hy/src/similar_convert_copy.jl:42 [inlined]
  [6] copyto!
    @ ./broadcast.jl:997 [inlined]
  [7] copyto!
    @ ./broadcast.jl:956 [inlined]
  [8] materialize!
    @ ./broadcast.jl:914 [inlined]
  [9] materialize!
    @ ./broadcast.jl:911 [inlined]
 [10] restructure(x::ComponentArrays.ComponentVector{…}, y::ComponentArrays.ComponentVector{…})
    @ ArrayInterface ~/.julia/packages/ArrayInterface/TFWPW/src/ArrayInterface.jl:637

However, the error was apparently caused a package that is used in the tutorial, or an extra one that I imported, but which has been updated and fixed in the last few days. In my original example, and in running the new tutorial, I imported those used in the new tutorial, and also the following:

import Base, DiffEqBase, OptimizationFlux
using SciMLSensitivity

I'm not sure which package caused the problem, but when I generated a new project today and imported only the packages used in the new tutorial (and also Lux and Zygote), the error disappeared. If someone else receives the same error as above, it is likely due an outdated package or some package conflict.

@John-Boik John-Boik added the bug label Sep 7, 2024
@John-Boik
Copy link
Author

I mentioned in my main post that the neural SDE tutorial example does not run as given. Here are the errors I get when I run the code.

The first is UndefVarError: ActivationFunction not defined, which occurs when defining the drift neural network. That can be fixed simply by using x -> x.^3 instead.

The next is ComponentArray not defined which occurs at p1 = Lux.ComponentArray(p1). That can be fixed by using p1 = ComponentArrays.ComponentArray(p1).

The next is:

MethodError: no method matching (::DiffEqFlux.NeuralDSDE{…})(::Vector{…}, ::Vector{…}, ::@NamedTuple{…}, ::@NamedTuple{})

Closest candidates are:
  (::DiffEqFlux.NeuralDSDE)(::Any, ::Any, ::Any)
   @ DiffEqFlux ~/.julia/packages/DiffEqFlux/TglmB/src/neural_de.jl:95

which occurs at prediction0, st1, st2 = neuralsde(u0,p,st1,st2).
This can be fixed by calling Lux.setup on neuralsde, as I mention in my main post:

p, st = Lux.setup(rng, neuralsde)
prediction0, st = neuralsde(u0,p,st)

@ChrisRackauckas
Copy link
Member

Okay yeah, I'd first say that the v6 tutorials are more than 2 years old and won't necessarily be a good guide for v7 usage. There's a major version between them because there are breaking differences, some of which you see and highlighted here. I'd highly recommend just using the updated version and tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants