GTorlai / PastaQ.jl

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

Fidelity betwee Choi MPOs shows unexpected behaviour #217

Closed GTorlai closed 3 years ago

GTorlai commented 3 years ago

The fidelity between two Choi matrices in MPO form breaks the tests with the new definition of the noise. It does that only for the depolarizing channel, which is somewhat weird. When looking for the problem, I also found a bizarre behavior of the product function in ITensors.


""" BRANCH: advancednoise """

using PastaQ
using ITensors
using Test
using Random

# first we define two different random circuits
Random.seed!(1234)
N = 3 
circuit1 = randomcircuit(N, 3)
circuit2 = randomcircuit(N, 3)

# and compute the Choi matrices for a depolarizing channel
sites = siteinds("Qubit",N)
ρ1 = PastaQ.choimatrix(sites, circuit1; noise=("DEP", (p=0.3,)))
ρ2 = PastaQ.choimatrix(sites, circuit2; noise=("DEP", (p=0.3,)))

# we now get the dense Choi matrices and normalized them
ρ1mat = PastaQ.array(ρ1)
ρ1mat = ρ1mat / tr(ρ1mat)
ρ2mat = PastaQ.array(ρ2)
ρ2mat = ρ2mat / tr(ρ2mat)

# first we compute the fidelity using PastaQ function on unnormalized states
Fpasta = fidelity(ρ1,ρ2; process = true)
@show Fpasta
# Fpasta = 0.4879283106332991

# then we compute the fidelity using the full formula on dense matrices
Fdirect = real(tr(sqrt(sqrt(ρ1mat) * ρ2mat * sqrt(ρ1mat))))^2
@show Fdirect
# Fdirect = 0.4846952791823069

# now we actually normalize the Choi matrices and repeat the pastaq calculation
normalize!(ρ1)
normalize!(ρ2)
Fpasta_norm = fidelity(ρ1,ρ2; process = true)
@show Fpasta_norm
# Fpasta_norm = 0.4914796073666302

# here we break down the internal pastaq function
ρ1prod = prod(ρ1)
ρ2prod = prod(ρ2)

# option 1
F2 = product(product(sqrt(ρ1prod), ρ2prod), sqrt(ρ1prod))
F2 = real(tr(sqrt(F2)))^2
@show F2
# F2 = 0.4921801299575313

# option 2
ρ1prod ./= tr(ρ1prod)
ρ2prod ./= tr(ρ2prod)
F3 = product(product(sqrt(ρ1prod), ρ2prod), sqrt(ρ1prod))
F3 = real(tr(sqrt(F3)))^2
@show F3
# F3 = 0.4914796073666302

ρ1prod ./= tr(ρ1prod)
ρ2prod ./= tr(ρ2prod)
F4 = product(product(sqrt(ρ1prod), ρ2prod), sqrt(ρ1prod))
F4 = real(tr(sqrt(F4)))^2
@show F4
# F4 = 0.4921801299575313