class_docstr: Tests for the quantum_monte_carlo function
class_docstr_tok: ["Tests","for","the","quantum_monte_carlo","function"]
docstr: Test if the quantum_monte_carlo performs the correct transformation by reconstructing the
  unitary and comparing against the one provided in the QuantumPhaseEstimation template.
  Random unitaries are chosen for a_mat and r_mat.
docstr_tok: ["Test","if","the","quantum_monte_carlo","performs","the","correct","transformation","by","reconstructing","the","unitary","and","comparing","against","the","one","provided","in","the","QuantumPhaseEstimation","template",".","Random","unitaries","are","chosen","for","a_mat","and","r_mat","."]
code: def test_apply(self, n_wires):
      """Test if the quantum_monte_carlo performs the correct transformation by reconstructing the
      unitary and comparing against the one provided in the QuantumPhaseEstimation template.
      Random unitaries are chosen for a_mat and r_mat."""
      n_all_wires = 2 * n_wires
  
      wires = range(n_wires)
      target_wire = n_wires - 1
      estimation_wires = range(n_wires, 2 * n_wires)
  
      a_mat = unitary_group.rvs(2 ** (n_wires - 1), random_state=1967)
      r_mat = unitary_group.rvs(2**n_wires, random_state=1967)
      q_mat = make_Q(a_mat, r_mat)
  
      def fn():
          qml.QubitUnitary(a_mat, wires=wires[:-1])
          qml.QubitUnitary(r_mat, wires=wires)
  
      circ = quantum_monte_carlo(
          fn,
          wires=wires,
          target_wire=target_wire,
          estimation_wires=estimation_wires,
      )
  
      u = get_unitary(circ, n_all_wires)
  
      def circ_ideal():
          fn()
          qml.templates.QuantumPhaseEstimation(
              q_mat,
              target_wires=wires,
              estimation_wires=estimation_wires,
          )
  
      u_ideal = get_unitary(circ_ideal, n_all_wires)
      assert np.allclose(u_ideal, u)
  
file_path: pennylane/tests/transforms/test_qmc_transform.py
imports: import itertools
  import numpy
  import pytest
  from scipy.stats import unitary_group, norm
  import pennylane
  from pennylane.transforms.qmc import _apply_controlled_z, _apply_controlled_v, apply_controlled_Q, quantum_monte_carlo
  from pennylane.templates.subroutines.qmc import _make_V, _make_Z, make_Q
  from pennylane.wires import Wires
label_desc: Use image node_id 1 for calling the TestQuantumMonteCarlo obj's underlying member method code with example usage: obj.test_apply(n_wires) without return types