GTorlai / PastaQ.jl

Package for Simulation, Tomography and Analysis of Quantum Computers
Apache License 2.0
142 stars 23 forks source link

Trace of dense Choi matrix not correct #238

Closed GTorlai closed 2 years ago

GTorlai commented 2 years ago
N = 3 
depth = 4 
circuit = randomcircuit(N, depth; layered=false)
s = siteinds("Qubit",N)
Λ = choimatrix(circuit; noise = ("DEP",(p=0.01,)))
Φ = choimatrix(circuit; noise = ("DEP",(p=0.01,)), full_representation = true)
@test PastaQ.array(Λ) ≈ PastaQ.array(Φ)

@show tr(Φ)
# 1.024554202178227 - 0.6166353206217738im
# it should be 8

I could track the issue to here (which is called in the tr(T::ITensor,...) function:

@show ITensors.indpairs(Λ; plev= 0=> 1)
# ((dim=2|id=501|"Input,Qubit,Site,n=1") => (dim=2|id=911|"Input,Qubit,Site,n=3")', 
# (dim=2|id=970|"Input,Qubit,Site,n=2") => (dim=2|id=970|"Input,Qubit,Site,n=2")', 
# (dim=2|id=911|"Input,Qubit,Site,n=3") => (dim=2|id=501|"Input,Qubit,Site,n=1")', 
# (dim=2|id=501|"Output,Qubit,Site,n=1") => (dim=2|id=911|"Output,Qubit,Site,n=3")', 
# (dim=2|id=970|"Output,Qubit,Site,n=2") => (dim=2|id=970|"Output,Qubit,Site,n=2")',
# (dim=2|id=911|"Output,Qubit,Site,n=3") => (dim=2|id=501|"Output,Qubit,Site,n=1")')
mtfishman commented 2 years ago

More minimal:

julia> ITensors.indpairs(ITensor(j, k', i', k, j', i))
((dim=2|id=27|"j") => (dim=2|id=337|"i")', (dim=2|id=900|"k") => (dim=2|id=27|"j")', (dim=2|id=337|"i") => (dim=2|id=900|"k")')

Must be a permutation that is wrong, thanks for catching that!

mtfishman commented 2 years ago

This should be fixed by https://github.com/ITensor/ITensors.jl/pull/750.

However, I can't get the example you wrote above to run. It looks like there is a bug when calling choimatrix(circuit; noise = ("DEP",(p=0.01,))): https://github.com/GTorlai/PastaQ.jl/blob/00f47b9c2df4901f6ea2063e70c6a53b9da9722d/src/circuits/runcircuit.jl#L354-L355

Also, is choimatrix supposed to be exported?

GTorlai commented 2 years ago

Yeah I think I already fixed this locally. Thanks for the fix on ITensor, will update shortly.