class_docstr: ControlledQutritUnitary(U, control_wires, wires, control_values)
  Apply an arbitrary fixed unitary to ``wires`` with control from the ``control_wires``.
  
  In addition to default ``Operation`` instance attributes, the following are
  available for ``ControlledQutritUnitary``:
  
  * ``control_wires``: wires that act as control for the operation
  * ``U``: unitary applied to the target wires. Accessible via ``op.parameters[0]``
  * ``control_values``: a string of trits representing the state of the control
    qutrits to control on (default is the all 2s state)
  
  **Details:**
  
  * Number of wires: Any (the operation can act on any number of wires)
  * Number of parameters: 1
  * Gradient recipe: None
  
  Args:
      U (array[complex]): square unitary matrix
      control_wires (Union[Wires, Sequence[int], or int]): the control wire(s)
      wires (Union[Wires, Sequence[int], or int]): the wire(s) the unitary acts on
      control_values (str): a string of trits representing the state of the control
          qutrits to control on (default is the all 2s state)
  
  **Example**
  
  The following shows how a single-qutrit unitary can be applied to wire ``2`` with control on
  both wires ``0`` and ``1``:
  
  >>> U = np.array([[1, 1, 0], [1, -1, 0], [0, 0, np.sqrt(2)]]) / np.sqrt(2)
  >>> qml.ControlledQutritUnitary(U, control_wires=[0, 1], wires=2)
  
  By default, controlled operations apply the desired gate if the control qutrit(s)
  are all in the state :math:`\vert 2\rangle`. However, there are some situations where
  it is necessary to apply a gate conditioned on all control qutrits being in the
  :math:`\vert 0\rangle` or :math:`\vert 1\rangle` state, or a mix of the three.
  
  The state on which to control can be changed by passing a string of trits to
  ``control_values``. For example, if we want to apply a single-qutrit unitary to
  wire ``3`` conditioned on three wires where the first is in state ``0``, the
  second is in state ``1``, and the third in state ``2``, we can write:
  
  >>> qml.ControlledQutritUnitary(U, control_wires=[0, 1, 2], wires=3, control_values='012')
class_docstr_tok: ["ControlledQutritUnitary","(","U",",","control_wires",",","wires",",","control_values",")","Apply","an","arbitrary","fixed","unitary","to","``","wires","``","with","control","from","the","``","control_wires","``",".","In","addition","to","default","``","Operation","``","instance","attributes",",","the","following","are","available","for","``","ControlledQutritUnitary","``",":","*","``","control_wires","``",":","wires","that","act","as","control","for","the","operation","*","``","U","``",":","unitary","applied","to","the","target","wires",".","Accessible","via","``","op.parameters","[","0","]","``","*","``","control_values","``",":","a","string","of","trits","representing","the","state","of","the","control","qutrits","to","control","on","(","default","is","the","all","2s","state",")","*","*","Details",":","*","*","*","Number","of","wires",":","Any","(","the","operation","can","act","on","any","number","of","wires",")","*","Number","of","parameters",":","1","*","Gradient","recipe",":","None","Args",":","U","(","array","[","complex","]",")",":","square","unitary","matrix","control_wires","(","Union","[","Wires",",","Sequence","[","int","]",",","or","int","]",")",":","the","control","wire","(","s",")","wires","(","Union","[","Wires",",","Sequence","[","int","]",",","or","int","]",")",":","the","wire","(","s",")","the","unitary","acts","on","control_values","(","str",")",":","a","string","of","trits","representing","the","state","of","the","control","qutrits","to","control","on","(","default","is","the","all","2s","state",")","*","*","Example","*","*","The","following","shows","how","a","single-qutrit","unitary","can","be","applied","to","wire","``","2","``","with","control","on","both","wires","``","0","``","and","``","1","``",":",">",">",">","U","=","np.array","(","[","[","1",",","1",",","0","]",",","[","1",",","-1",",","0","]",",","[","0",",","0",",","np.sqrt","(","2",")","]","]",")","\/","np.sqrt","(","2",")",">",">",">","qml.ControlledQutritUnitary","(","U",",","control_wires=","[","0",",","1","]",",","wires=2",")","By","default",",","controlled","operations","apply","the","desired","gate","if","the","control","qutrit","(","s",")","are","all","in","the","state",":","math",":","`","\\vert","2\\rangle","`",".","However",",","there","are","some","situations","where","it","is","necessary","to","apply","a","gate","conditioned","on","all","control","qutrits","being","in","the",":","math",":","`","\\vert","0\\rangle","`","or",":","math",":","`","\\vert","1\\rangle","`","state",",","or","a","mix","of","the","three",".","The","state","on","which","to","control","can","be","changed","by","passing","a","string","of","trits","to","``","control_values","``",".","For","example",",","if","we","want","to","apply","a","single-qutrit","unitary","to","wire","``","3","``","conditioned","on","three","wires","where","the","first","is","in","state","``","0","``",",","the","second","is","in","state","``","1","``",",","and","the","third","in","state","``","2","``",",","we","can","write",":",">",">",">","qml.ControlledQutritUnitary","(","U",",","control_wires=","[","0",",","1",",","2","]",",","wires=3",",","control_values='012","'",")"]
docstr: Representation of the operator as a canonical matrix in the computational basis (static method).
  
  The canonical matrix is the textbook matrix representation that does not consider wires.
  Implicitly, this assumes that the wires of the operator correspond to the global wire order.
  
  Args:
      U (tensor_like): unitary matrix
      control_wires (Iterable): the control wire(s)
      u_wires (Iterable): the wire(s) the unitary acts on
      control_values (str or None): a string of trits representing the state of the control
          qutrits to control on (default is the all 2s state)
  
  Returns:
      tensor_like: canonical matrix
  
  **Example**
  
  >>> U = np.array([[1, 1, 0], [1, -1, 0], [0, 0, np.sqrt(2)]]) / np.sqrt(2)
  >>> qml.ControlledQutritUnitary.compute_matrix(U, control_wires=[0], u_wires=[1], control_values="1")
  array([[ 1.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
         [ 0.        +0.j,  1.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
         [ 0.        +0.j,  0.        +0.j,  1.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
         [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.70710678+0.j,  0.70710678+0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
         [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.70710678+0.j, -0.70710678+0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
         [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  1.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
         [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  1.        +0.j,  0.        +0.j,  0.        +0.j],
         [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  1.        +0.j,  0.        +0.j],
         [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  1.        +0.j]])
docstr_tok: ["Representation","of","the","operator","as","a","canonical","matrix","in","the","computational","basis","(","static","method",")",".","The","canonical","matrix","is","the","textbook","matrix","representation","that","does","not","consider","wires",".","Implicitly",",","this","assumes","that","the","wires","of","the","operator","correspond","to","the","global","wire","order",".","Args",":","U","(","tensor_like",")",":","unitary","matrix","control_wires","(","Iterable",")",":","the","control","wire","(","s",")","u_wires","(","Iterable",")",":","the","wire","(","s",")","the","unitary","acts","on","control_values","(","str","or","None",")",":","a","string","of","trits","representing","the","state","of","the","control","qutrits","to","control","on","(","default","is","the","all","2s","state",")","Returns",":","tensor_like",":","canonical","matrix","*","*","Example","*","*",">",">",">","U","=","np.array","(","[","[","1",",","1",",","0","]",",","[","1",",","-1",",","0","]",",","[","0",",","0",",","np.sqrt","(","2",")","]","]",")","\/","np.sqrt","(","2",")",">",">",">","qml.ControlledQutritUnitary.compute_matrix","(","U",",","control_wires=","[","0","]",",","u_wires=","[","1","]",",","control_values=","''","1","''",")","array","(","[","[","1",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","1",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0",".","+0.j",",","1",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0.70710678+0.j",",","0.70710678+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0.70710678+0.j",",","-0.70710678+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","1",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","1",".","+0.j",",","0",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","1",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","0",".","+0.j",",","1",".","+0.j","]","]",")"]
code: def compute_matrix(
      U, control_wires, u_wires, control_values=None
  ):  # pylint: disable=arguments-differ
      r"""Representation of the operator as a canonical matrix in the computational basis (static method).
  
      The canonical matrix is the textbook matrix representation that does not consider wires.
      Implicitly, this assumes that the wires of the operator correspond to the global wire order.
  
      Args:
          U (tensor_like): unitary matrix
          control_wires (Iterable): the control wire(s)
          u_wires (Iterable): the wire(s) the unitary acts on
          control_values (str or None): a string of trits representing the state of the control
              qutrits to control on (default is the all 2s state)
  
      Returns:
          tensor_like: canonical matrix
  
      **Example**
  
      >>> U = np.array([[1, 1, 0], [1, -1, 0], [0, 0, np.sqrt(2)]]) / np.sqrt(2)
      >>> qml.ControlledQutritUnitary.compute_matrix(U, control_wires=[0], u_wires=[1], control_values="1")
      array([[ 1.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
             [ 0.        +0.j,  1.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
             [ 0.        +0.j,  0.        +0.j,  1.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
             [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.70710678+0.j,  0.70710678+0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
             [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.70710678+0.j, -0.70710678+0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
             [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  1.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j],
             [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  1.        +0.j,  0.        +0.j,  0.        +0.j],
             [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  1.        +0.j,  0.        +0.j],
             [ 0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  0.        +0.j,  1.        +0.j]])
      """
      target_dim = 3 ** len(u_wires)
      shape = qml.math.shape(U)
      if not (
          len(shape) in {2, 3}
          and shape[-2:] == (target_dim, target_dim)
      ):
          raise ValueError(
              f"Input unitary must be of shape {(target_dim, target_dim)} or "
              f"(batch_size, {target_dim}, {target_dim})."
          )
  
      # A multi-controlled operation is a block-diagonal matrix partitioned into
      # blocks where the operation being applied sits in the block positioned at
      # the integer value of the control string.
  
      total_wires = qml.wires.Wires(control_wires) + qml.wires.Wires(
          u_wires
      )
  
      # if control values unspecified, we control on the all-twos string
      if not control_values:
          control_values = "2" * len(control_wires)
  
      if isinstance(control_values, str):
          if len(control_values) != len(control_wires):
              raise ValueError(
                  "Length of control trit string must equal number of control wires."
              )
  
          # Make sure all values are either 0 or 1 or 2
          if not set(control_values).issubset({"0", "1", "2"}):
              raise ValueError(
                  "String of control values can contain only '0' or '1' or '2'."
              )
  
          control_int = int(control_values, 3)
      else:
          raise ValueError(
              "Alternative control values must be passed as a ternary string."
          )
  
      padding_left = control_int * target_dim
      padding_right = 3 ** len(total_wires) - target_dim - padding_left
  
      interface = qml.math.get_interface(U)
      left_pad = qml.math.cast_like(
          qml.math.eye(padding_left, like=interface), 1j
      )
      right_pad = qml.math.cast_like(
          qml.math.eye(padding_right, like=interface), 1j
      )
      if len(qml.math.shape(U)) == 3:
          return qml.math.stack(
              [
                  qml.math.block_diag([left_pad, _U, right_pad])
                  for _U in U
              ]
          )
      return qml.math.block_diag([left_pad, U, right_pad])
  
imports: import warnings
  import pennylane
  from pennylane.operation import AnyWires, Operation
  from pennylane.wires import Wires
label_desc: Use image node_id 2 for calling the ControlledQutritUnitary obj's underlying member method code with example usage: obj.compute_matrix(U, control_wires, u_wires, control_values) and returns: qml, qml