Mapping
In [ ]:
Copied!
import sympy as sp
from sympy.physics.quantum import Dagger as dag, TensorProduct as tensor
import sympy as sp
from sympy.physics.quantum import Dagger as dag, TensorProduct as tensor
In [ ]:
Copied!
# 1Q Pauli
I = sp.Matrix(
[
[1, 0],
[0, 1],
],
)
X = sp.Matrix(
[
[0, 1],
[1, 0],
],
)
Y = sp.Matrix(
[
[0, -sp.I],
[sp.I, 0],
],
)
Z = sp.Matrix(
[
[1, 0],
[0, -1],
],
)
# 1Q Pauli
I = sp.Matrix(
[
[1, 0],
[0, 1],
],
)
X = sp.Matrix(
[
[0, 1],
[1, 0],
],
)
Y = sp.Matrix(
[
[0, -sp.I],
[sp.I, 0],
],
)
Z = sp.Matrix(
[
[1, 0],
[0, -1],
],
)
In [ ]:
Copied!
# 2Q Pauli
PAULI_2Q = {
"II": tensor(I, I),
"IX": tensor(I, X),
"IY": tensor(I, Y),
"IZ": tensor(I, Z),
"XI": tensor(X, I),
"XX": tensor(X, X),
"XY": tensor(X, Y),
"XZ": tensor(X, Z),
"YI": tensor(Y, I),
"YX": tensor(Y, X),
"YY": tensor(Y, Y),
"YZ": tensor(Y, Z),
"ZI": tensor(Z, I),
"ZX": tensor(Z, X),
"ZY": tensor(Z, Y),
"ZZ": tensor(Z, Z),
}
# 2Q Pauli
PAULI_2Q = {
"II": tensor(I, I),
"IX": tensor(I, X),
"IY": tensor(I, Y),
"IZ": tensor(I, Z),
"XI": tensor(X, I),
"XX": tensor(X, X),
"XY": tensor(X, Y),
"XZ": tensor(X, Z),
"YI": tensor(Y, I),
"YX": tensor(Y, X),
"YY": tensor(Y, Y),
"YZ": tensor(Y, Z),
"ZI": tensor(Z, I),
"ZX": tensor(Z, X),
"ZY": tensor(Z, Y),
"ZZ": tensor(Z, Z),
}
In [ ]:
Copied!
# 1Q Clifford
X90 = sp.Matrix(
[
[1, -sp.I],
[-sp.I, 1],
],
) / sp.sqrt(2)
Y90 = sp.Matrix(
[
[1, -1],
[1, 1],
],
) / sp.sqrt(2)
Z90 = sp.Matrix(
[
[1 - sp.I, 0],
[0, 1 + sp.I],
],
) / sp.sqrt(2)
# 1Q Clifford
X90 = sp.Matrix(
[
[1, -sp.I],
[-sp.I, 1],
],
) / sp.sqrt(2)
Y90 = sp.Matrix(
[
[1, -1],
[1, 1],
],
) / sp.sqrt(2)
Z90 = sp.Matrix(
[
[1 - sp.I, 0],
[0, 1 + sp.I],
],
) / sp.sqrt(2)
In [ ]:
Copied!
# 1Qx1Q Clifford
II = tensor(I, I)
IX90 = tensor(I, X90)
IY90 = tensor(I, Y90)
IZ90 = tensor(I, Z90)
XI90 = tensor(X90, I)
YI90 = tensor(Y90, I)
ZI90 = tensor(Z90, I)
# 1Qx1Q Clifford
II = tensor(I, I)
IX90 = tensor(I, X90)
IY90 = tensor(I, Y90)
IZ90 = tensor(I, Z90)
XI90 = tensor(X90, I)
YI90 = tensor(Y90, I)
ZI90 = tensor(Z90, I)
In [ ]:
Copied!
# 2Q Clifford
ZX90 = sp.Matrix(
[
[1, -sp.I, 0, 0],
[-sp.I, 1, 0, 0],
[0, 0, 1, sp.I],
[0, 0, sp.I, 1],
]
) / sp.sqrt(2)
ZZ90 = sp.Matrix(
[
[1 - sp.I, 0, 0, 0],
[0, 1 + sp.I, 0, 0],
[0, 0, 1 + sp.I, 0],
[0, 0, 0, 1 - sp.I],
]
) / sp.sqrt(2)
CNOT = sp.Matrix(
[
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0],
],
)
CZ = sp.Matrix(
[
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, -1],
],
)
SWAP = sp.Matrix(
[
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
],
)
ISWAP = sp.Matrix(
[
[1, 0, 0, 0],
[0, 0, sp.I, 0],
[0, sp.I, 0, 0],
[0, 0, 0, 1],
],
)
BSWAP = sp.Matrix(
[
[0, 0, 0, sp.I],
[0, 1, 0, 0],
[0, 0, 1, 0],
[sp.I, 0, 0, 0],
],
)
# 2Q Clifford
ZX90 = sp.Matrix(
[
[1, -sp.I, 0, 0],
[-sp.I, 1, 0, 0],
[0, 0, 1, sp.I],
[0, 0, sp.I, 1],
]
) / sp.sqrt(2)
ZZ90 = sp.Matrix(
[
[1 - sp.I, 0, 0, 0],
[0, 1 + sp.I, 0, 0],
[0, 0, 1 + sp.I, 0],
[0, 0, 0, 1 - sp.I],
]
) / sp.sqrt(2)
CNOT = sp.Matrix(
[
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0],
],
)
CZ = sp.Matrix(
[
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, -1],
],
)
SWAP = sp.Matrix(
[
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
],
)
ISWAP = sp.Matrix(
[
[1, 0, 0, 0],
[0, 0, sp.I, 0],
[0, sp.I, 0, 0],
[0, 0, 0, 1],
],
)
BSWAP = sp.Matrix(
[
[0, 0, 0, sp.I],
[0, 1, 0, 0],
[0, 0, 1, 0],
[sp.I, 0, 0, 0],
],
)
In [ ]:
Copied!
# 2Q Non-Clifford
SQRT_ISWAP = sp.Matrix(
[
[sp.sqrt(2), 0, 0, 0],
[0, 1, sp.I, 0],
[0, sp.I, 1, 0],
[0, 0, 0, sp.sqrt(2)],
],
) / sp.sqrt(2)
BGATE = sp.Matrix(
[
[sp.cos(sp.pi / 8), 0, 0, sp.I * sp.sin(sp.pi / 8)],
[0, sp.sin(sp.pi / 8), sp.I * sp.cos(sp.pi / 8), 0],
[0, sp.I * sp.cos(sp.pi / 8), sp.sin(sp.pi / 8), 0],
[sp.I * sp.sin(sp.pi / 8), 0, 0, sp.cos(sp.pi / 8)],
],
)
# 2Q Non-Clifford
SQRT_ISWAP = sp.Matrix(
[
[sp.sqrt(2), 0, 0, 0],
[0, 1, sp.I, 0],
[0, sp.I, 1, 0],
[0, 0, 0, sp.sqrt(2)],
],
) / sp.sqrt(2)
BGATE = sp.Matrix(
[
[sp.cos(sp.pi / 8), 0, 0, sp.I * sp.sin(sp.pi / 8)],
[0, sp.sin(sp.pi / 8), sp.I * sp.cos(sp.pi / 8), 0],
[0, sp.I * sp.cos(sp.pi / 8), sp.sin(sp.pi / 8), 0],
[sp.I * sp.sin(sp.pi / 8), 0, 0, sp.cos(sp.pi / 8)],
],
)
In [ ]:
Copied!
ZX90
ZX90
In [ ]:
Copied!
ZX90 * ZX90
ZX90 * ZX90
In [ ]:
Copied!
-sp.I * tensor(Z, X)
-sp.I * tensor(Z, X)
In [ ]:
Copied!
(SQRT_ISWAP * SQRT_ISWAP).equals(ISWAP)
(SQRT_ISWAP * SQRT_ISWAP).equals(ISWAP)
In [ ]:
Copied!
for k, v in PAULI_2Q.items():
print(f"{k} =")
display(v)
for k, v in PAULI_2Q.items():
print(f"{k} =")
display(v)
In [ ]:
Copied!
def create_pauli_mapping(C: sp.Matrix):
"""Return Pauli mappings induced by a Clifford matrix."""
mapping = {}
for label, P in PAULI_2Q.items():
P_mapped = C * P * dag(C)
P_mapped.simplify()
print(f"{label} ->")
display(P_mapped)
for k, v in PAULI_2Q.items():
for sign in [1, -1, sp.I, -sp.I]:
if P_mapped.equals(sign * v):
mapping[label] = (sign, k)
print(f"= {sign} * {k}\n")
break
# print if not found
if label not in mapping:
print(f"Could not find mapping for {label}\n")
return mapping
def create_pauli_mapping(C: sp.Matrix):
"""Return Pauli mappings induced by a Clifford matrix."""
mapping = {}
for label, P in PAULI_2Q.items():
P_mapped = C * P * dag(C)
P_mapped.simplify()
print(f"{label} ->")
display(P_mapped)
for k, v in PAULI_2Q.items():
for sign in [1, -1, sp.I, -sp.I]:
if P_mapped.equals(sign * v):
mapping[label] = (sign, k)
print(f"= {sign} * {k}\n")
break
# print if not found
if label not in mapping:
print(f"Could not find mapping for {label}\n")
return mapping
In [ ]:
Copied!
create_pauli_mapping(ZX90)
create_pauli_mapping(ZX90)
In [ ]:
Copied!
create_pauli_mapping(ZZ90)
create_pauli_mapping(ZZ90)
In [ ]:
Copied!
create_pauli_mapping(CNOT)
create_pauli_mapping(CNOT)
In [ ]:
Copied!
create_pauli_mapping(CZ)
create_pauli_mapping(CZ)
In [ ]:
Copied!
create_pauli_mapping(SWAP)
create_pauli_mapping(SWAP)
In [ ]:
Copied!
create_pauli_mapping(ISWAP)
create_pauli_mapping(ISWAP)
In [ ]:
Copied!
create_pauli_mapping(BSWAP)
create_pauli_mapping(BSWAP)
In [ ]:
Copied!
create_pauli_mapping(SQRT_ISWAP)
create_pauli_mapping(SQRT_ISWAP)
In [ ]:
Copied!
create_pauli_mapping(BGATE)
create_pauli_mapping(BGATE)