def test_planar_mps_decoder_correlated_errors(): # check MPS decoder successfully decodes for error # I--+--I--+--I # I I # Y--+--I--+--Y # I I # I--+--I--+--I # and MWPM decoder fails as expected code = PlanarCode(3, 3) error = code.new_pauli().site('Y', (2, 0), (2, 4)).to_bsf() syndrome = pt.bsp(error, code.stabilizers.T) # MPS decoder decoder = PlanarMPSDecoder() recovery = decoder.decode(code, syndrome) # check recovery ^ error commutes with stabilizers (by construction) assert np.all(pt.bsp(recovery ^ error, code.stabilizers.T) == 0), ( 'recovery ^ error ({} ^ {}) does not commute with stabilizers for MPS decoder.' .format(recovery, error)) # check recovery ^ error commutes with logicals (we expect this to succeed for MPS) assert np.all(pt.bsp(recovery ^ error, code.logicals.T) == 0), ( 'recovery ^ error ({} ^ {}) does not commute with logicals for MPS decoder.' .format(recovery, error)) # MWPM decoder decoder = PlanarMWPMDecoder() recovery = decoder.decode(code, syndrome) # check recovery ^ error commutes with stabilizers (by construction) assert np.all(pt.bsp(recovery ^ error, code.stabilizers.T) == 0), ( 'recovery ^ error ({} ^ {}) does not commute with stabilizers for MWPM decoder.' .format(recovery, error)) # check recovery ^ error commutes with logicals (we expect this to fail for MWPM) assert not np.all(pt.bsp(recovery ^ error, code.logicals.T) == 0), ( 'recovery ^ error ({} ^ {}) does commute with logicals for MWPM decoder.' .format(recovery, error))
def test_planar_mps_decoder_zero_norm_in_left_canonical_form(): # parameters random_seed = 13 code = PlanarCode(7, 7) error_model = BitFlipErrorModel() decoder = PlanarMPSDecoder(chi=6, mode='c') error_probability = 0.1 # single run error = error_model.generate(code, error_probability, np.random.default_rng(random_seed)) syndrome = pt.bsp(error, code.stabilizers.T) decoder.decode(code, syndrome, error_model=error_model, error_probability=error_probability)
def test_planar_mps_decoder_decode_logging_nonpositivefinite_max_coset_probability( caplog): # taken from corner case mode='a' of test_planar_mps_decoder_positive_max_coset_probability code = PlanarCode(9, 9) decoder = PlanarMPSDecoder(chi=48, mode='a') error_model = BiasedDepolarizingErrorModel(bias=100) error_probability = 0.41 error = pt.unpack([ "c96aa012210dc2254031f15d9ce80c871fb864b510c91086e112a018f8aece7406638fdc00", 290 ]) syndrome = pt.unpack(["8f59cd273bd1c027b3b925085af85f2aaf22", 144]) assert np.array_equal(syndrome, pt.bsp(error, code.stabilizers.T)) decoder.decode(code, syndrome, error_model=error_model, error_probability=error_probability) assert 'NON-POSITIVE-FINITE MAX COSET PROBABILITY' in caplog.text, ( 'Non-positive-finite max coset probability not logged')
def test_planar_mps_decoder_svd_does_not_converge(): code = PlanarCode(21, 21) decoder = PlanarMPSDecoder(chi=4) error = pt.unpack(( '001281500200080080000000000080001000000c0000002012000000801040004000000100000000004000002100000800800000000000' '02000100028022001000002044841000080080008110020000400801200000801040112008010004400000000000000002000000402201' '10040000000000000481000200000601000080080000000820200020000000008820000100000010045000004000010000000000000000' '40010000840010200008000400024000880000000004000000004000200890040001082000000000000002000000', 1682)) syndrome = pt.bsp(error, code.stabilizers.T) recovery = decoder.decode(code, syndrome) # no error raised assert np.all(pt.bsp(recovery ^ error, code.stabilizers.T) == 0), ( 'recovery ^ error ({} ^ {}) does not commute with stabilizers.'.format( recovery, error))
def test_planar_mps_decoder_decode(error_pauli, chi, caplog): with caplog.at_level(logging.WARN): error = error_pauli.to_bsf() code = error_pauli.code syndrome = pt.bsp(error, code.stabilizers.T) decoder = PlanarMPSDecoder(chi=chi) recovery = decoder.decode(code, syndrome) assert np.array_equal(pt.bsp( recovery, code.stabilizers.T), syndrome), ( 'recovery {} does not give the same syndrome as the error {}'. format(recovery, error)) assert np.all(pt.bsp(recovery ^ error, code.stabilizers.T) == 0), ( 'recovery ^ error ({} ^ {}) does not commute with stabilizers.'. format(recovery, error)) assert len(caplog.records) == 0, 'Unexpected log messages: {}'.format( caplog.text)