class_docstr: Test that the TensorFlow execute function can be differentiated
class_docstr_tok: ["Test","that","the","TensorFlow","execute","function","can","be","differentiated"]
docstr: Tests that the output of the parameter-shift transform
  can be differentiated using tensorflow, yielding second derivatives.
docstr_tok: ["Tests","that","the","output","of","the","parameter-shift","transform","can","be","differentiated","using","tensorflow",",","yielding","second","derivatives","."]
code: def test_parameter_shift_hessian(self, params, tol, interface):
      """Tests that the output of the parameter-shift transform
      can be differentiated using tensorflow, yielding second derivatives.
      """
      dev = qml.device("default.qubit.tf", wires=2)
      x, y = params * 1.0
  
      with tf.GradientTape() as t2:
          with tf.GradientTape() as t1:
              with qml.queuing.AnnotatedQueue() as q1:
                  qml.RX(params[0], wires=[0])
                  qml.RY(params[1], wires=[1])
                  qml.CNOT(wires=[0, 1])
                  qml.var(qml.PauliZ(0) @ qml.PauliX(1))
  
              tape1 = qml.tape.QuantumScript.from_queue(q1)
              with qml.queuing.AnnotatedQueue() as q2:
                  qml.RX(params[0], wires=0)
                  qml.RY(params[0], wires=1)
                  qml.CNOT(wires=[0, 1])
                  qml.probs(wires=1)
  
              tape2 = qml.tape.QuantumScript.from_queue(q2)
              result = execute(
                  [tape1, tape2],
                  dev,
                  gradient_fn=param_shift,
                  interface=interface,
                  max_diff=2,
              )
              res = result[0] + result[1][0]
  
          expected = 0.5 * (3 + np.cos(x) ** 2 * np.cos(2 * y))
          assert np.allclose(res, expected, atol=tol, rtol=0)
  
          grad = t1.gradient(res, params)
          expected = np.array(
              [
                  -np.cos(x) * np.cos(2 * y) * np.sin(x),
                  -np.cos(x) ** 2 * np.sin(2 * y),
              ]
          )
          assert np.allclose(grad, expected, atol=tol, rtol=0)
  
      hess = t2.jacobian(grad, params)
      expected = np.array(
          [
              [
                  -np.cos(2 * x) * np.cos(2 * y),
                  np.sin(2 * x) * np.sin(2 * y),
              ],
              [
                  np.sin(2 * x) * np.sin(2 * y),
                  -2 * np.cos(x) ** 2 * np.cos(2 * y),
              ],
          ]
      )
      assert np.allclose(hess, expected, atol=tol, rtol=0)
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane.gradients import finite_diff, param_shift
  from pennylane import execute
label_desc: Use image node_id 1 for calling the TestHigherOrderDerivatives obj's underlying member method code with example usage: obj.test_parameter_shift_hessian(params, tol, interface) without return types