def test_hermitian_expectation(self, device, shots, tol):
    'Test that arbitrary 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(A, wires=[0], do_queue=False).diagonalizing_gates() + O(A, wires=[1], do_queue=False).diagonalizing_gates()))
    dev._obs_queue = [O(A, wires=[0], do_queue=False), O(A, wires=[1], do_queue=False)]
    res = np.array([dev.expval(O(A, wires=[0], do_queue=False)), dev.expval(O(A, wires=[1], do_queue=False))])
    a = A[(0, 0)]
    re_b = A[(0, 1)].real
    d = A[(1, 1)]
    ev1 = ((((((a - d) * np.cos(theta)) + (((2 * re_b) * np.sin(theta)) * np.sin(phi))) + a) + d) / 2)
    ev2 = (((((((a - d) * np.cos(theta)) * np.cos(phi)) + ((2 * re_b) * np.sin(phi))) + a) + d) / 2)
    expected = np.array([ev1, ev2])
    assert np.allclose(res, expected, **tol)
Test that arbitrary Hermitian expectation values are correct
def test_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(A, wires=[0], do_queue=False).diagonalizing_gates() + O(A, wires=[1], do_queue=False).diagonalizing_gates()))
    dev._obs_queue = [O(A, wires=[0], do_queue=False), O(A, wires=[1], do_queue=False)]
    res = np.array([dev.expval(O(A, wires=[0], do_queue=False)), dev.expval(O(A, wires=[1], do_queue=False))])
    a = A[(0, 0)]
    re_b = A[(0, 1)].real
    d = A[(1, 1)]
    ev1 = ((((((a - d) * np.cos(theta)) + (((2 * re_b) * np.sin(theta)) * np.sin(phi))) + a) + d) / 2)
    ev2 = (((((((a - d) * np.cos(theta)) * np.cos(phi)) + ((2 * re_b) * np.sin(phi))) + a) + d) / 2)
    expected = np.array([ev1, ev2])
    assert np.allclose(res, expected, **tol)