class_docstr: Tests for the QuantumMonteCarlo template
class_docstr_tok: ["Tests","for","the","QuantumMonteCarlo","template"]
docstr: Test if the circuit applied when using the QMC template is the same as the expected
  circuit for a fixed example
docstr_tok: ["Test","if","the","circuit","applied","when","using","the","QMC","template","is","the","same","as","the","expected","circuit","for","a","fixed","example"]
code: def test_expected_circuit(self):
      """Test if the circuit applied when using the QMC template is the same as the expected
      circuit for a fixed example"""
      p = np.ones(4) / 4
      target_wires, estimation_wires = Wires(range(3)), Wires(
          range(3, 5)
      )
  
      op = QuantumMonteCarlo(
          p, self.func, target_wires, estimation_wires
      )
      tape = op.expand()
  
      # Do expansion in two steps to avoid also decomposing the first QubitUnitary
      queue_before_qpe = tape.operations[:2]
  
      # 2-qubit decomposition has 18 operations, and after is a 3-qubit gate so start at 19
      queue_after_qpe = tape.expand().operations[19:]
  
      A = probs_to_unitary(p)
      R = func_to_unitary(self.func, 4)
  
      assert len(queue_before_qpe) == 2
      assert queue_before_qpe[0].name == "QubitUnitary"
      assert queue_before_qpe[1].name == "QubitUnitary"
      assert np.allclose(queue_before_qpe[0].matrix(), A)
      assert np.allclose(queue_before_qpe[1].matrix(), R)
      assert queue_before_qpe[0].wires == target_wires[:-1]
      assert queue_before_qpe[1].wires == target_wires
  
      Q = make_Q(A, R)
  
      with qml.queuing.AnnotatedQueue() as q_qpe_tape:
          qml.QuantumPhaseEstimation(Q, target_wires, estimation_wires)
  
      qpe_tape = qml.tape.QuantumScript.from_queue(q_qpe_tape)
      qpe_tape = qpe_tape.expand()
  
      assert len(queue_after_qpe) == len(qpe_tape.operations)
      assert all(
          o1.name == o2.name
          for o1, o2 in zip(queue_after_qpe, qpe_tape.operations)
      )
      assert all(
          np.allclose(o1.matrix(), o2.matrix())
          for o1, o2 in zip(queue_after_qpe, qpe_tape.operations)
      )
      assert all(
          o1.wires == o2.wires
          for o1, o2 in zip(queue_after_qpe, qpe_tape.operations)
      )
  
imports: import numpy
  import pytest
  from scipy.stats import norm
  import pennylane
  from pennylane.templates.subroutines.qmc import QuantumMonteCarlo, _make_V, _make_Z, func_to_unitary, make_Q, probs_to_unitary
  from pennylane.wires import Wires
label_desc: Use image node_id 6 for calling the TestQuantumMonteCarlo obj's underlying member method code with example usage: obj.test_expected_circuit() without return types