def test_toric_code_stabilizers(size, expected): assert len(ToricCode(*size).stabilizers) == expected
def test_toric_code_new_invalid_parameters(rows, columns): with pytest.raises((ValueError, TypeError), match=r"^ToricCode") as exc_info: ToricCode(rows, columns) print(exc_info)
def test_toric_code_n_k_d(size, expected): code = ToricCode(*size) assert code.n_k_d == expected
def test_toric_lattice_translation(size, a_index, b_index, expected): assert ToricCode(*size).translation(a_index, b_index) == expected
def test_toric_lattice_invalid_translation(size, a_index, b_index): code = ToricCode(*size) with pytest.raises(IndexError): code.translation(a_index, b_index)
@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, 'custom_values': np.ndarray} assert data.keys() == expected_key_cls.keys(), 'data={} has missing/extra keys'
def test_toric_pauli_properties(size): lattice = ToricCode(*size) pauli = lattice.new_pauli() assert pauli.code == lattice assert isinstance(repr(pauli), str) assert isinstance(str(pauli), str)
@pytest.mark.parametrize( 'size, a_index, b_index', [ ((5, 5), (0, 1, 1), (1, 2, 2)), # different lattices ]) def test_toric_lattice_invalid_translation(size, a_index, b_index): code = ToricCode(*size) with pytest.raises(IndexError): code.translation(a_index, b_index) @pytest.mark.parametrize('error, expected', [ (ToricCode(3, 3).new_pauli().site('X', (1, 0, 0), (0, 1, 2)).site('Z', (0, 2, 2), (1, 1, 2), (1, 0, 2)), [(0, 0, 0), (0, 1, 2), (1, 1, 0), (1, 2, 2)]), ]) def test_toric_lattice_syndrome_to_plaquette_indices(error, expected): code = error.code syndrome = pt.bsp(error.to_bsf(), code.stabilizers.T) assert set(code.syndrome_to_plaquette_indices(syndrome)) == set(expected) @pytest.mark.parametrize('pauli', [ ToricCode(3, 3).new_pauli().site('Y', (0, 0, 0), (1, 2, 2)), ToricCode(3, 5).new_pauli().logical_x1(), ToricCode(5, 3).new_pauli().logical_z1(),
def test_toric_code_new(rows, columns): code = ToricCode(rows, columns) code.validate() # no error raised
def test_toric_mwpm_decoder_distance(size, a_index, b_index, expected): assert ToricMWPMDecoder.distance(ToricCode(*size), a_index, b_index) == expected
def test_toric_mwpm_decoder_invalid_distance(size, a_index, b_index): with pytest.raises(IndexError): ToricMWPMDecoder.distance(ToricCode(*size), a_index, b_index)
assert ToricMWPMDecoder.distance(ToricCode(*size), a_index, b_index) == expected @pytest.mark.parametrize( 'size, a_index, b_index', [ ((5, 5), (0, 1, 1), (1, 2, 2)), # different lattices ]) def test_toric_mwpm_decoder_invalid_distance(size, a_index, b_index): with pytest.raises(IndexError): ToricMWPMDecoder.distance(ToricCode(*size), a_index, b_index) @pytest.mark.parametrize('error_pauli', [ (ToricCode(5, 5).new_pauli().site('X', (0, 1, 1), (0, 2, 1))), (ToricCode(5, 5).new_pauli().site('X', (0, 1, 1), (0, 2, 1)).site('Z', (0, 3, 2), (0, 1, 0))), (ToricCode(5, 5).new_pauli().site('X', (1, 1, 1), (0, 2, 1)).site('Z', (0, 3, 2), (1, 1, 0))), (ToricCode(3, 5).new_pauli().site('X', (1, 1, 1), (0, 2, 1)).site('Z', (0, 1, 2), (1, 1, 4))), (ToricCode(5, 3).new_pauli().site('X', (1, 1, 1), (0, 2, 1)).site('Z', (0, 4, 2), (1, 2, 0))), (ToricCode(5, 3).new_pauli().site('Y', (1, 1, 1), (0, 2, 1)).site('Z', (0, 4, 2), (0, 3, 2), (0, 2, 2))),
def test_toric_pauli_invalid_path(size, a_index, b_index): pauli = ToricCode(*size).new_pauli() with pytest.raises(IndexError): pauli.path(a_index, b_index)
def test_toric_pauli_plaquette_index_modulo(size, a_index, b_index): toric_pauli_1 = ToricCode(*size).new_pauli().plaquette(a_index) toric_pauli_2 = ToricCode(*size).new_pauli().plaquette(b_index) assert toric_pauli_1 == toric_pauli_2, ( 'Plaquette indices {} and {} are not equivalent on size {}'.format( a_index, b_index, size))
def test_toric_code_logicals(): assert len(ToricCode(5, 5).logicals) == 4
def test_toric_lattice_properties(size): lattice = ToricCode(*size) assert lattice.size == size assert lattice.shape == (2, *size) assert isinstance(repr(lattice), str) assert isinstance(str(lattice), str)
def test_toric_code_validate(size): code = ToricCode(*size) code.validate() # no error raised
def test_toric_code_properties(size): code = ToricCode(*size) assert isinstance(code.label, str) assert isinstance(repr(code), str)
| | | --|----(0,1,0)----|----(0,1,1)----|----(0,1,2)-- | | | (1,1,0) (1,1,1) (1,1,2) | | | --|----(0,2,0)----|----(0,2,1)----|----(0,2,2)-- | | | (1,2,0) (1,2,1) (1,2,2) | | | """ # set models sizes = range( 11, 16, 2) #choose odd sizes since we have defined hadamard_mat for odd sizes codes_and_size = [ToricCode(*(size, size)) for size in sizes] bias_list = [10000] layout_name = "rot" code_name = "CSS" code_name = "random" code_name = "optimal" code_name = "XZZX" if (code_name == "random"): realizations = 30 else: realizations = 1 # set physical error probabilities error_probability_min, error_probability_max = 0.05, 0.5
(5, 5), (3, 5), (2, 4), (7, 4), (2, 2), ]) def test_toric_pauli_properties(size): lattice = ToricCode(*size) pauli = lattice.new_pauli() assert pauli.code == lattice assert isinstance(repr(pauli), str) assert isinstance(str(pauli), str) @pytest.mark.parametrize('toric_pauli', [ ToricCode(5, 5).new_pauli(), ToricCode(5, 5).new_pauli().plaquette((0, 1, 1)).plaquette((1, 3, 3)), ToricCode(5, 5).new_pauli().logical_x1().plaquette((1, 3, 3)).plaquette( (1, 2, 2)), ToricCode(5, 5).new_pauli().logical_z1().plaquette((0, 4, 4)).plaquette( (1, 2, 3)), ToricCode(5, 5).new_pauli().logical_x2().plaquette((1, 3, 1)).plaquette( (0, 4, 4)), ToricCode(5, 5).new_pauli().logical_z2().plaquette((0, 2, 1)).plaquette( (1, 3, 2)), ]) def test_toric_pauli_new_to_bsf(toric_pauli): assert toric_pauli.code.new_pauli(toric_pauli.to_bsf()) == toric_pauli, ( 'Conversion to_bsf+from_bsf does not result in equality.')