Exemplo n.º 1
0
def circuit_syndrome_test():
    """
    compares syndromes generated by measurement circuit with q = 0 to
    those generated by perfect stabiliser measurement from 2D
    simulation. 
    They all ought to match.
    """
    two_d_sim = dc2.Sim2D(15, 15, 0.00)
    three_d_sim = dc3.Sim3D(15, 1000, ('pq', 0.1, 0.0))
    err_hist, synd_hist = three_d_sim.history()

    for idx, err in enumerate(err_hist):
        idl_x_synd, idl_z_synd = two_d_sim.syndromes(err)
        assert synd_hist['X'][idx] == set(idl_x_synd)
        assert synd_hist['Z'][idx] == set(idl_z_synd)
Exemplo n.º 2
0
def run_batch(err_lo,
              err_hi,
              n_points,
              dists,
              n_trials,
              flnm,
              sim_type='iidxz'):
    """
    Makes a bunch of simulation objects and runs them, based on input
    parameters.
    """
    sim_type = sim_type.lower()
    if sim_type not in ['iidxz', 'pq', 'circ']:
        raise ValueError("sim_type must be one of: ['iidxz', 'pq', 'circ']")

    errs = np.linspace(err_lo, err_hi, n_points)
    output_dict = locals()

    for dist in dists:
        failures = []
        for err in errs:
            if sim_type == 'iidxz':
                current_sim = dc2.Sim2D(dist, dist, err)
            elif sim_type == 'pq':
                current_sim = dc3.Sim3D(dist, dist, ('pq', err, err))
            elif sim_type == 'circ':
                raise NotImplementedError("Coming Soon!")

            current_sim.run(n_trials, progress=False)
            failures.append(current_sim.errors)
        output_dict.update({'failures ' + str(dist): failures})

    with open(flnm, 'wb') as phil:
        pkl.dump(output_dict, phil)

    pass
Exemplo n.º 3
0
def calc_parity_3d(dist, meas_rnds, model, use_blossom):
    """
    Calculates the amount of errors after d faulty Surface 
    code rounds mod 2. Based on the result we know the logical
    state of the logical qubit
    """
    #dq = [1,2,3,7,8,9,13,14,15]
    no_anc = (d + 1) * (d - 1) / 2
    flp = [0] * no_anc
    #flips_X = flp * (d+1)
    flips_Z = [0] * (d + 1)
    for i in range(d + 1):
        flips_Z[i] = deepcopy(flp)

    sim = dc3.Sim3D(dist, meas_rnds, model, use_blossom)
    err_history, syndrome_history = sim.history()
    #print('err_history ', err_history)
    #print('syndrome_history ', syndrome_history)
    #print("-----------")
    #print(err_history[2].x_set)
    #print(err_history[2].z_set)
    #print("-----------")
    #print(len(err_history[2].x_set))
    #print(len(err_history[2].z_set))
    #print("-----------")
    #print(len(err_history[2].x_set) % 2)
    #print(len(err_history[2].z_set) % 2)
    #print("-----------")
    x_parity = len(err_history[2].x_set) % 2
    #z_parity = len(err_history[2].z_set) % 2

    if x_parity == 1:
        log_err = 'X'
    else:
        log_err = 'I'

    #if x_parity == 0:
    #    log_err = 'I' if z_parity == 0 else 'Z'
    #else:
    #    log_err = 'X' if z_parity == 0 else 'Y'
    #print('log_err ', log_err)
    #print(syndrome_history.items())

    #sim_test = dc.Sim2D(3, 3, 0.01)
    #test_layout = SCLayoutClass.SCLayout(3)
    #print(sim_test.layout.map)
    #print(sim_test.layout.map.inv)
    #x_ancs = sim_test.layout.x_ancs()
    #z_ancs = sim_test.layout.z_ancs()
    #errors_X = ''
    #errors_Z = ''
    #for i in range(len(dq)):
    #    errors_X += ('1' if dq[i] in err_history[2].x_set else '0') + ' '
    #    errors_Z += ('1' if dq[i] in err_history[2].z_set else '0') + ' '

    #if d == 3:
    #x_ancs = [4,6,10,12]
    #z_ancs = [0,5,11,16]
    #elif d == 5:
    #x_ancs = [7,9,11,17,19,21,27,29,31,37,39,41]
    z_ancs = [0, 1, 8, 10, 18, 20, 28, 30, 38, 40, 47, 48]
    '''
    for j in range(4):
        for i in range(4):
            if (x_ancs[i] in syndrome_history['X'][j] and x_ancs[i] in syndrome_history['X'][j+1]) or \
               (x_ancs[i] not in syndrome_history['X'][j] and x_ancs[i] not in syndrome_history['X'][j+1]):
                flips_X[j][i] = 0
            else:
                flips_X[j][i] = 1
    '''
    #print(flips_Z)
    for j in range(d + 1):
        for i in range(no_anc):
            if (z_ancs[i] in syndrome_history['Z'][j] and z_ancs[i] in syndrome_history['Z'][j+1]) or \
               (z_ancs[i] not in syndrome_history['Z'][j] and z_ancs[i] not in syndrome_history['Z'][j+1]):
                flips_Z[j][i] = 0
            else:
                flips_Z[j][i] = 1

    return flips_Z, log_err  # flips_X, [errors_X, errors_Z]#, [x_parity, z_parity]
Exemplo n.º 4
0
    # dist_7_single_sample()
    #dumbest_dataset(5, 0.08, 1000000, 'd_5_dataset_million')
    d = 3
    ms_rnd = 3
    no_anc = int((d + 1) * (d - 1) / 2)
    p = 0.04
    q = 0.04
    samples = {}
    z_ancs = [0, 5, 11, 16]
    flp = [0] * no_anc
    flips_Z = [0] * (d + 1)
    for i in range(d + 1):
        flips_Z[i] = deepcopy(flp)
    no_samples = 10000
    sim_test2d = dc2.Sim2D(d, d, p)
    sim_test = dc3.Sim3D(d, d, ('fowler', p), True)
    #err = sim_test.run(no_samples, progress=False, metric=None, bdy_info=None, final_perfect_rnd=True)
    #print(err)

    #calc_parity_3d(dist, meas_rnds, model, use_blossom)

    for cycl in range(1000000):
        err, synd = sim_test.history(True)
        rnd_err = err[2].x_set
        rd_er = sp.Pauli(rnd_err, [])
        corr_blossom = sim_test.correction(synd, metric=None, bdy_info=None)
        mwpm_log_err = sim_test.logical_error(err[-1], corr_blossom)
        synds_2d = sim_test2d.syndromes(rd_er)
        dumb_x_corr, dumb_z_corr = sim_test2d.dumb_correction(synds_2d, False)
        dumb_log_err = sim_test2d.logical_error(rd_er, dumb_x_corr,
                                                dumb_z_corr)
Exemplo n.º 5
0
import decoding_2d as dc2
import decoding_3d as dc3
import error_model as em
from functools import reduce
import sparse_pauli as sp
import tensorflow as tf
import numpy as np
import time
from datetime import timedelta
import random

d = 3
p=0.08
iterations = 5000
sim_test2d = dc2.Sim2D(d, d, p)
sim_test = dc3.Sim3D(d, d, ('pq', p, p), True)
z_ancs_keys = list(sim_test.layout.z_ancs())
logicals = sim_test.layout.logicals()
cycles = 0
mwpm_log_err = 0
plut_log_err = 0
mwpm = 0
dumb = 0
nn = 0

def weight_variable(shape):
    initial = tf.truncated_normal(shape, stddev=0.01)
    return tf.Variable(initial)

def bias_variable(shape):
    initial = tf.constant(0.05, shape=shape)
Exemplo n.º 6
0
def run_batch(err_lo,
              err_hi,
              n_points,
              dists,
              n_trials,
              flnm,
              sim_type='iidxz',
              bc='rotated',
              bp=False):
    """
    Makes a bunch of simulation objects and runs them, based on input
    parameters. 
    """
    sim_type = sim_type.lower()
    if sim_type not in ['iidxz', 'dep', 'pq', 'circ']:
        raise ValueError(
            "sim_type must be one of: ['iidxz', 'dep', 'pq', 'circ']")

    errs = np.linspace(err_lo, err_hi, n_points)
    output_dict = locals()

    for dist in dists:
        failures = []
        for err in errs:
            if sim_type in ['iidxz', 'dep']:
                # current_sim = dc2.Sim2D(dist, dist, err, useBlossom=False, boundary_conditions=bc)
                # dist_func = fancy_dist(dist, err, bc=bc)
                # dist_func = entropic_dist(dist, err)
                if bc == 'open':
                    current_sim = dc2.Sim2D(dist,
                                            dist,
                                            err,
                                            useBlossom=True,
                                            boundary_conditions=bc)
                else:
                    current_sim = dc2.Sim2D(dist,
                                            dist,
                                            err,
                                            useBlossom=True,
                                            boundary_conditions=bc)
            elif sim_type == 'pq':
                current_sim = dc3.Sim3D(dist, dist, ('pq', err, err))
            elif sim_type == 'circ':
                current_sim = dc3.Sim3D(dist, dist, ('fowler', err))
                met_fun = dc3.nest_metric(current_sim, err)
                bdy_fun = dc3.nest_bdy_tpl(current_sim, err)

            if sim_type == 'dep':
                current_sim.error_model = em.depolarize(
                    err, [[current_sim.layout.map[_]]
                          for _ in current_sim.layout.datas])
                # dist_func = fancy_dist(dist, 0.66666667 * err)

            current_sim.run(n_trials, progress=False, bp=bp)
            # current_sim.run(n_trials, progress=False, bp=bp, bp_rounds=0)
            # current_sim.run(n_trials, progress=False,
            # metric=met_fun, bdy_info=bdy_fun)
            # current_sim.run(n_trials, progress=False, dist_func=dist_func)
            # hb.bravyi_run(current_sim, n_trials)
            failures.append(current_sim.errors)
        output_dict.update({'failures ' + str(dist): failures})

    with open(flnm, 'wb') as phil:
        pkl.dump(output_dict, phil)

    pass