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

Can't calculate von_neumann_entropy() in gpu #489

Open
zipeilee opened this issue Dec 9, 2023 · 1 comment
Open

Can't calculate von_neumann_entropy() in gpu #489

zipeilee opened this issue Dec 9, 2023 · 1 comment

Comments

@zipeilee
Copy link

zipeilee commented Dec 9, 2023

When calculating the von_neumann_entropy() of a certain quantum state on the GPU, I often receive CUDA errors like

ERROR: ArgumentError: cannot take the CPU address of a CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}
Stacktrace:
 [1] unsafe_convert(#unused#::Type{Ptr{Float32}}, x::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
   @ CUDA ~/.julia/packages/CUDA/pCcGc/src/array.jl:370
 [2] geevx!(balanc::Char, jobvl::Char, jobvr::Char, sense::Char, A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
   @ LinearAlgebra.LAPACK ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/LinearAlgebra/src/lapack.jl:2093
 [3] eigvals!(A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}; permute::Bool, scale::Bool, sortby::typeof(LinearAlgebra.eigsortby))
   @ LinearAlgebra ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/LinearAlgebra/src/eigen.jl:306
 [4] eigvals!(A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
   @ LinearAlgebra ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/LinearAlgebra/src/eigen.jl:304
 [5] eigvals(A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}; kws::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ LinearAlgebra ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/LinearAlgebra/src/eigen.jl:339
 [6] eigvals(A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer})
   @ LinearAlgebra ~/packages/julias/julia-1.9/share/julia/stdlib/v1.9/LinearAlgebra/src/eigen.jl:339

Then I remind that function von_neumann_entropy() have a operattion p = max.(eigvals(dm), eps(real(eltype(dm)))) but it seems eigvals() operation have not been implemented in CUDA.jl.

I wander if there is any way to improve this operation in Yao.jl so that it can run successfully on the GPU, or alternatively, to only load the quantum state onto the CPU when calculating the entropy?

@zipeilee
Copy link
Author

zipeilee commented Dec 9, 2023

I have tried change the
p = max.(eigvals(dm), eps(real(eltype(dm))))
to

 _, l = eigen(dm)
p = max.(l, eps(real(eltype(dm))))

but due to computational precision, the density matrix is not a Hermitian matrix and LinearAlgebra.eigen() only seems to work for symmetric/hermitian inputs.

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

No branches or pull requests

1 participant