class_docstr: Tests specific to the ControlledQubitUnitary operation
class_docstr_tok: ["Tests","specific","to","the","ControlledQubitUnitary","operation"]
docstr: Test if ControlledQubitUnitary properly applies mixed-polarity
  control values.
docstr_tok: ["Test","if","ControlledQubitUnitary","properly","applies","mixed-polarity","control","values","."]
code: def test_mixed_polarity_controls(
      self, control_wires, wires, control_values
  ):
      """Test if ControlledQubitUnitary properly applies mixed-polarity
      control values."""
      target_wires = Wires(wires)
  
      dev = qml.device(
          "default.qubit", wires=len(control_wires + target_wires)
      )
  
      # Pick a random unitary
      U = unitary_group.rvs(2 ** len(target_wires), random_state=1967)
  
      # Pick random starting state for the control and target qubits
      control_state_weights = np.random.normal(
          size=2 ** (len(control_wires) + 1) - 2
      )
      target_state_weights = np.random.normal(
          size=2 ** (len(target_wires) + 1) - 2
      )
  
      @qml.qnode(dev)
      def circuit_mixed_polarity():
          qml.templates.ArbitraryStatePreparation(
              control_state_weights, wires=control_wires
          )
          qml.templates.ArbitraryStatePreparation(
              target_state_weights, wires=target_wires
          )
  
          qml.ControlledQubitUnitary(
              U,
              control_wires=control_wires,
              wires=target_wires,
              control_values=control_values,
          )
          return qml.state()
  
      # The result of applying the mixed-polarity gate should be the same as
      # if we conjugated the specified control wires with Pauli X and applied the
      # "regular" ControlledQubitUnitary in between.
  
      x_locations = [
          x
          for x in range(len(control_values))
          if control_values[x] == 0
      ]
  
      @qml.qnode(dev)
      def circuit_pauli_x():
          qml.templates.ArbitraryStatePreparation(
              control_state_weights, wires=control_wires
          )
          qml.templates.ArbitraryStatePreparation(
              target_state_weights, wires=target_wires
          )
  
          for wire in x_locations:
              qml.PauliX(wires=control_wires[wire])
  
          qml.ControlledQubitUnitary(
              U, control_wires=control_wires, wires=wires
          )
  
          for wire in x_locations:
              qml.PauliX(wires=control_wires[wire])
  
          return qml.state()
  
      mixed_polarity_state = circuit_mixed_polarity()
      pauli_x_state = circuit_pauli_x()
  
      assert np.allclose(mixed_polarity_state, pauli_x_state)
  
imports: import copy
  import numpy
  import pytest
  from scipy.linalg import fractional_matrix_power
  from scipy.sparse import csr_matrix
  from scipy.stats import unitary_group
  from gate_data import CY, CZ
  import pennylane
  from pennylane.wires import Wires
  from pennylane.operation import AnyWires
  from pennylane.ops.qubit.matrix_ops import QubitUnitary
label_desc: Use image node_id 10 for calling the TestControlledQubitUnitary obj's underlying member method code with example usage: obj.test_mixed_polarity_controls(control_wires, wires, control_values) and returns: qml, qml