class_docstr: Tests for the hamiltonian_expand transform
class_docstr_tok: ["Tests","for","the","hamiltonian_expand","transform"]
docstr: Tests that the hamiltonian_expand tape transform is differentiable with the Tensorflow interface
docstr_tok: ["Tests","that","the","hamiltonian_expand","tape","transform","is","differentiable","with","the","Tensorflow","interface"]
code: def test_hamiltonian_dif_tensorflow(self):
      """Tests that the hamiltonian_expand tape transform is differentiable with the Tensorflow interface"""
  
      import tensorflow as tf
  
      H = qml.Hamiltonian(
          [-0.2, 0.5, 1],
          [qml.PauliX(1), qml.PauliZ(1) @ qml.PauliY(2), qml.PauliZ(0)],
      )
      var = tf.Variable(
          [[0.1, 0.67, 0.3], [0.4, -0.5, 0.7]], dtype=tf.float64
      )
      output = 0.42294409781940356
      output2 = [
          9.68883500e-02,
          -2.90832724e-01,
          -1.04448033e-01,
          -1.94289029e-09,
          3.50307411e-01,
          -3.41123470e-01,
      ]
  
      with tf.GradientTape() as gtape:
          with AnnotatedQueue() as q:
              for _i in range(2):
                  qml.RX(var[_i, 0], wires=0)
                  qml.RX(var[_i, 1], wires=1)
                  qml.RX(var[_i, 2], wires=2)
                  qml.CNOT(wires=[0, 1])
                  qml.CNOT(wires=[1, 2])
                  qml.CNOT(wires=[2, 0])
              qml.expval(H)
  
          tape = QuantumScript.from_queue(q)
          tapes, fn = hamiltonian_expand(tape)
          res = fn(qml.execute(tapes, dev, qml.gradients.param_shift))
  
          assert np.isclose(res, output)
  
          g = gtape.gradient(res, var)
          assert np.allclose(list(g[0]) + list(g[1]), output2)
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.queuing import AnnotatedQueue
  from pennylane.tape import QuantumScript
  from pennylane.transforms import hamiltonian_expand, sum_expand
label_desc: Use image node_id 10 for calling the TestHamiltonianExpand obj's underlying member method code with example usage: obj.test_hamiltonian_dif_tensorflow() without return types