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 results obtained are equivalent to those of QuantumPhaseEstimation
docstr_tok: ["Test","to","check","that","the","results","obtained","are","equivalent","to","those","of","QuantumPhaseEstimation"]
code: def test_compare_qpe(self, phi):
      """Test to check that the results obtained are equivalent to those of QuantumPhaseEstimation"""
  
      # TODO: When we have general statistics on measurements we can calculate it exactly with qml.probs
      dev = qml.device("default.qubit", shots=10000000)
  
      @qml.qnode(dev)
      def circuit_iterative():
          # Initial state
          qml.PauliX(wires=[0])
  
          # Iterative QPE
          measurements = qml.iterative_qpe(
              qml.RZ(phi, wires=[0]), ancilla=[1], iters=3
          )
  
          return [qml.sample(op=meas) for meas in measurements]
  
      sample_list = np.array(circuit_iterative())
      sample_list = sample_list.T
      output = qml.probs().process_samples(
          np.array(sample_list), wire_order=[0, 1, 2]
      )
  
      @qml.qnode(dev)
      def circuit_qpe():
          # Initial state
          qml.PauliX(wires=[0])
  
          # Iterative QPE
          qml.QuantumPhaseEstimation(
              qml.RZ(phi, wires=[0]), estimation_wires=[1, 2, 3]
          )
  
          return qml.probs(wires=[1, 2, 3])
  
      assert np.allclose(
          np.round(output, 2), np.round(circuit_qpe(), 2)
      )
  
file_path: pennylane/tests/ops/functions/test_iterative_qpe.py
imports: import pytest
  import numpy
  import pennylane
label_desc: Use image node_id 1 for calling the TestIQPE obj's underlying member method code with example usage: obj.test_compare_qpe(phi) and returns: unknown, qml