Skip to content

Commit 3b957be

Browse files
committed
WIP pauli
1 parent fe0b4d1 commit 3b957be

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

src/pauli.jl

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
1+
using TransmuteDims
12

2-
const PauliTransferType = Operator{<:ChoiBasis,<:ChoiBasis}
3+
const PauliTransferType = Operator{<:PauliBasis,<:PauliBasis}
34

4-
5-
# TODO this should maybe be exported?
6-
# TODO also maybe more efficient to super-tensor product vec'd single qubit transformation
7-
function _ketbra_to_pauli()
5+
# TODO should either of these functions be cached?
6+
function _pauli_to_ketbra1()
87
b = SpinBasis(1//2)
9-
pvec(fn) = vec(fn(b)).data
10-
kb2p = sparse(hcat(map(pvec, [identityoperator, sigmax, sigmay, sigmaz])...)')
8+
vec_it(fn) = vec(fn(b).data)
9+
p2kb = hcat(map(vec_it, [identityoperator, sigmax, sigmay, sigmaz])...)
10+
end
11+
12+
function _ketbra_to_pauli(N)
13+
T = kron((_pauli_to_ketbra1 for _=1:N)...)
14+
T = reshape(T, Tuple(4 for _=1:2N))
15+
T = PermutedDimsArray(T, ((2i-1 for i=1:N)..., (2i for i=1:N)...))
16+
reshape(T, (4^N, 4^N))
17+
end
18+
19+
function _op_to_pauli(Nl, Nr, data)
20+
Ul = ket_bra_to_pauli(Nl)
21+
Ur = Nl == Nr ? Ul : _ketbra_to_pauli(Nr)
22+
data = dagger(Ul) * data * Ur # TODO figure out normalization
23+
@assert isapprox(imag.(data), zero(data), atol=tol)
24+
Operator(PauliBasis()^Nl, PauliBasis()^Nr, real.(data))
1125
end
1226

13-
_Ukb2p = _ketbra_to_pauli()
27+
"""
28+
comp_to_pauli(N)
29+
30+
Creates a superoperator which changes from the computational `SpinBasis(1//2)`
31+
to the `PauliBasis()` over `N` qubits.
32+
"""
33+
function comp_to_pauli(N)
34+
T = kron((_pauli_to_ketbra1 for _=1:N)...)
35+
T = reshape(T, Tuple(4 for _=1:2N))
36+
T = PermutedDimsArray(T, ((2i-1 for i=1:N)..., (2i for i=1:N)...))
37+
sb = SpinBasis(1//2)^N
38+
Operator(PauliBasis()^N, KetBraBasis(sb, sb), reshape(T, (4^N, 4^N))
39+
end
1440

1541
function pauli(op::SuperOperatorType; tol=1e-9)
1642
bl, br = basis_l(op), basis_r(op)
@@ -24,7 +50,7 @@ function pauli(op::SuperOperatorType; tol=1e-9)
2450

2551
Nl, Nr = length(basis_l(bl)), length(basis_l(br))
2652
Ul = ket_bra_to_pauli(Nl)
27-
Ur = Nl == Nr ? Ul : ket_bra_to_pauli(Nr)
53+
Ur = Nl == Nr ? Ul : _ketbra_to_pauli(Nr)
2854
data = dagger(Ul)*op.data*Ur # TODO figure out normalization
2955
@assert isapprox(imag.(data), zero(data), atol=tol)
3056
Operator(PauliBasis()^Nl, PauliBasis()^Nr, real.(data))
@@ -36,7 +62,7 @@ function chi(op::ChoiStateType; tol=1e-9)
3662
bl, br = basis_l(basis_l(op)), basis_r(basis_l(op))
3763
for b in (bl, br)
3864
for i=1:length(b)
39-
(b[i] isa NLevelBasis) || throw(ArgumentError("Choi state must be over systems composed of SpinBasis(1//2) to be converted to chi representation"))
65+
(b[i] isa SpinBasis && dimension(b[i]) == 2) || throw(ArgumentError("Choi state must be over systems composed of SpinBasis(1//2) to be converted to chi representation"))
4066
end
4167
end
4268

@@ -49,7 +75,7 @@ function chi(op::ChoiStateType; tol=1e-9)
4975
end
5076

5177
"""
52-
function pauli(op::SuperOperatorType; tol=1e-9)
78+
function hwpauli(op::SuperOperatorType; tol=1e-9)
5379
bl, br = basis_l(op), basis_r(op)
5480
((basis_l(bl) == basis_r(bl)) && (basis_l(br) == basis_r(br))) || throw(ArgumentError("Superoperator must map between square operators in order to be converted to pauli represenation"))
5581

src/superoperators.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ const ChoiStateType = Operator{<:ChoiBasis,<:ChoiBasis}
2020
vec(op::Operator) = Ket(KetBraBasis(basis_l(op), basis_r(op)), vec(op.data))
2121
function unvec(k::SuperKetType)
2222
bl, br = basis_l(basis(k)), basis_r(basis(k))
23-
@cast A[n,m] |= k.data[(n,m)] (n 1:dimension(bl), m 1:dimension(br))
24-
return Operator(bl, br, A)
23+
Operator(bl, br, reshape(k.data, dimension(bl), dimension(br)))
2524
end
25+
#function unvec(k::SuperKetType)
26+
# bl, br = basis_l(basis(k)), basis_r(basis(k))
27+
# @cast A[n,m] |= k.data[(n,m)] (n ∈ 1:dimension(bl), m ∈ 1:dimension(br))
28+
# return Operator(bl, br, A)
29+
#end
2630

2731
function spre(op::Operator)
2832
multiplicable(op, op) || throw(ArgumentError("It's not clear what spre of a non-square operator should be. See issue #113"))
@@ -33,8 +37,12 @@ function spost(op::Operator)
3337
multiplicable(op, op) || throw(ArgumentError("It's not clear what spost of a non-square operator should be. See issue #113"))
3438
sprepost(identityoperator(op), op)
3539
end
40+
#function sprepost(A::Operator, B::Operator)
41+
# @cast C[(ν,μ), (n,m)] |= A.data[ν,n] * B.data[m,μ]
42+
# Operator(KetBraBasis(basis_l(A), basis_r(B)), KetBraBasis(basis_r(A), basis_l(B)), C)
43+
#end
3644

37-
#sprepost(A::Operator, B::Operator) = Operator(KetBraBasis(A.basis_l, B.basis_r), KetBraBasis(A.basis_r, B.basis_l), kron(permutedims(B.data), A.data))
45+
#sprepost(A::Operator, B::Operator) = Operator(KetBraBasis(basis_l(A), basis_r(B)), KetBraBasis(basis_r(A), basis_l(B)), kron(permutedims(B.data), A.data))
3846

3947
function sprepost(A::Operator, B::Operator)
4048
@cast C[(ν,μ), (n,m)] |= A.data[ν,n] * B.data[m,μ]
@@ -63,7 +71,6 @@ super(op::ChoiStateType) = _super_choi(KetBraBasis, op)
6371

6472
dagger(a::ChoiStateType) = choi(dagger(super(a)))
6573

66-
*(a::SuperOperatorType, b::SuperOperatorType) = (check_multiplicable(a,b); Operator(a.basis_l, b.basis_r, a.data*b.data))
6774
*(a::SuperOperatorType, b::Operator) = unvec(a*vec(b))
6875
*(a::ChoiStateType, b::SuperOperatorType) = super(a)*b
6976
*(a::SuperOperatorType, b::ChoiStateType) = a*super(b)

0 commit comments

Comments
 (0)