Ejemplo n.º 1
0
def test_rotated_toric_pauli_path(size, a_index, b_index):
    code = RotatedToricCode(*size)
    pauli = code.new_pauli().path(a_index, b_index)
    syndrome = pt.bsp(pauli.to_bsf(), code.stabilizers.T)
    syndrome_indices = code.syndrome_to_plaquette_indices(syndrome)
    if a_index == b_index:
        assert len(syndrome_indices) == 0, 'Unexpected syndrome for null path'
    else:
        dim_y, dim_x = code.size
        a_index = tuple(np.mod(a_index, (dim_x, dim_y)))
        b_index = tuple(np.mod(b_index, (dim_x, dim_y)))
        assert syndrome_indices == {a_index, b_index
                                    }, 'Path does not give expected syndrome'
Ejemplo n.º 2
0
def test_run_ftp_measurement_error_probability_defaults(time_steps, error_probability, measurement_error_probability,
                                                        expected):
    code = RotatedToricCode(4, 4)
    error_model = BitPhaseFlipErrorModel()
    decoder = RotatedToricSMWPMDecoder()
    max_runs = 2
    data = app.run_ftp(code, time_steps, error_model, decoder, error_probability, measurement_error_probability,
                       max_runs=max_runs)
    assert data['measurement_error_probability'] == expected
Ejemplo n.º 3
0
def test_run_once_ftp_seeded():
    code = RotatedToricCode(4, 4)
    time_steps = 4
    error_model = BitPhaseFlipErrorModel()
    decoder = RotatedToricSMWPMDecoder()
    error_probability = 0.15
    data1 = app.run_once_ftp(code, time_steps, error_model, decoder, error_probability, rng=np.random.default_rng(5))
    data2 = app.run_once_ftp(code, time_steps, error_model, decoder, error_probability, rng=np.random.default_rng(5))
    assert data1['error_weight'] == data2['error_weight']
    assert data1['success'] == data2['success']
    assert np.array_equal(data1['logical_commutations'], data2['logical_commutations'])
    assert np.array_equal(data1['custom_values'], data2['custom_values'])
Ejemplo n.º 4
0
def test_run_ftp_count(max_runs, max_failures):
    code = RotatedToricCode(6, 6)
    time_steps = 6
    error_model = BitPhaseFlipErrorModel()
    decoder = RotatedToricSMWPMDecoder()
    error_probability = 0.05
    data = app.run_ftp(code, time_steps, error_model, decoder, error_probability,
                       max_runs=max_runs, max_failures=max_failures)  # no error raised
    assert {'n_run', 'n_fail'} <= data.keys(), 'data={} missing count keys'
    if max_runs is None and max_failures is None:
        assert data['n_run'] == 1, 'n_run does not equal 1 when max_runs and max_failures unspecified'
    if max_runs is not None:
        assert data['n_run'] <= max_runs, ('n_run is not <= requested max_runs (data={}).'.format(data))
    if max_failures is not None:
        assert data['n_fail'] <= max_failures, ('n_fail is not <= requested max_failures (data={}).'.format(data))
Ejemplo n.º 5
0
def test_run_ftp_seeded():
    code = RotatedToricCode(4, 4)
    time_steps = 4
    error_model = BitPhaseFlipErrorModel()
    decoder = RotatedToricSMWPMDecoder()
    error_probability = 0.15
    max_runs = 5
    random_seed = 5
    data1 = app.run_ftp(code, time_steps, error_model, decoder, error_probability, max_runs=max_runs,
                        random_seed=random_seed)
    data2 = app.run_ftp(code, time_steps, error_model, decoder, error_probability, max_runs=max_runs,
                        random_seed=random_seed)
    # remove wall_time from data
    for data in (data1, data2):
        del data['wall_time']
    assert data1 == data2, 'Identically seeded runs are not the same. '
Ejemplo n.º 6
0
def test_rotated_toric_code_new_invalid_parameters(rows, columns):
    with pytest.raises((ValueError, TypeError),
                       match=r"^RotatedToricCode") as exc_info:
        RotatedToricCode(rows, columns)
    print(exc_info)
Ejemplo n.º 7
0
def test_rotated_toric_lattice_translation(size, a_index, b_index, expected):
    assert RotatedToricCode(*size).translation(a_index, b_index) == expected
Ejemplo n.º 8
0
def test_rotated_toric_lattice_is_in_bounds(index, expected):
    lattice = RotatedToricCode(4, 6)
    assert lattice.is_in_bounds(index) == expected
Ejemplo n.º 9
0
def test_rotated_toric_code_properties(size):
    code = RotatedToricCode(*size)
    assert isinstance(code.label, str)
    assert isinstance(repr(code), str)
Ejemplo n.º 10
0
def test_rotated_toric_lattice_is_x_plaquette(index, expected):
    lattice = RotatedToricCode(2, 4)
    assert lattice.is_x_plaquette(index) == expected
Ejemplo n.º 11
0
def test_rotated_toric_pauli_properties(size):
    code = RotatedToricCode(*size)
    pauli = code.new_pauli()
    assert pauli.code == code
    assert isinstance(repr(pauli), str)
    assert isinstance(str(pauli), str)
Ejemplo n.º 12
0
def test_rotated_toric_code_logicals():
    assert len(RotatedToricCode(4, 4).logicals) == 4
Ejemplo n.º 13
0
def test_run_ftp_invalid_parameters(time_steps, error_probability, measurement_error_probability):
    with pytest.raises(ValueError) as exc_info:
        app.run_ftp(RotatedToricCode(6, 6), time_steps, BitPhaseFlipErrorModel(), RotatedToricSMWPMDecoder(),
                    error_probability, measurement_error_probability, max_runs=2)
    print(exc_info)
Ejemplo n.º 14
0
        return 'fixed'


@pytest.mark.parametrize('code, error_model, decoder', [
    # each code with each valid decoder
    (Color666Code(5), DepolarizingErrorModel(), Color666MPSDecoder(chi=8)),
    (FiveQubitCode(), DepolarizingErrorModel(), NaiveDecoder()),
    (PlanarCode(5, 5), DepolarizingErrorModel(), PlanarCMWPMDecoder()),
    (PlanarCode(5, 5), DepolarizingErrorModel(), PlanarMPSDecoder(chi=6)),
    (PlanarCode(5, 5), DepolarizingErrorModel(), PlanarMWPMDecoder()),
    (PlanarCode(5, 5), DepolarizingErrorModel(), PlanarRMPSDecoder(chi=6)),
    (PlanarCode(4, 5), BitPhaseFlipErrorModel(), PlanarYDecoder()),
    (RotatedPlanarCode(7, 7), DepolarizingErrorModel(), RotatedPlanarMPSDecoder(chi=8)),
    (RotatedPlanarCode(7, 7), DepolarizingErrorModel(), RotatedPlanarRMPSDecoder(chi=8)),
    (RotatedPlanarCode(7, 7), BiasedDepolarizingErrorModel(100), RotatedPlanarSMWPMDecoder()),
    (RotatedToricCode(6, 6), BiasedDepolarizingErrorModel(100), RotatedToricSMWPMDecoder()),
    (SteaneCode(), DepolarizingErrorModel(), NaiveDecoder()),
    (ToricCode(5, 5), DepolarizingErrorModel(), ToricMWPMDecoder()),
    # each generic noise model
    (PlanarCode(5, 5), BiasedDepolarizingErrorModel(10), PlanarMPSDecoder(chi=6)),
    (PlanarCode(5, 5), BiasedYXErrorModel(10), PlanarMPSDecoder(chi=6)),
    (PlanarCode(5, 5), BitFlipErrorModel(), PlanarMPSDecoder(chi=6)),
    (PlanarCode(5, 5), BitPhaseFlipErrorModel(), PlanarMPSDecoder(chi=6)),
    (PlanarCode(5, 5), CenterSliceErrorModel((0.2, 0.8, 0), 0.5), PlanarMPSDecoder(chi=6)),
    (PlanarCode(5, 5), DepolarizingErrorModel(), PlanarMPSDecoder(chi=6)),
    (PlanarCode(5, 5), PhaseFlipErrorModel(), PlanarMPSDecoder(chi=6)),
])
def test_run_once(code, error_model, decoder):
    error_probability = 0.15
    data = app.run_once(code, error_model, decoder, error_probability)  # no error raised
    expected_key_cls = {'error_weight': int, 'success': bool, 'logical_commutations': np.ndarray,
Ejemplo n.º 15
0
def test_rotated_toric_code_n_k_d(size, expected):
    code = RotatedToricCode(*size)
    assert code.n_k_d == expected
Ejemplo n.º 16
0
        ((3, 0), True),  # boundary x plaquette
        ((3, 2), True),  # out-bounds x plaquette
        ((0, 0), False),  # in-bounds z plaquette
        ((1, 1), False),  # boundary z plaquette
        ((3, 1), False),  # out-bounds z plaquette
    ])
def test_rotated_toric_lattice_is_x_plaquette(index, expected):
    lattice = RotatedToricCode(2, 4)
    assert lattice.is_x_plaquette(index) == expected


@pytest.mark.parametrize(
    'lattice, expected',
    [
        # RotatedToricCode(row, cols), (max_site_x, max_site_y)
        (RotatedToricCode(2, 2), (1, 1)),
        (RotatedToricCode(4, 4), (3, 3)),
        (RotatedToricCode(2, 4), (3, 1)),
        (RotatedToricCode(4, 2), (1, 3)),
        (RotatedToricCode(6, 6), (5, 5)),
        (RotatedToricCode(4, 6), (5, 3)),
        (RotatedToricCode(6, 4), (3, 5)),
    ])
def test_rotated_toric_lattice_bounds(lattice, expected):
    assert lattice.bounds == expected


@pytest.mark.parametrize(
    'index, expected',
    [
        ((0, 1), True),  # in-bounds left
Ejemplo n.º 17
0
def test_rotated_toric_code_stabilizers(size, expected):
    assert len(RotatedToricCode(*size).stabilizers) == expected
Ejemplo n.º 18
0
def test_rotated_toric_lattice_size(size):
    lattice = RotatedToricCode(*size)
    assert lattice.size == size
Ejemplo n.º 19
0
def test_rotated_toric_code_validate(size):
    code = RotatedToricCode(*size)
    code.validate()  # no error raised
Ejemplo n.º 20
0
    (2, 4),
    (4, 2),
    (6, 6),
    (4, 6),
    (6, 4),
])
def test_rotated_toric_pauli_properties(size):
    code = RotatedToricCode(*size)
    pauli = code.new_pauli()
    assert pauli.code == code
    assert isinstance(repr(pauli), str)
    assert isinstance(str(pauli), str)


@pytest.mark.parametrize('pauli', [
    RotatedToricCode(4, 4).new_pauli(),
    RotatedToricCode(4, 6).new_pauli().plaquette((1, 1)).plaquette((3, 2)),
    RotatedToricCode(6, 6).new_pauli().logical_x1().plaquette(
        (-1, 0)).plaquette((4, 1)),
    RotatedToricCode(6, 4).new_pauli().logical_z1().plaquette(
        (1, 5)).plaquette((3, -1)),
    RotatedToricCode(8, 6).new_pauli().logical_x2().plaquette(
        (0, 2)).plaquette((1, 1)),
    RotatedToricCode(6, 8).new_pauli().logical_z2().plaquette(
        (1, -1)).plaquette((2, 4)),
])
def test_rotated_toric_pauli_new_to_bsf(pauli):
    assert pauli.code.new_pauli(pauli.to_bsf()) == pauli, (
        'Conversion to_bsf+from_bsf does not result in equality.')