class_docstr: Test to check that the iterative quantum phase estimation function works as expected.
class_docstr_tok: ["Test","to","check","that","the","iterative","quantum","phase","estimation","function","works","as","expected","."]
docstr: Test to check that the gradients are correct comparing with the expanded circuit using PyTorch
docstr_tok: ["Test","to","check","that","the","gradients","are","correct","comparing","with","the","expanded","circuit","using","PyTorch"]
code: def test_check_gradients_torch(self):
      """Test to check that the gradients are correct comparing with the expanded circuit using PyTorch"""
  
      import torch
  
      dev = qml.device("default.qubit")
  
      @qml.qnode(dev)
      def circuit(theta):
          meas = qml.iterative_qpe(
              qml.RZ(theta, wires=[0]), [1], iters=2
          )
          return qml.expval(meas[0])
  
      @qml.qnode(dev)
      def manual_circuit(phi):
          qml.Hadamard(wires=[1])
          qml.ctrl(qml.RZ(phi, wires=[0]) ** 2, control=[1])
          qml.Hadamard(wires=[1])
          qml.CNOT(wires=[1, 2])
          qml.CNOT(wires=[2, 1])
          qml.Hadamard(wires=[1])
          qml.ctrl(qml.RZ(phi, wires=[0]), control=[1])
          qml.ctrl(qml.PhaseShift(-np.pi / 2, wires=[1]), control=[2])
          qml.Hadamard(wires=[1])
          qml.CNOT(wires=[1, 3])
          qml.CNOT(wires=[3, 1])
  
          return qml.expval(qml.Hermitian([[0, 0], [0, 1]], wires=3))
  
      phi = torch.tensor(1.0, requires_grad=True)
      assert torch.isclose(
          torch.func.grad(circuit)(phi),
          torch.func.grad(manual_circuit)(phi),
      )
  
file_path: pennylane/tests/ops/functions/test_iterative_qpe.py
imports: import pytest
  import numpy
  import pennylane
label_desc: Use image node_id 3 for calling the TestIQPE obj's underlying member method code with example usage: obj.test_check_gradients_torch() and returns: qml, qml