|
1 | | -import QuantumInterface: KetBraBasis, ChoiBasis, PauliBasis, ChiBasis |
2 | | -using TensorCast |
| 1 | +import QuantumInterface: KetBraBasis, ChoiBasis |
| 2 | +#using TensorCast |
3 | 3 |
|
4 | | -const SOpBasis = Union{KetBraBasis, PauliBasis} |
5 | | -const SuperOperatorType{BL,BR,T} = Operator{BL,BR,T} where {BL<:SOpBasis,BR<:SOpBasis} |
6 | | -const SOpKetBraType{BL,BR,T} = Operator{BL,BR,T} where {BL<:KetBraBasis,BR<:KetBraBasis} |
7 | | -const SOpPauliType{BL,BR,T} = Operator{BL,BR,T} where {BL<:PauliBasis,BR<:PauliBasis} |
| 4 | +const SuperOperatorType{BL,BR,T} = Operator{BL,BR,T} where {BL<:KetBraBasis,BR<:KetBraBasis} |
8 | 5 | const ChoiStateType{BL,BR,T} = Operator{BL,BR,T} where {BR<:ChoiBasis,BL<:ChoiBasis} |
9 | | -const ChoiKetBraType{BL,BR,T} = Operator{ChoiBasis{BL,BR},ChoiBasis{BL,BR},T} where {BL<:KetBraBasis,BR<:KetBraBasis} |
10 | | -const ChiType{BL,BR,T} = Operator{ChoiBasis{BL,BR},ChoiBasis{BL,BR},T} where {BL<:PauliBasis,BR<:PauliBasis} |
11 | 6 |
|
12 | | -const DenseSuperOpPureType{BL,BR} = SuperOperatorType{BL,BR,<:Matrix} |
13 | | -const DenseSuperOpAdjType{BL,BR} = SuperOperatorType{BL,BR,<:Adjoint{<:Number,<:Matrix}} |
14 | | -const DenseSuperOpType{BL,BR} = Union{DenseOpPureType{BL,BL},DenseOpAdjType{BL,BR}} |
15 | | -const SparseSuperOpPureType{BL,BR} = SuperOperatorType{BL,BR,<:SparseMatrixCSC} |
16 | | -const SparseSuperOpAdjType{BL,BR} = SuperOperatorType{BL,BR,<:Adjoint{<:Number,<:SparseMatrixCSC}} |
17 | | -const SparseSuperOpType{BL,BR} = Union{SparseOpPureType{BL,BR},SparseOpAdjType{BL,BR}} |
| 7 | +#const SOpBasis = Union{KetBraBasis, PauliBasis} |
| 8 | +#const SuperOperatorType{BL,BR,T} = Operator{BL,BR,T} where {BL<:SOpBasis,BR<:SOpBasis} |
| 9 | +#const SOpKetBraType{BL,BR,T} = Operator{BL,BR,T} where {BL<:KetBraBasis,BR<:KetBraBasis} |
| 10 | +#const SOpPauliType{BL,BR,T} = Operator{BL,BR,T} where {BL<:PauliBasis,BR<:PauliBasis} |
| 11 | +#const ChoiStateType{BL,BR,T} = Operator{BL,BR,T} where {BR<:ChoiBasis,BL<:ChoiBasis} |
| 12 | +#const ChannelType = Union{SOpKetBraType, SOpPauliType, ChoiStateType, ChiType} |
| 13 | + |
| 14 | +#const DenseSuperOpPureType{BL,BR} = SuperOperatorType{BL,BR,<:Matrix} |
| 15 | +#const DenseSuperOpAdjType{BL,BR} = SuperOperatorType{BL,BR,<:Adjoint{<:Number,<:Matrix}} |
| 16 | +#const DenseSuperOpType{BL,BR} = Union{DenseOpPureType{BL,BL},DenseOpAdjType{BL,BR}} |
| 17 | +#const SparseSuperOpPureType{BL,BR} = SuperOperatorType{BL,BR,<:SparseMatrixCSC} |
| 18 | +#const SparseSuperOpAdjType{BL,BR} = SuperOperatorType{BL,BR,<:Adjoint{<:Number,<:SparseMatrixCSC}} |
| 19 | +#const SparseSuperOpType{BL,BR} = Union{SparseOpPureType{BL,BR},SparseOpAdjType{BL,BR}} |
18 | 20 |
|
19 | 21 | vec(op::Operator) = Ket(KetBraBasis(basis_l(op), basis_r(op)), vec(op.data)) |
20 | 22 | function unvec(k::Ket{<:KetBraBasis}) |
@@ -43,15 +45,20 @@ sprepost(A::Operator, B::Operator) = Operator(KetBraBasis(basis_l(A), basis_r(B) |
43 | 45 | # Operator(KetBraBasis(basis_l(A), basis_r(B)), KetBraBasis(basis_r(A), basis_l(B)), C) |
44 | 46 | #end |
45 | 47 |
|
46 | | -function tensor(A::SuperOperatorType, B::SuperOperatorType) |
| 48 | +function tensor(A::T, B::T) where T<:Union{SuperOperatorType, ChoiStateType} |
47 | 49 | a1, a2 = basis_l(A), basis_r(A) |
48 | 50 | b1, b2 = basis_l(B), basis_r(B) |
49 | 51 | #da1, da2, db1, db2 = map(dimension, (a1, a2, b1, b2)) |
50 | 52 | #@cast C[(ν,μ), (n,m)] |= A.data[m,μ] * B.data[n,ν] (m ∈ 1:da1, μ ∈ 1:da2, n ∈ 1:db1, ν ∈ 1:db2) |
| 53 | + #data = kron(B.data, A.data) |
| 54 | + #data = reshape(data, map(dimension, (a1, a2, b1, b2))) |
| 55 | + #data = PermutedDimsArray(data, (4, 2, 3, 1)) |
| 56 | + #data = reshape(data, map(dimension, (a2⊗b2, a1⊗b1))) |
| 57 | + #return Operator(a1⊗b1, a2⊗b2, data) |
51 | 58 | data = kron(B.data, A.data) |
52 | 59 | data = reshape(data, map(dimension, (a1, a2, b1, b2))) |
53 | | - data = PermutedDimsArray(data, (4, 2, 3, 1)) |
54 | | - data = reshape(data, map(dimension, (a2⊗b2, a1⊗b1))) |
| 60 | + data = PermutedDimsArray(data, (1, 3, 2, 4)) |
| 61 | + data = reshape(data, map(dimension, (a1⊗b1, a2⊗b2))) |
55 | 62 | return Operator(a1⊗b1, a2⊗b2, data) |
56 | 63 | end |
57 | 64 |
|
@@ -86,31 +93,42 @@ function _super_choi(basis_fn, op) |
86 | 93 | #data = _sch(op.data, l1, l2, r1, r2) |
87 | 94 | #dl1, dl2, dr1, dr2 = map(dimension, (l1, l2, r1, r2)) |
88 | 95 | #@cast A[(ν,μ), (n,m)] |= op.data[(m,μ), (n,ν)] (m ∈ 1:dl1, μ ∈ 1:dl2, n ∈ 1:dr1, ν ∈ 1:dr2) |
| 96 | + |
| 97 | + #data = reshape(op.data, map(dimension, (l1, l2, r1, r2))) |
| 98 | + #data = PermutedDimsArray(data, (4, 2, 3, 1)) |
| 99 | + #data = reshape(data, map(dimension, (r2⊗l2, r1⊗l1))) |
| 100 | + #return Operator(basis_fn(r2, l2), basis_fn(r1, l1), data) |
| 101 | + |
89 | 102 | data = reshape(op.data, map(dimension, (l1, l2, r1, r2))) |
90 | | - data = PermutedDimsArray(data, (4, 2, 3, 1)) |
91 | | - data = reshape(data, map(dimension, (l2⊗r2, l1⊗r1))) |
92 | | - return Operator(basis_fn(r2, l2), basis_fn(r1, l1), data) |
| 103 | + data = PermutedDimsArray(data, (1, 3, 2, 4)) |
| 104 | + data = reshape(data, map(dimension, (l1⊗r1, l2⊗r2))) |
| 105 | + return Operator(basis_fn(l1, r1), basis_fn(l2, r2), data) |
93 | 106 | end |
94 | 107 |
|
95 | 108 | choi(op::SuperOperatorType) = _super_choi(ChoiBasis, op) |
96 | 109 | super(op::ChoiStateType) = _super_choi(KetBraBasis, op) |
| 110 | +super(op::SuperOperatorType) = op |
| 111 | +choi(op::ChoiStateType) = op |
97 | 112 |
|
98 | 113 | # I'm not sure this is actually right... see sec V.C. of https://arxiv.org/abs/1111.6950 |
99 | 114 | dagger(a::ChoiStateType) = choi(dagger(super(a))) |
100 | 115 |
|
101 | 116 | # This method is necessary so we don't fall back to the method below it |
102 | 117 | *(a::SuperOperatorType, b::SuperOperatorType) = (check_multiplicable(a,b); Operator(a.basis_l, b.basis_r, a.data*b.data)) |
103 | 118 | *(a::SuperOperatorType, b::Operator) = unvec(a*vec(b)) |
104 | | -*(a::ChoiStateType, b::SuperOperatorType) = super(a)*b |
105 | | -*(a::SuperOperatorType, b::ChoiStateType) = a*super(b) |
| 119 | + |
106 | 120 | *(a::ChoiStateType, b::ChoiStateType) = choi(super(a)*super(b)) |
107 | 121 | *(a::ChoiStateType, b::Operator) = super(a)*b |
108 | 122 |
|
| 123 | +*(a::ChoiStateType, b::SuperOperatorType) = super(a)*b |
| 124 | +*(a::SuperOperatorType, b::ChoiStateType) = a*super(b) |
| 125 | + |
| 126 | + |
109 | 127 | identitysuperoperator(b::Basis) = Operator(KetBraBasis(b,b), KetBraBasis(b,b), Eye{ComplexF64}(dimension(b)^2)) |
110 | 128 |
|
111 | | -identitysuperoperator(op::DenseSuperOpType) = |
| 129 | +identitysuperoperator(op::DenseOpType{BL,BR}) where {BL<:KetBraBasis, BR<:KetBraBasis} = |
112 | 130 | Operator(op.basis_l, op.basis_r, Matrix(one(eltype(op.data))I, size(op.data))) |
113 | 131 |
|
114 | | -identitysuperoperator(op::SparseSuperOpType) = |
| 132 | +identitysuperoperator(op::SparseOpType{BL,BR}) where {BL<:KetBraBasis, BR<:KetBraBasis} = |
115 | 133 | Operator(op.basis_l, op.basis_r, sparse(one(eltype(op.data))I, size(op.data))) |
116 | 134 |
|
0 commit comments