slimgroup / JUDI.jl

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

The final result cannot be saved in h5 file? #184

Closed WYJLCYWHZ closed 1 year ago

WYJLCYWHZ commented 1 year ago

Hi, when I was running the program in https://github.com/slimgroup/JUDI.jl/blob/master/examples/scripts/fwi_example_constraints.jl, there was an error in saving the final result. Because on the remote server, it cannot be displayed directly as a figure. So I decided to save them in .h5 file. But it seems that this data type cannot be saved in .h5 file.

┌ Warning: Fixed length trace flag set in stream: IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=1086467600, maxsize=Inf, ptr=3601, mark=-1) └ @ SegyIO ~/.julia/packages/SegyIO/qkvUT/src/read/read_file.jl:26 ERROR: LoadError: MethodError: no method matching Vector{Float32}(::UndefInitializer, ::Tuple{Int64, Int64}) Closest candidates are: Array{T, N}(::UndefInitializer, ::Tuple{Vararg{Int64, N}}) where {T, N} at ~/julia-1.7.2/share/julia/base/boot.jl:469 Array{T, N}(::UndefInitializer, ::Tuple{Vararg{Integer, N}}) where {T, N} at ~/julia-1.7.2/share/julia/base/baseext.jl:36 Vector{T}(::UndefInitializer, !Matched::Int64) where T at ~/julia-1.7.2/share/julia/base/boot.jl:457 ... Stacktrace: [1] Vector{Float32}(x::PhysicalParameter{Float32}) @ Base ./array.jl:563 [2] Array(A::PhysicalParameter{Float32}) @ Core ./boot.jl:481 [3] top-level scope @ ~/.julia/environments/v1.7/fwi_example_constraints.jl:144 in expression starting at /public/home/user/.julia/environments/v1.7/fwi_example_constraints.jl:144

Then, I tried to convert it to Array,:

m_array = Array(model0.m) h5open("model_history.h5", "w") do file write(file, "m_1", m_array) end

but it didn't seem to work. I have no idea. Can you help me?

mloubout commented 1 year ago

You can save. directly model0.m

h5open("model_history.h5", "w") do file
    write(file, "m_1", model0.m)
end

this seems to work fine

WYJLCYWHZ commented 1 year ago

You can save. directly model0.m

h5open("model_history.h5", "w") do file
    write(file, "m_1", model0.m)
end

this seems to work fine

I tried to save directly before, and it still seems to have bugs:

┌ Warning: Fixed length trace flag set in stream: IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=1086467600, maxsize=Inf, ptr=3601, mark=-1) └ @ SegyIO ~/.julia/packages/SegyIO/qkvUT/src/read/read_file.jl:26 ERROR: LoadError: MethodError: no method matching strides(::PhysicalParameter{Float32}) Closest candidates are: strides(!Matched::Adjoint{<:Real, <:AbstractVector}) at ~/julia-1.7.2/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:191 strides(!Matched::Adjoint{<:Real, <:AbstractMatrix}) at ~/julia-1.7.2/share/julia/stdlib/v1.7/LinearAlgebra/src/adjtrans.jl:194 strides(!Matched::StaticArraysCore.SizedArray) at ~/.julia/packages/StaticArrays/5bAMi/src/abstractarray.jl:23 ... Stacktrace: [1] stride(A::PhysicalParameter{Float32}, k::Int64) @ Base ./abstractarray.jl:541 [2] h5d_write(dataset_id::Int64, memtype_id::Int64, buf::PhysicalParameter{Float32}, xfer::Int64) @ HDF5 ~/.julia/packages/HDF5/YX0jU/src/HDF5.jl:2090 [3] writearray(dset::HDF5Dataset, type_id::Int64, buf::PhysicalParameter{Float32}) @ HDF5 ~/.julia/packages/HDF5/YX0jU/src/HDF5.jl:1918 [4] _d_write(::HDF5File, ::String, ::PhysicalParameter{Float32}) @ HDF5 ~/.julia/packages/HDF5/YX0jU/src/HDF5.jl:1714 [5] d_write(::HDF5File, ::String, ::PhysicalParameter{Float32}) @ HDF5 ~/.julia/packages/HDF5/YX0jU/src/HDF5.jl:1721 [6] write(::HDF5File, ::String, ::PhysicalParameter{Float32}) @ HDF5 ~/.julia/packages/HDF5/YX0jU/src/HDF5.jl:1748 [7] (::var"#4#5")(file::HDF5File) @ Main ~/.julia/environments/v1.7/fwi_example_constraints.jl:145 [8] h5open(::var"#4#5", ::String, ::Vararg{String}; swmr::Bool) @ HDF5 ~/.julia/packages/HDF5/YX0jU/src/HDF5.jl:696 [9] h5open(::Function, ::String, ::String) @ HDF5 ~/.julia/packages/HDF5/YX0jU/src/HDF5.jl:694 [10] top-level scope @ ~/.julia/environments/v1.7/fwi_example_constraints.jl:144 in expression starting at /public/home/user/.julia/environments/v1.7/fwi_example_constraints.jl:144

WYJLCYWHZ commented 1 year ago

I try to add the collect(), then it seems to work fine. Thank you(^▽^)

h5open("model_history.h5", "w") do file write(file, "m_1", collect(model0.m)) end