Example #1
0
def prepL(i, t, L):
    # compute bitstring by adding rows of l
    Lbits = list(np.binary_repr(i, width=len(L)))
    bitstring = np.zeros(t)
    for idx in range(len(Lbits)):
        if Lbits[idx] == '1':
            bitstring += L[idx]
    bitstring = bitstring.astype(int) % 2

    # Stabilizer state is product of |0> and |+>
    # 1's in bitstring indicate positions of |+>

    # initialize stabilizer state
    phi = StabilizerState(t, t)

    # construct state using shrink
    for xtildeidx in range(t):
        if bitstring[xtildeidx] == 0:
            vec = np.zeros(t)
            vec[xtildeidx] = 1
            phi.shrink(vec, 0)
            # |0> at index, inner prod with 1 is 0
        # |+> at index -> do nothing

    return phi
Example #2
0
def load(psi):
    state = StabilizerState(psi["n"], psi["k"])
    state.G = np.array(psi["G"])
    state.Gbar = np.array(psi["Gbar"])
    state.h = np.array(psi["h"])

    if "D" in psi:
        state.D = np.array(psi["D"])[:state.k]
        state.J = np.array(psi["J"])[:state.k, :state.k] * 4
        state.Q = psi["Q"]

    return state
Example #3
0
def prepH(i, t):
    size = int(np.ceil(t / 2))
    odd = t % 2 == 1

    bits = list(np.binary_repr(i, width=size))

    # initialize stabilizer state
    phi = StabilizerState(t, t)

    # set J matrix
    for idx in range(size):
        bit = int(bits[idx])
        if bit == 0 and not (odd and idx == size - 1):
            # phi.J = np.array([[0, 4], [4, 0]])
            phi.J[idx * 2 + 1, idx * 2] = 4
            phi.J[idx * 2, idx * 2 + 1] = 4

    # truncate affine space using shrink
    for idx in range(size):
        bit = int(bits[idx])
        vec = np.zeros(t)

        if odd and idx == size - 1:
            # bit = 0 is |+>
            # bit = 1 is |0>
            if bit == 1:
                vec[t - 1] = 1
                phi.shrink(vec, 0)
            continue

        # bit = 1 corresponds to |00> + |11> state
        # bit = 0 corresponds to |00> + |01> + |10> - |11>

        if bit == 1:
            vec[idx * 2] = 1
            vec[idx * 2 + 1] = 1
            phi.shrink(vec, 0)  # only 00 and 11 have inner prod 0 with 11

    return phi
Example #4
0
f = open(directory + "ExponentialSum.txt")
tests = json.loads(f.read())
tests = []

indexcut = 0
failed = 0
index = 0
starttime = datetime.now()
for test in tests:
    index += 1
    if index < indexcut: continue
    # don't actually depend on n, but need for initialization
    k = len(test["D"]["D"])
    # k = 4
    state = StabilizerState(k, k)
    # state.D = np.array(test["D"]["D"])[:4]
    state.D = np.array(test["D"]["D"])
    # state.J = np.array(test["J"]["J"])[:4, :4]*4
    state.J = np.array(test["J"]["J"]) * 4
    state.Q = test["Q"]["Q"]

    (eps, p, m) = state.exponentialSum(exact=True)
    if eps != test["eps_out"]\
            or m != test["m_out"] % 8\
            or p != test["p_out"]:
        if failed == 0: print("ExponentialSum errors:")
        print(
            "ExponentialSum %d (k=%d) failed: (%d,%d,%d) should be (%d,%d,%d)"
            % (index, state.k, eps, p, m, test["eps_out"], test["p_out"],
               test["m_out"]))