qec/lib.py
Dutta3
Dutta's 3-qubit code, which is a permutation-invariant code designed to be the smallest code that can correct a single AD error. The codewords are:
def Dutta3() -> CodeImplementation
def Dutta3() -> Code:
cw0 = pt.zeros(8)
cw1 = pt.zeros(8)
cw0[1] = 1
cw0[2] = 1
cw0[4] = 1
cw1[7] = 1
code = pt.stack([cw0 / pt.linalg.norm(cw0), cw1 / pt.linalg.norm(cw1)])
return Code(code)Leung
Leung's 4-qubit code, which is a standard code that can correct a single AD error. The codewords are:
$ |0_L\rangle = \frac{1}{\sqrt{2}}(|0000\rangle + |1111\rangle) \ |1_L\rangle = \frac{1}{\sqrt{2}}(|0011\rangle + |1100\rangle)
def Leung() -> CodeImplementation
def Leung() -> Code:
leung_0 = pt.zeros(16)
leung_1 = pt.zeros(16)
leung_0[0] = 1
leung_0[-1] = 1
leung_1[3] = 1
leung_1[12] = 1
code = pt.stack([leung_0 / pt.linalg.norm(leung_0), leung_1 / pt.linalg.norm(leung_1)])
return Code(code)Perfect
The
def Perfect() -> CodeImplementation
def Perfect() -> Code:
_0L = pt.zeros(32)
_1L = pt.zeros(32)
k0 = [0, 18, 9, 20, 10, -27, -6, -24, -29, -3, -30, -15, -17, -12, -23, 5]
k1 = [31, 13, 22, 11, 21, -4, -25, -7, -2, -28, -1, -16, -14, -19, -8, 26]
for i in range(len(k0)):
_0key = k0[i]
_1key = k1[i]
_0L[abs(_0key)] = 1.0 if _0key >= 0 else -1.0
_1L[abs(_1key)] = 1.0 if _1key >= 0 else -1.0
_0L[0] = 1
return Code(pt.stack([_0L / pt.linalg.norm(_0L), _1L / pt.linalg.norm(_1L)]))Qutrit3
3-qutrit repetition code: three codewords
Encodes one logical qutrit in three physical qutrits (
def Qutrit3() -> CodeImplementation
def Qutrit3() -> Code:
cw = pt.zeros(3, 27)
cw[0, 0] = 1.0
cw[1, 13] = 1.0
cw[2, 26] = 1.0
return Code(cw, d=3)GottesmanD
Gottesman-type CSS code for prime
Codewords:
For
def GottesmanD(d: int) -> CodeImplementation
def GottesmanD(d: int=2) -> Code:
n_phys = d
dim_total = d ** n_phys
cws = []
norm = 1.0 / math.sqrt(d)
for j in range(d):
vec = pt.zeros(dim_total, dtype=pt.complex64)
for a in range(d):
idx = 0
for pos in range(n_phys):
digit = (a + pos * j) % d
idx = idx * d + digit
vec[idx] += norm
cws.append(vec)
return Code(pt.stack(cws), d=d)Surface
Build an Code spanning the stabilizer space.
def Surface(m: int, n: int, d: int, edge: str, start: str) -> CodeImplementation
def Surface(m: int, n: int, d: int=2, edge: str='even', start: str='X') -> Code:
stabs = Stabilisers(m, n, edge=edge, start=start)
return Code.fromStabilizers(stabs, d=d)