slimgroup / JUDI.jl

Julia Devito inversion.
https://slimgroup.github.io/JUDI.jl
MIT License
98 stars 32 forks source link

ERROR: MethodError: Cannot `convert` an object of type Float32 to an object of type Vector{Float32} #117

Closed AMzaheri closed 2 years ago

AMzaheri commented 2 years ago

Hello, I’ve got a syntax error when I was running the documentation example (from: https://slimgroup.github.io/JUDI.jl/dev/tutorials/03_constrained_fwi/#pos). Here is the error:

src_geom = Geometry(xsrc, ysrc, zsrc; dt=dt, t=tn); ERROR: MethodError: Cannot convert an object of type Float32 to an object of type Vector{Float32} Closest candidates are: convert(::Type{Array{T, N}}, ::StaticArrays.SizedArray{S, T, N, N, Array{T, N}}) where {S, T, N} at ~/.julia/packages/StaticArrays/58yy1/src/SizedArray.jl:218 convert(::Type{Array{T, N}}, ::StaticArrays.SizedArray{S, T, N, M, TData} where {M, TData<:AbstractArray{T, M}}) where {T, S, N} at ~/.julia/packages/StaticArrays/58yy1/src/SizedArray.jl:212 convert(::Type{T}, ::Factorization) where T<:AbstractArray at ~/local/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/factorization.jl:58 ... Stacktrace: [1] GeometryIC{Float32}(xloc::Vector{Vector{Float32}}, yloc::Vector{Vector{Float32}}, zloc::Vector{Vector{Float32}}, dt::Float32, nt::Int64, t::Float32) @ JUDI ~/.julia/packages/JUDI/Xrqx6/src/TimeModeling/Types/GeometryStructure.jl:15 [2] Geometry(xloc::Vector{Vector{Float32}}, yloc::Vector{Vector{Float32}}, zloc::Vector{Vector{Float32}}; dt::Float32, t::Int64) @ JUDI ~/.julia/packages/JUDI/Xrqx6/src/TimeModeling/Types/GeometryStructure.jl:258 [3] Geometry(xloc::Vector{Vector{Float64}}, yloc::Vector{Vector{Float32}}, zloc::Vector{Vector{Float32}}; dt::Float32, t::Int64, nsrc::Nothing) @ JUDI ~/.julia/packages/JUDI/Xrqx6/src/TimeModeling/Types/GeometryStructure.jl:240 [4] top-level scope @ REPL[91]:1 [5] top-level scope @ ~/.julia/packages/CUDA/GGwVa/src/initialization.jl:52

julia>

I’d be grateful if you could help. It might be worth mentioning that some lines in the documentation need to be updated. As I got errors when running those as well. Functions from Distributed (e.g. workers) need to be imported explicitly. Thank you Afsaneh

mloubout commented 2 years ago

Looks like there is an type handling issue indeed. d[1] in xsrc = convertToCell(d[1].*ones(Float32, nsrc)) happens to be a Float64 throwing off the Geomnetry initialization. I'll see if can cleanly fix it, in the mean time xsrc = convertToCell(Float32(d[1]).*ones(Float32, nsrc)) should fix it

EDIT: Small bug to fix actually, only need to change tn=4000 to tn=4000f0 which is still la type processing issue but much smaller and easier to fix.

AMzaheri commented 2 years ago

I've just changed the xsrc, ysrc and zsrc as follows and it's removed the error. xsrc = d[1].ones(Float32, nsrc) ysrc = range(0f0, stop = 0f0, length = nsrc) zsrc = range(0f0, (n[2] - 1)d[2], length=nsrc)

Thank you,

AMzaheri commented 2 years ago

Thank you very much mloubout. I've changed tn to tn=4000f0 and it solved the problem. Best regards,

AMzaheri commented 2 years ago

Setting xsrc to xsrc = convertToCell(range(d[1], stop = d[1], length = nsrc)) and tn=4000, I get the same syntax error.

ziyiyin97 commented 2 years ago

Sorry I miscommented. Change tn=4000f0 should work

AMzaheri commented 2 years ago

That's OK. Yes, tn=4000f0 solved it. Thank you, Regards,

AMzaheri commented 2 years ago

Hello, After running PQN, I’ve got an InexactError. I was wondering if it is related to the previous type error. Any idea how to solve it? I’d appreciate your help. Afsaneh

sol = pqn(f, g!, fg!, vec(m0), prj, options_pqn); Running PQN... Number of L-BFGS Corrections to store: 10 ERROR: InexactError: Bool(2) Stacktrace: [1] Bool @ ./float.jl:258 [inlined] [2] convert @ ./number.jl:7 [inlined] [3] oftype(x::Bool, y::Int64) @ Base ./essentials.jl:296 [4] fmt @ ~/local/julia-1.7.3/share/julia/stdlib/v1.7/Printf/src/Printf.jl:250 [inlined] [5] format @ ~/local/julia-1.7.3/share/julia/stdlib/v1.7/Printf/src/Printf.jl:232 [inlined] [6] format(io::Base.TTY, f::Printf.Format{Base.CodeUnits{UInt8, String}, Tuple{Printf.Spec{Val{'d'}}}}, args::Bool) @ Printf ~/local/julia-1.7.3/share/julia/stdlib/v1.7/Printf/src/Printf.jl:216 [7] _pqn(obj::Function, grad!::SlimOptim.var"#grad!#23"{typeof(g!), result{Float32}}, objgrad!::SlimOptim.var"#objgrad!#24"{typeof(fg!), result{Float32}}, projection::SlimOptim.var"#projection#21"{typeof(prj), result{Float32}}, x::Vector{Float32}, g::Vector{Float32}, sol::result{Float32}, ls::Nothing, options::SlimOptim.PQN_params) @ SlimOptim ~/.julia/packages/SlimOptim/rFROp/src/PQNSlim.jl:249 [8] pqn(f::typeof(f), g!::typeof(g!), fg!::typeof(fg!), x::Vector{Float32}, funProj::typeof(prj), options::SlimOptim.PQN_params, ls::Nothing) @ SlimOptim ~/.julia/packages/SlimOptim/rFROp/src/PQNSlim.jl:228 [9] pqn(f::Function, g!::Function, fg!::Function, x::Vector{Float32}, funProj::Function, options::SlimOptim.PQN_params) @ SlimOptim ~/.julia/packages/SlimOptim/rFROp/src/PQNSlim.jl:218 [10] top-level scope @ REPL[206]:1 [11] top-level scope @ ~/.julia/packages/CUDA/GGwVa/src/initialization.jl:52

mloubout commented 2 years ago

That's quite an odd error. Can you share the versions of Julia and SlimOptim you are using? This seem to be am issue with PQN rather than JUDI

AMzaheri commented 2 years ago

Thank you for your response. Julia Version 1.7.3 Platform Info: OS: Linux (x86_64-pc-linux-gnu) and SlimOptim v0.1.8. Can it be due to a bad installation of SlimOptim? I'll add it again and will run the example again. Will let you know the result. Thanks,

mloubout commented 2 years ago

Are you using the example one or did you make some changes to ig

AMzaheri commented 2 years ago

I'm using the example from the documentation : https://slimgroup.github.io/JUDI.jl/dev/tutorials/03_constrained_fwi/

mloubout commented 2 years ago

Interesting. I ran it yesterday to make sure and ran fine I'll look into it. This looks like a printf error though so you should be able to run it with verbose=0 in the mean time to disable the log

ziyiyin97 commented 2 years ago

It also runs fine on my end

(@v1.7) pkg> status JUDI
      Status `~/.julia/environments/v1.7/Project.toml`
  [f3b833dc] JUDI v3.0.2 `~/.julia/dev/JUDI`

(@v1.7) pkg> status SlimOptim
      Status `~/.julia/environments/v1.7/Project.toml`
  [e4c7bc62] SlimOptim v0.1.8 `~/.julia/dev/SlimOptim`
AMzaheri commented 2 years ago

The same error happens, after I've reinstalled SlimOptim.

mloubout commented 2 years ago

Something is off with printf not sure why, it fails to parse one of the options (bbinit). Will try to figure it out. In the mean time, as I said you can turn off the prints and log with verbose=0 in the lqn options

AMzaheri commented 2 years ago

Thanks.

mloubout commented 2 years ago

THis is really odd, I can't seem to be able to reproduce it. Can you try the examples and tests in SlimOptim for a simpler debug case and let me know if it errors too,

AMzaheri commented 2 years ago

Yes, sure I'll let you know the result, once I've checked it.