Manuscript En02-B@1 · En02-B-v1.tex · section · ca28dee4

Exact finite checks and a schedule explorer

Exact finite checks and a schedule explorer · lines 2037–2140

Back to manuscript

def multiply_paulis(a, b): pa, wa = a pb, wb = b need(len(wa) == len(wb), "Pauli lengths differ") phase = (pa + pb) word = [] for x, y in zip(wa, wb): if x == "I": word.append(y) elif y == "I": word.append(x) elif x == y: word.append("I") else: p, z = LOCAL_PRODUCT[x, y] phase = (phase + p) word.append(z) return phase, "".join(word)

GENERATORS = ("XZZXI", "IXZZX", "XIXZZ", "ZXIXZ")

def stabilizer_group(): out = [] for selected in product((0, 1), repeat=4): p = (0, "IIIII") for use, word in zip(selected, GENERATORS): if use: p = multiply_paulis(p, (0, word)) out.append(p) need(len(set(out)) == 16, "stabilizers are dependent") need((2, "IIIII") not in out, "minus identity is a stabilizer") for phase, word in out: need(phase in (0, 2), "stabilizer is not Hermitian") if word != "IIIII": need(sum(x != "I" for x in word) == 4, "nonidentity stabilizer is not weight four") return tuple(out)

def encoded_integer_vectors(): """True code vectors are these Gaussian-integer vectors / 4.""" v = [ZERO] * 32 v[0] = ONE for g in GENERATORS: v = vadd(v, pauli_action(v, g)) w = pauli_action(v, "XXXXX") need(inner(v, v) == (16, 0), "wrong code-zero norm") need(inner(w, w) == (16, 0), "wrong code-one norm") need(inner(v, w) == ZERO, "codewords not orthogonal") need(pauli_action(v, "ZZZZZ") == v, "wrong logical Z zero") need(pauli_action(w, "ZZZZZ") == [neg(x) for x in w], "wrong logical Z one") for g in GENERATORS: need(pauli_action(v, g) == v, "zero not stabilized") need(pauli_action(w, g) == w, "one not stabilized") return v, w

def apply_gate(v, gate): """H is unnormalized: the omitted factor is 1/sqrt(2).""" n = nqubits(v) kind = gate[0] if kind in ("X", "Y", "Z"): q = gate[1] word = ["I"] * n word[q] = kind return pauli_action(v, "".join(word))

out = [ZERO] * len(v) if kind == "H": q = gate[1] for k, amp in enumerate(v): bs = list(bits(k, n)) old = bs[q] for new in (0, 1): bs[q] = new term = neg(amp) if old == 1 and new == 1 else amp target = index_of(bs) out[target] = add(out[target], term) return out

if kind == "SD": q = gate[1] for k, amp in enumerate(v): out[k] = mul(amp, (0, -1)) if bits(k, n)[q] else amp return out

if kind in ("CX", "CZ"): q, r = gate[1], gate[2] for k, amp in enumerate(v): bs = list(bits(k, n)) if kind == "CX": if bs[q]: bs[r] ^= 1 out[index_of(bs)] = amp else: out[k] = neg(amp) if bs[q] and bs[r] else amp return out

raise CheckFailure("unknown gate")

Nearby in this section