def test_multi_mode_hermitian_expectation(self, device, shots, tol):
    'Test that arbitrary multi-mode Hermitian expectation values are correct'
    theta = 0.432
    phi = 0.123
    dev = device(2)
    O = qml.Hermitian
    with mimic_execution_for_expval(dev):
        dev.apply([qml.RY(theta, wires=[0]), qml.RY(phi, wires=[1]), qml.CNOT(wires=[0, 1])], rotations=O(B, wires=[0, 1], do_queue=False).diagonalizing_gates())
    dev._obs_queue = [O(B, wires=[0, 1], do_queue=False)]
    res = np.array([dev.expval(O(B, wires=[0, 1], do_queue=False))])
    expected = (0.5 * ((((((6 * np.cos(theta)) * np.sin(phi)) - (np.sin(theta) * (((8 * np.sin(phi)) + (7 * np.cos(phi))) + 3))) - (2 * np.sin(phi))) - (6 * np.cos(phi))) - 6))
    assert np.allclose(res, expected, **tol)
Test that arbitrary multi-mode Hermitian expectation values are correct
def test_multi_mode_hermitian_expectation(self, device, shots, tol):
    
    theta = 0.432
    phi = 0.123
    dev = device(2)
    O = qml.Hermitian
    with mimic_execution_for_expval(dev):
        dev.apply([qml.RY(theta, wires=[0]), qml.RY(phi, wires=[1]), qml.CNOT(wires=[0, 1])], rotations=O(B, wires=[0, 1], do_queue=False).diagonalizing_gates())
    dev._obs_queue = [O(B, wires=[0, 1], do_queue=False)]
    res = np.array([dev.expval(O(B, wires=[0, 1], do_queue=False))])
    expected = (0.5 * ((((((6 * np.cos(theta)) * np.sin(phi)) - (np.sin(theta) * (((8 * np.sin(phi)) + (7 * np.cos(phi))) + 3))) - (2 * np.sin(phi))) - (6 * np.cos(phi))) - 6))
    assert np.allclose(res, expected, **tol)