def test_rotated_planar_rmps_decoder_cosets_probability_pair_optimisation(
        mode):
    code = RotatedPlanarCode(5, 5)
    decoder = RotatedPlanarRMPSDecoder(mode=mode)
    # probabilities
    prob_dist = BiasedDepolarizingErrorModel(bias=10).probability_distribution(
        probability=0.1)
    # coset probabilities for null Pauli
    coset_i_ps, _ = decoder._coset_probabilities(prob_dist, code.new_pauli())
    coset_x_ps, _ = decoder._coset_probabilities(prob_dist,
                                                 code.new_pauli().logical_x())
    # expect Pr(iIG) ~= Pr(xXG)
    assert _is_close(
        coset_i_ps[0], coset_x_ps[1], rtol=0,
        atol=0), ('Coset probabilites do not satisfy Pr(iIG) ~= Pr(xXG)')
    # expect Pr(iXG) ~= Pr(xIG)
    assert _is_close(
        coset_i_ps[1], coset_x_ps[0], rtol=0,
        atol=0), ('Coset probabilites do not satisfy Pr(iXG) ~= Pr(xIG)')
    # expect Pr(iZG) ~= Pr(xYG)
    assert _is_close(
        coset_i_ps[3], coset_x_ps[2], rtol=0,
        atol=0), ('Coset probabilites do not satisfy Pr(iZG) ~= Pr(xYG)')
    # expect Pr(iYG) ~= Pr(xZG)
    assert _is_close(
        coset_i_ps[2], coset_x_ps[3], rtol=0,
        atol=0), ('Coset probabilites do not satisfy Pr(iYG) ~= Pr(xZG)')
def test_rotated_planar_mps_decoder_small_codes_exact_approx():
    code = RotatedPlanarCode(5, 5)
    exact_decoder = RotatedPlanarMPSDecoder()
    approx_decoder = RotatedPlanarMPSDecoder(chi=8)
    identity = code.new_pauli()
    # probabilities
    prob_dist = BiasedDepolarizingErrorModel(bias=10).probability_distribution(
        probability=0.1)
    # coset probabilities
    exact_coset_ps, _ = exact_decoder._coset_probabilities(prob_dist, identity)
    approx_coset_ps, _ = approx_decoder._coset_probabilities(
        prob_dist, identity)
    print('#exact Pr(G)=', exact_coset_ps)
    print('#approx Pr(G)=', approx_coset_ps)
    assert all(_is_close(
        exact_coset_ps, approx_coset_ps, rtol=1e-11, atol=0)), (
            'Coset probabilites do not satisfy exact Pr(G) ~= approx Pr(G)')
def test_rotated_planar_mps_decoder_cosets_probability_inequality(mode, rtol):
    code = RotatedPlanarCode(25, 25)
    decoder = RotatedPlanarMPSDecoder(chi=5, mode=mode)
    # probabilities
    prob_dist = DepolarizingErrorModel().probability_distribution(0.1)
    # coset probabilities for null Pauli
    coset_ps, _ = decoder._coset_probabilities(prob_dist, code.new_pauli())
    coset_i_p, coset_x_p, coset_y_p, coset_z_p = coset_ps
    # expect Pr(IG) > Pr(XG) ~= Pr(ZG) > Pr(YG)
    print('{} > {} ~= {} > {}. rtol={}'.format(
        coset_i_p, coset_x_p, coset_z_p, coset_y_p,
        abs(coset_x_p - coset_z_p) / abs(coset_z_p)))
    print('types: Pr(IG):{}, Pr(XG):{}, Pr(ZG):{}, Pr(YG):{}'.format(
        type(coset_i_p), type(coset_x_p), type(coset_z_p), type(coset_y_p)))
    assert coset_i_p > coset_x_p, 'Coset probabilites do not satisfy Pr(IG) > Pr(XG)'
    assert coset_i_p > coset_z_p, 'Coset probabilites do not satisfy Pr(IG) > Pr(ZG)'
    assert _is_close(
        coset_x_p, coset_z_p, rtol=rtol,
        atol=0), 'Coset probabilites do not satisfy Pr(XG) ~= Pr(ZG)'
    assert coset_x_p > coset_y_p, 'Coset probabilites do not satisfy Pr(XG) > Pr(YG)'
    assert coset_z_p > coset_y_p, 'Coset probabilites do not satisfy Pr(ZG) > Pr(YG)'
Example #4
0
def test_rotated_planar_pauli_properties(size):
    code = RotatedPlanarCode(*size)
    pauli = code.new_pauli()
    assert pauli.code == code
    assert isinstance(repr(pauli), str)
    assert isinstance(str(pauli), str)