def test_hermitian(self, device, shots, tol):
    'Test that a tensor product involving qml.Hermitian works correctly'
    theta = 0.432
    phi = 0.123
    varphi = (- 0.543)
    dev = device(3)
    A = np.array([[(- 6), (2 + 1j), (- 3), ((- 5) + 2j)], [(2 - 1j), 0, (2 - 1j), ((- 5) + 4j)], [(- 3), (2 + 1j), 0, ((- 4) + 3j)], [((- 5) - 2j), ((- 5) - 4j), ((- 4) - 3j), (- 6)]])
    obs = (qml.PauliZ(wires=[0], do_queue=False) @ qml.Hermitian(A, wires=[1, 2], do_queue=False))
    with mimic_execution_for_expval(dev):
        dev.apply([qml.RX(theta, wires=[0]), qml.RX(phi, wires=[1]), qml.RX(varphi, wires=[2]), qml.CNOT(wires=[0, 1]), qml.CNOT(wires=[1, 2])], rotations=obs.diagonalizing_gates())
    res = dev.expval(obs)
    expected = (0.5 * ((((((- 6) * np.cos(theta)) * (np.cos(varphi) + 1)) - ((2 * np.sin(varphi)) * ((np.cos(theta) + np.sin(phi)) - (2 * np.cos(phi))))) + ((3 * np.cos(varphi)) * np.sin(phi))) + np.sin(phi)))
    assert np.allclose(res, expected, **tol)
Test that a tensor product involving qml.Hermitian works correctly
def test_hermitian(self, device, shots, tol):
    
    theta = 0.432
    phi = 0.123
    varphi = (- 0.543)
    dev = device(3)
    A = np.array([[(- 6), (2 + 1j), (- 3), ((- 5) + 2j)], [(2 - 1j), 0, (2 - 1j), ((- 5) + 4j)], [(- 3), (2 + 1j), 0, ((- 4) + 3j)], [((- 5) - 2j), ((- 5) - 4j), ((- 4) - 3j), (- 6)]])
    obs = (qml.PauliZ(wires=[0], do_queue=False) @ qml.Hermitian(A, wires=[1, 2], do_queue=False))
    with mimic_execution_for_expval(dev):
        dev.apply([qml.RX(theta, wires=[0]), qml.RX(phi, wires=[1]), qml.RX(varphi, wires=[2]), qml.CNOT(wires=[0, 1]), qml.CNOT(wires=[1, 2])], rotations=obs.diagonalizing_gates())
    res = dev.expval(obs)
    expected = (0.5 * ((((((- 6) * np.cos(theta)) * (np.cos(varphi) + 1)) - ((2 * np.sin(varphi)) * ((np.cos(theta) + np.sin(phi)) - (2 * np.cos(phi))))) + ((3 * np.cos(varphi)) * np.sin(phi))) + np.sin(phi)))
    assert np.allclose(res, expected, **tol)