class_docstr: Tests that the template defines the correct decomposition.
class_docstr_tok: ["Tests","that","the","template","defines","the","correct","decomposition","."]
docstr: Tests if QuantumPhaseEstimation populates the quantum script as expected for a fixed example
docstr_tok: ["Tests","if","QuantumPhaseEstimation","populates","the","quantum","script","as","expected","for","a","fixed","example"]
code: def test_expected_qscript(self):
      """Tests if QuantumPhaseEstimation populates the quantum script as expected for a fixed example"""
  
      m = qml.RX(0.3, wires=0).matrix()
  
      op = qml.QuantumPhaseEstimation(
          m, target_wires=[0], estimation_wires=[1, 2]
      )
      qscript = op.expand()
  
      unitary = qml.QubitUnitary(m, wires=[0])
      with qml.queuing.AnnotatedQueue() as q:
          qml.Hadamard(1)
          qml.Hadamard(2)
          qml.ctrl(qml.pow(unitary, 2), control=[1])
          qml.ctrl(qml.pow(unitary, 1), control=[2])
          qml.adjoint(qml.QFT(wires=[1, 2]))
      qscript2 = qml.tape.QuantumScript.from_queue(q)
      assert len(qscript) == len(qscript2)
      # qml.equal doesn't work for Adjoint or Pow op yet, so we stop before we get to it.
      for op1, op2 in zip(qscript[:2], qscript2[:2]):
          assert qml.equal(op1, op2)
  
      assert qml.equal(qscript[2].base.base, qscript2[2].base.base)
      assert qscript[2].base.z, qscript2[2].base.z
      assert qscript[2].control_wires == qscript2[2].control_wires
  
      assert qml.equal(qscript[3].base.base, qscript2[3].base.base)
      assert qscript[3].base.z == qscript2[3].base.z
      assert qscript[3].control_wires == qscript2[3].control_wires
  
      assert isinstance(
          qscript[-1], qml.ops.op_math.Adjoint
      )  # pylint: disable=no-member
      assert qml.equal(qscript[-1].base, qml.QFT(wires=(1, 2)))
  
      assert np.allclose(qscript[1].matrix(), qscript[1].matrix())
      assert np.allclose(qscript[3].matrix(), qscript[3].matrix())
  
file_path: pennylane/tests/templates/test_subroutines/test_qpe.py
imports: import pytest
  import numpy
  from scipy.stats import unitary_group
  import pennylane
label_desc: Use image node_id 1 for calling the TestDecomposition obj's underlying member method code with example usage: obj.test_expected_qscript() without return types