Problem performing trace calculation with GPU

Hi, ITensor Teams!

I am trying to use GPU to improve a code for studying quantum master equations. During the code in some parts, I need to calculate expectation values of a density matrix state. I calculate those expectation values using the trace definition \langle O \rangle = Tr( \rho O).

I found that there is a problem in general when I want to calculate traces using GPU.

using ITensors
using CUDA 

sites = siteinds("S=1/2",50)
O = MPO(sites, "Id")
tr(O) #Here I got: 1.1258999068426202e15

#Now, if we try the same with GPU:

O = cu(O)
tr(O) #Here I got: ArgumentError: cannot take the CPU address of a CuArray{Float64, 2, CUDA.Mem.DeviceBuffer}

Thanks for the report, it should be a simple fix. @kmp5

1 Like

For the time being you can perform the trace manually by contracting the bra and ket site indices of each site with delta tensors. EDIT: Though you have to make sure the delta tensors are constructed on GPU before contracting with the MPO, the current code isn’t doing that which is why it is failing.

1 Like

I made an issue about it here: [ITensors] [BUG] `tr` on GPU · Issue #1450 · ITensor/ITensors.jl · GitHub

1 Like

@mtfishman @Joacop16 I am looking into the problem, will create a PR soon and like it to the issue Matt made!

1 Like

Thank you, I will perform the trace manually as you suggests for now.

This is getting fixed in [NDTensors] Fix contracting dense with diag on GPU by kmp5VT · Pull Request #1453 · ITensor/ITensors.jl · GitHub, should be ready soon.

1 Like

@Joacop16 we’ve merged [NDTensors] Fix contracting dense with diag on GPU by kmp5VT · Pull Request #1453 · ITensor/ITensors.jl · GitHub, it will be available in NDTensors v0.3.18 which will be registered this evening.

The fix implemented by @kmp5 has some room for improvement in terms of performance, let us know if you see any performance issues and we can try to optimize the implementation.

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.