class_docstr: Tests for the apply_controlled_Q function
class_docstr_tok: ["Tests","for","the","apply_controlled_Q","function"]
docstr: Test if the apply_controlled_Q performs the correct transformation by reconstructing the
  unitary and comparing against the one provided in make_Q. Random unitaries are chosen for
  a_mat and r_mat.
docstr_tok: ["Test","if","the","apply_controlled_Q","performs","the","correct","transformation","by","reconstructing","the","unitary","and","comparing","against","the","one","provided","in","make_Q",".","Random","unitaries","are","chosen","for","a_mat","and","r_mat","."]
code: def test_apply(self, n_wires):
      """Test if the apply_controlled_Q performs the correct transformation by reconstructing the
      unitary and comparing against the one provided in make_Q. Random unitaries are chosen for
      a_mat and r_mat."""
      n_all_wires = n_wires + 1
  
      wires = range(n_wires)
      target_wire = n_wires - 1
      control_wire = 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 = apply_controlled_Q(
          fn,
          wires=wires,
          target_wire=target_wire,
          control_wire=control_wire,
          work_wires=None,
      )
  
      u = get_unitary(circ, n_all_wires)
  
      circ = lambda: qml.ControlledQubitUnitary(
          q_mat, wires=wires, control_wires=control_wire
      )
      u_ideal = get_unitary(circ, 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 TestApplyControlledQ obj's underlying member method code with example usage: obj.test_apply(n_wires) without return types