예제 #1
0
def test_bad_probs():
    with pytest.raises(ValueError,
                       match=re.escape('p(X) was greater than 1.')):
        cirq.asymmetric_depolarize(error_probabilities={'X': 1.1, 'Y': -0.1})
    with pytest.raises(ValueError,
                       match=re.escape('Probabilities do not add up to 1')):
        cirq.asymmetric_depolarize(error_probabilities={'X': 0.7, 'Y': 0.6})
예제 #2
0
def test_asymmetric_depolarizing_channel_eq():
    et = cirq.testing.EqualsTester()
    c = cirq.asymmetric_depolarize(0.0, 0.0, 0.0)
    et.make_equality_group(lambda: c)
    et.add_equality_group(cirq.asymmetric_depolarize(0.0, 0.0, 0.1))
    et.add_equality_group(cirq.asymmetric_depolarize(0.0, 0.1, 0.0))
    et.add_equality_group(cirq.asymmetric_depolarize(0.1, 0.0, 0.0))
    et.add_equality_group(cirq.asymmetric_depolarize(0.1, 0.2, 0.3))
    et.add_equality_group(cirq.asymmetric_depolarize(0.3, 0.4, 0.3))
    et.add_equality_group(cirq.asymmetric_depolarize(1.0, 0.0, 0.0))
    et.add_equality_group(cirq.asymmetric_depolarize(0.0, 1.0, 0.0))
    et.add_equality_group(cirq.asymmetric_depolarize(0.0, 0.0, 1.0))
예제 #3
0
def test_asymmetric_depolarizing_channel():
    d = cirq.asymmetric_depolarize(0.1, 0.2, 0.3)
    np.testing.assert_almost_equal(
        cirq.kraus(d),
        (np.sqrt(0.4) * np.eye(2), np.sqrt(0.1) * X, np.sqrt(0.2) * Y, np.sqrt(0.3) * Z),
    )
    assert cirq.has_kraus(d)
예제 #4
0
def test_multi_asymmetric_depolarizing_channel_str():
    assert str(
        cirq.asymmetric_depolarize(error_probabilities={
            'II': 0.8,
            'XX': 0.2
        })
    ) == ("asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})")
예제 #5
0
def test_default_asymmetric_depolarizing_channel():
    d = cirq.asymmetric_depolarize()
    assert d.p_i == 1.0
    assert d.p_x == 0.0
    assert d.p_y == 0.0
    assert d.p_z == 0.0
    assert d.num_qubits() == 1
def test_asymmetric_depolarizing_channel_text_diagram():
    a = cirq.asymmetric_depolarize(1 / 9, 2 / 9, 3 / 9)
    assert (cirq.circuit_diagram_info(
        a, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
            wire_symbols=('A(0.111111,0.222222,0.333333)', )))
    assert (cirq.circuit_diagram_info(
        a, args=round_to_2_prec) == cirq.CircuitDiagramInfo(
            wire_symbols=('A(0.11,0.22,0.33)', )))
def test_asymmetric_depolarizing_mixture():
    d = cirq.asymmetric_depolarize(0.1, 0.2, 0.3)
    assert_mixtures_equal(cirq.mixture(d),
                          ((0.4, np.eye(2)),
                           (0.1, X),
                           (0.2, Y),
                           (0.3, Z)))
    assert cirq.has_mixture_channel(d)
예제 #8
0
def test_multi_asymmetric_depolarizing_channel_text_diagram():
    a = cirq.asymmetric_depolarize(error_probabilities={'II': 2 / 3, 'XX': 1 / 3})
    assert cirq.circuit_diagram_info(a, args=no_precision) == cirq.CircuitDiagramInfo(
        wire_symbols=('A(II:0.6666666666666666, XX:0.3333333333333333)',)
    )
    assert cirq.circuit_diagram_info(a, args=round_to_6_prec) == cirq.CircuitDiagramInfo(
        wire_symbols=('A(II:0.666667, XX:0.333333)',)
    )
    assert cirq.circuit_diagram_info(a, args=round_to_2_prec) == cirq.CircuitDiagramInfo(
        wire_symbols=('A(II:0.67, XX:0.33)',)
    )
예제 #9
0
def test_asymmetric_depolarizing_channel():
    d = cirq.asymmetric_depolarize(0.1, 0.2, 0.3)
    np.testing.assert_almost_equal(
        cirq.kraus(d),
        (np.sqrt(0.4) * np.eye(2), np.sqrt(0.1) * X, np.sqrt(0.2) * Y,
         np.sqrt(0.3) * Z),
    )
    assert cirq.has_kraus(d)

    assert cirq.AsymmetricDepolarizingChannel(p_x=0, p_y=0.1,
                                              p_z=0).num_qubits() == 1
예제 #10
0
def test_multi_asymmetric_depolarizing_channel():
    d = cirq.asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})
    np.testing.assert_almost_equal(
        cirq.channel(d),
        (np.sqrt(0.8) * np.eye(4), np.sqrt(0.2) * np.kron(X, X)))
    assert cirq.has_channel(d)
    np.testing.assert_equal(d._num_qubits_(), 2)
    with pytest.raises(ValueError, match="num_qubits should be 1"):
        assert d.p_x == 0.0
    with pytest.raises(ValueError, match="num_qubits should be 1"):
        assert d.p_y == 0.0
    with pytest.raises(ValueError, match="num_qubits should be 1"):
        assert d.p_z == 0.0
예제 #11
0
def _get_noise_proto_pairs():
    q0 = cirq.GridQubit(0, 0)

    pairs = [
        # Depolarization.
        (cirq.Circuit(cirq.depolarize(p=0.3)(q0)),
         _build_op_proto("DP", ['p'], [0.3], ['0_0'])),

        # Asymmetric depolarization.
        (cirq.Circuit(
            cirq.asymmetric_depolarize(p_x=0.1, p_y=0.2, p_z=0.3)(q0)),
         _build_op_proto("ADP", ['p_x', 'p_y', 'p_z'], [0.1, 0.2, 0.3],
                         ['0_0']))
    ]
    return pairs
예제 #12
0
def _get_noise_proto_pairs():
    q0 = cirq.GridQubit(0, 0)

    pairs = [
        # Depolarization.
        (cirq.Circuit(cirq.depolarize(p=0.3)(q0)),
         _build_op_proto("DP", ['p'], [0.3], ['0_0'])),

        # Asymmetric depolarization.
        (cirq.Circuit(
            cirq.asymmetric_depolarize(p_x=0.1, p_y=0.2, p_z=0.3)(q0)),
         _build_op_proto("ADP", ['p_x', 'p_y', 'p_z'], [0.1, 0.2, 0.3],
                         ['0_0'])),

        # Generalized Amplitude damp.
        (cirq.Circuit(cirq.generalized_amplitude_damp(p=0.1, gamma=0.2)(q0)),
         _build_op_proto("GAD", ['p', 'gamma'], [0.1, 0.2], ['0_0'])),

        # Amplitude damp.
        (cirq.Circuit(cirq.amplitude_damp(gamma=0.1)(q0)),
         _build_op_proto("AD", ['gamma'], [0.1], ['0_0'])),

        # Reset.
        (cirq.Circuit(cirq.reset(q0)), _build_op_proto("RST", [], [],
                                                       ['0_0'])),

        # Phase damp.
        (cirq.Circuit(cirq.phase_damp(gamma=0.1)(q0)),
         _build_op_proto("PD", ['gamma'], [0.1], ['0_0'])),

        # Phase flip.
        (cirq.Circuit(cirq.phase_flip(p=0.1)(q0)),
         _build_op_proto("PF", ['p'], [0.1], ['0_0'])),

        # Bit flip.
        (cirq.Circuit(cirq.bit_flip(p=0.1)(q0)),
         _build_op_proto("BF", ['p'], [0.1], ['0_0']))
    ]
    return pairs
예제 #13
0
def _get_noise_proto_pairs():
    q0 = cirq.GridQubit(0, 0)

    pairs = [
        # Depolarization.
        (cirq.Circuit(cirq.depolarize(p=0.3)(q0)),
         _build_op_proto("DP", ['p'], [0.3], ['0_0'])),

        # Asymmetric depolarization.
        (cirq.Circuit(
            cirq.asymmetric_depolarize(p_x=0.1, p_y=0.2, p_z=0.3)(q0)),
         _build_op_proto("ADP", ['p_x', 'p_y', 'p_z'], [0.1, 0.2, 0.3],
                         ['0_0'])),

        # Amplitude damp.
        (cirq.Circuit(cirq.amplitude_damp(gamma=0.1)(q0)),
         _build_op_proto("AD", ['gamma'], [0.1], ['0_0'])),

        # Reset.
        (cirq.Circuit(cirq.reset(q0)), _build_op_proto("RST", [], [], ['0_0']))
    ]
    return pairs
예제 #14
0
def test_asymmetric_depolarizing_channel_str():
    assert (str(
        cirq.asymmetric_depolarize(0.1, 0.2, 0.3)
    ) == "asymmetric_depolarize(error_probabilities={'I': 0.3999999999999999, "
            + "'X': 0.1, 'Y': 0.2, 'Z': 0.3})")
예제 #15
0
def test_multi_asymmetric_depolarizing_mixture():
    d = cirq.asymmetric_depolarize(error_probabilities={'II': 0.8, 'XX': 0.2})
    assert_mixtures_equal(cirq.mixture(d),
                          ((0.8, np.eye(4)), (0.2, np.kron(X, X))))
    assert cirq.has_mixture(d)
    np.testing.assert_equal(d._num_qubits_(), 2)
예제 #16
0
def test_missing_prob_mass():
    with pytest.raises(ValueError, match='Probabilities do not add up to 1'):
        cirq.asymmetric_depolarize(error_probabilities={'X': 0.1, 'I': 0.2})
    d = cirq.asymmetric_depolarize(error_probabilities={'X': 0.1})
    np.testing.assert_almost_equal(d.error_probabilities['I'], 0.9)
예제 #17
0
def test_asymmetric_depolarizing_channel_text_diagram():
    a = cirq.asymmetric_depolarize(0.1, 0.2, 0.3)
    assert (cirq.circuit_diagram_info(a) == cirq.CircuitDiagramInfo(
        wire_symbols=('A(0.1,0.2,0.3)', )))
예제 #18
0
def test_bad_error_probabilities_gate():
    with pytest.raises(ValueError,
                       match='AB is not made solely of I, X, Y, Z.'):
        cirq.asymmetric_depolarize(error_probabilities={'AB': 1.0})
    with pytest.raises(ValueError, match='Y must have 2 Pauli gates.'):
        cirq.asymmetric_depolarize(error_probabilities={'IX': 0.8, 'Y': 0.2})
예제 #19
0
def test_asymmetric_depolarizing_channel_bigly_probability(p_x, p_y, p_z):
    with pytest.raises(ValueError, match='was greater than 1'):
        cirq.asymmetric_depolarize(p_x, p_y, p_z)
예제 #20
0
def test_asymmetric_depolarizing_channel_negative_probability(p_x, p_y, p_z):
    with pytest.raises(ValueError, match='was less than 0'):
        cirq.asymmetric_depolarize(p_x, p_y, p_z)
def test_asymmetric_depolarizing_channel_str():
    assert (str(cirq.asymmetric_depolarize(
        0.1, 0.2, 0.3)) == 'asymmetric_depolarize(p_x=0.1,p_y=0.2,p_z=0.3)')
예제 #22
0
def test_asymmetric_depolarizing_channel_eq():

    a = cirq.asymmetric_depolarize(0.0099999, 0.01)
    b = cirq.asymmetric_depolarize(0.01, 0.0099999)
    c = cirq.asymmetric_depolarize(0.0, 0.0, 0.0)

    assert cirq.approx_eq(a, b, atol=1e-2)

    et = cirq.testing.EqualsTester()
    et.make_equality_group(lambda: c)
    et.add_equality_group(cirq.asymmetric_depolarize(0.0, 0.0, 0.1))
    et.add_equality_group(cirq.asymmetric_depolarize(0.0, 0.1, 0.0))
    et.add_equality_group(cirq.asymmetric_depolarize(0.1, 0.0, 0.0))
    et.add_equality_group(cirq.asymmetric_depolarize(0.1, 0.2, 0.3))
    et.add_equality_group(cirq.asymmetric_depolarize(0.3, 0.4, 0.3))
    et.add_equality_group(cirq.asymmetric_depolarize(1.0, 0.0, 0.0))
    et.add_equality_group(cirq.asymmetric_depolarize(0.0, 1.0, 0.0))
    et.add_equality_group(cirq.asymmetric_depolarize(0.0, 0.0, 1.0))