class_docstr: Differentiation tests
class_docstr_tok: ["Differentiation","tests"]
docstr: Test that differentiation works correctly when using TF
docstr_tok: ["Test","that","differentiation","works","correctly","when","using","TF"]
code: def test_tensorflow(self, v):
      """Test that differentiation works correctly when using TF"""
      import tensorflow as tf
  
      def circuit(theta):
          qml.RX(theta, wires=0)
          qml.PauliZ(wires=0)
          qml.CNOT(wires=[0, 1])
  
      def loss(theta):
          U = qml.eigvals(circuit)(theta)
          return qml.math.sum(qml.math.real(U))
  
      x = tf.Variable(v)
      with tf.GradientTape() as tape:
          with pytest.warns(
              UserWarning,
              match="the eigenvalues will be computed numerically",
          ):
              l = loss(x)
      dl = tape.gradient(l, x)
  
      assert isinstance(l, tf.Tensor)
      assert np.allclose(l, 2 * np.cos(v / 2))
      assert np.allclose(dl, -np.sin(v / 2))
  
imports: from functools import reduce
  import pytest
  import scipy
  from gate_data import CNOT, H, I, S, X, Y, Z
  import pennylane
  from pennylane import numpy
  from pennylane.transforms.op_transforms import OperationTransformError
label_desc: Use image node_id 3 for calling the TestDifferentiation obj's underlying member method code with example usage: obj.test_tensorflow(v) and returns: qml