def test_imperfect_code(): # Also known as the bit-flip code. bit_flip_code = sc.StabilizerCode(group_generators=['ZZI', 'ZIZ'], correctable_errors=['X']) for input_val in [0, 1]: _, traced_out_state_no_error = encode_corrupt_correct(bit_flip_code, input_val, error_gate=None, error_loc=None) for error_gate in [cirq.X]: for error_loc in range(bit_flip_code.n): decoded, traced_out_state = encode_corrupt_correct( bit_flip_code, input_val, error_gate, error_loc) assert decoded == input_val np.testing.assert_allclose(traced_out_state_no_error, traced_out_state, atol=1e-6) # Test that we cannot correct a Z error. In this case, they manifest as a phase error, so we # test the state vectors. _, traced_out_state_no_error = encode_corrupt_correct(bit_flip_code, input_val=1, error_gate=None, error_loc=None) _, traced_out_state_z1_error = encode_corrupt_correct(bit_flip_code, input_val=1, error_gate=cirq.Z, error_loc=1) with np.testing.assert_raises(AssertionError): np.testing.assert_allclose(traced_out_state_no_error, traced_out_state_z1_error, atol=1e-6)
def test_no_error(): # Table 3.2. five_qubit_code = sc.StabilizerCode( group_generators=['XZZXI', 'IXZZX', 'XIXZZ', 'ZXIXZ'], correctable_errors=['X', 'Z'] ) for input_val in [0, 1]: decoded, _ = encode_corrupt_correct( five_qubit_code, input_val, error_gate=None, error_loc=None ) assert decoded == input_val
def test_errors(group_generators): code = sc.StabilizerCode(group_generators=group_generators, correctable_errors=['X', 'Z']) for input_val in [0, 1]: _, traced_out_state_no_error = encode_corrupt_correct( code, input_val, error_gate=None, error_loc=None ) for error_gate in [cirq.X, cirq.Z]: for error_loc in range(code.n): decoded, traced_out_state = encode_corrupt_correct( code, input_val, error_gate, error_loc ) assert decoded == input_val np.testing.assert_allclose(traced_out_state_no_error, traced_out_state, atol=1e-6)