Example #1
0
def test_pauli_sum_exponential_parameterized_matrix_raises():
    with pytest.raises(ValueError, match='parameterized'):
        cirq.PauliSumExponential(
            cirq.X(q0) + cirq.Z(q1), sympy.Symbol("theta")).matrix()
Example #2
0
def test_with_parameters_resolved_by(psum, exp):
    psum_exp = cirq.PauliSumExponential(psum, sympy.Symbol("theta"))
    resolver = cirq.ParamResolver({"theta": exp})
    actual = cirq.resolve_parameters(psum_exp, resolver)
    expected = cirq.PauliSumExponential(psum, exp)
    assert actual == expected
Example #3
0
def test_raises_for_non_commuting_paulis():
    with pytest.raises(ValueError, match='commuting'):
        cirq.PauliSumExponential(cirq.X(q0) + cirq.Z(q0), np.pi / 2)
Example #4
0
def test_raises_for_non_hermitian_pauli():
    with pytest.raises(ValueError, match='hermitian'):
        cirq.PauliSumExponential(cirq.X(q0) + 1j * cirq.Z(q1), np.pi / 2)
Example #5
0

def test_raises_for_non_commuting_paulis():
    with pytest.raises(ValueError, match='commuting'):
        cirq.PauliSumExponential(cirq.X(q0) + cirq.Z(q0), np.pi / 2)


def test_raises_for_non_hermitian_pauli():
    with pytest.raises(ValueError, match='hermitian'):
        cirq.PauliSumExponential(cirq.X(q0) + 1j * cirq.Z(q1), np.pi / 2)


@pytest.mark.parametrize(
    'psum_exp, expected_qubits',
    (
        (cirq.PauliSumExponential(cirq.Z(q1), np.pi / 2), (q1, )),
        (
            cirq.PauliSumExponential(2j * cirq.X(q0) + 3j * cirq.Y(q2),
                                     sympy.Symbol("theta")),
            (q0, q2),
        ),
        (
            cirq.PauliSumExponential(
                cirq.X(q0) * cirq.Y(q1) + cirq.Y(q2) * cirq.Z(q3), np.pi),
            (q0, q1, q2, q3),
        ),
    ),
)
def test_pauli_sum_exponential_qubits(psum_exp, expected_qubits):
    assert psum_exp.qubits == expected_qubits