class_docstr: The single qutrit X rotation
  
  Performs the RX operation on the specified 2D subspace. The subspace is
  given as a keyword argument and determines which two of three single-qutrit
  basis states the operation applies to.
  
  The construction of this operator is based on section 3 of
  `Di et al. (2012) <https://arxiv.org/abs/1105.5485>`_.
  
  .. math:: TRX^{jk}(\phi) = \exp(-i\phi\sigma_x^{jk}/2),
  
  where :math:`\sigma_x^{jk} = |j\rangle\langle k| + |k\rangle\langle j|;`
  :math:`j, k \in \{0, 1, 2\}, j < k`.
  
  .. seealso:: :class:`~.RX`
  
  **Details:**
  
  * Number of wires: 1
  * Number of parameters: 1
  * Number of dimensions per parameter: (0,)
  
  Args:
      phi (float): rotation angle :math:`\phi`
      wires (Sequence[int] or int): the wire the operation acts on
      subspace (Sequence[int]): the 2D subspace on which to apply operation
      id (str or None): String representing the operation (optional)
  
  **Example**
  
  The specified subspace will determine which basis states the operation actually
  applies to:
  
  >>> qml.TRX(0.5, wires=0, subspace=(0, 1)).matrix()
  array([[0.96891242+0.j        , 0.        -0.24740396j, 0.        +0.j        ],
         [0.        -0.24740396j, 0.96891242+0.j        , 0.        +0.j        ],
         [0.        +0.j        , 0.        +0.j        , 1.        +0.j        ]])
  
  >>> qml.TRX(0.5, wires=0, subspace=(0, 2)).matrix()
  array([[0.96891242+0.j        , 0.        +0.j        , 0.        -0.24740396j],
         [0.        +0.j        , 1.        +0.j        , 0.        +0.j        ],
         [0.        -0.24740396j, 0.        +0.j        , 0.96891242+0.j        ]])
  
  >>> qml.TRX(0.5, wires=0, subspace=(1, 2)).matrix()
  array([[1.        +0.j        , 0.        +0.j        , 0.        +0.j        ],
         [0.        +0.j        , 0.96891242+0.j        , 0.        -0.24740396j],
         [0.        +0.j        , 0.        -0.24740396j, 0.96891242+0.j        ]])
class_docstr_tok: ["The","single","qutrit","X","rotation","Performs","the","RX","operation","on","the","specified","2D","subspace",".","The","subspace","is","given","as","a","keyword","argument","and","determines","which","two","of","three","single-qutrit","basis","states","the","operation","applies","to",".","The","construction","of","this","operator","is","based","on","section","3","of","`","Di","et","al",".","(","2012",")","<","https",":","\/\/arxiv.org\/abs\/1105.5485",">","`","_",".","..","math",":",":","TRX^","{","jk","}","(","\\phi",")","=","\\exp","(","-i\\phi\\sigma_x^","{","jk","}","\/2",")",",","where",":","math",":","`","\\sigma_x^","{","jk","}","=","|j\\rangle\\langle","k|","+","|k\\rangle\\langle","j|",";","`",":","math",":","`","j",",","k","\\in","\\","{","0",",","1",",","2\\","}",",","j","<","k","`",".","..","seealso",":",":",":","class",":","`","~.RX","`","*","*","Details",":","*","*","*","Number","of","wires",":","1","*","Number","of","parameters",":","1","*","Number","of","dimensions","per","parameter",":","(","0",",",")","Args",":","phi","(","float",")",":","rotation","angle",":","math",":","`","\\phi","`","wires","(","Sequence","[","int","]","or","int",")",":","the","wire","the","operation","acts","on","subspace","(","Sequence","[","int","]",")",":","the","2D","subspace","on","which","to","apply","operation","id","(","str","or","None",")",":","String","representing","the","operation","(","optional",")","*","*","Example","*","*","The","specified","subspace","will","determine","which","basis","states","the","operation","actually","applies","to",":",">",">",">","qml.TRX","(","0.5",",","wires=0",",","subspace=","(","0",",","1",")",")",".matrix","(",")","array","(","[","[","0.96891242+0.j",",","0",".","-0.24740396j",",","0",".","+0.j","]",",","[","0",".","-0.24740396j",",","0.96891242+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0",".","+0.j",",","1",".","+0.j","]","]",")",">",">",">","qml.TRX","(","0.5",",","wires=0",",","subspace=","(","0",",","2",")",")",".matrix","(",")","array","(","[","[","0.96891242+0.j",",","0",".","+0.j",",","0",".","-0.24740396j","]",",","[","0",".","+0.j",",","1",".","+0.j",",","0",".","+0.j","]",",","[","0",".","-0.24740396j",",","0",".","+0.j",",","0.96891242+0.j","]","]",")",">",">",">","qml.TRX","(","0.5",",","wires=0",",","subspace=","(","1",",","2",")",")",".matrix","(",")","array","(","[","[","1",".","+0.j",",","0",".","+0.j",",","0",".","+0.j","]",",","[","0",".","+0.j",",","0.96891242+0.j",",","0",".","-0.24740396j","]",",","[","0",".","+0.j",",","0",".","-0.24740396j",",","0.96891242+0.j","]","]",")"]
docstr: Representation of the operator as a canonical matrix in the computational basis.
  
  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.
  
  .. seealso:: :meth:`~.TRX.matrix`
  
  Args:
      theta (tensor_like or float): rotation angle
      subspace (Sequence[int]): the 2D subspace on which to apply the operation
  
  Returns:
      tensor_like: canonical matrix
  
  **Example**
  
  >>> qml.TRX.compute_matrix(torch.tensor(0.5), subspace=(0, 2))
  tensor([[0.9689+0.0000j, 0.0000+0.0000j, 0.0000-0.2474j],
          [0.0000+0.0000j, 1.0000+0.0000j, 0.0000+0.0000j],
          [0.0000-0.2474j, 0.0000+0.0000j, 0.9689+0.0000j]])
docstr_tok: ["Representation","of","the","operator","as","a","canonical","matrix","in","the","computational","basis",".","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",".","..","seealso",":",":",":","meth",":","`","~.TRX.matrix","`","Args",":","theta","(","tensor_like","or","float",")",":","rotation","angle","subspace","(","Sequence","[","int","]",")",":","the","2D","subspace","on","which","to","apply","the","operation","Returns",":","tensor_like",":","canonical","matrix","*","*","Example","*","*",">",">",">","qml.TRX.compute_matrix","(","torch.tensor","(","0.5",")",",","subspace=","(","0",",","2",")",")","tensor","(","[","[","0.9689+0.0000j",",","0.0000+0.0000j",",","0.0000-0.2474j","]",",","[","0.0000+0.0000j",",","1.0000+0.0000j",",","0.0000+0.0000j","]",",","[","0.0000-0.2474j",",","0.0000+0.0000j",",","0.9689+0.0000j","]","]",")"]
code: def compute_matrix(
      theta, subspace=(0, 1)
  ):  # pylint: disable=arguments-differ,dangerous-default-value
      r"""Representation of the operator as a canonical matrix in the computational basis.
  
      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.
  
      .. seealso:: :meth:`~.TRX.matrix`
  
      Args:
          theta (tensor_like or float): rotation angle
          subspace (Sequence[int]): the 2D subspace on which to apply the operation
  
      Returns:
          tensor_like: canonical matrix
  
      **Example**
  
      >>> qml.TRX.compute_matrix(torch.tensor(0.5), subspace=(0, 2))
      tensor([[0.9689+0.0000j, 0.0000+0.0000j, 0.0000-0.2474j],
              [0.0000+0.0000j, 1.0000+0.0000j, 0.0000+0.0000j],
              [0.0000-0.2474j, 0.0000+0.0000j, 0.9689+0.0000j]])
      """
      c = qml.math.cos(theta / 2)
      s = qml.math.sin(theta / 2)
  
      if qml.math.get_interface(theta) == "tensorflow":
          c = qml.math.cast_like(c, 1j)
          s = qml.math.cast_like(s, 1j)
  
      # The following avoids casting an imaginary quantity to reals when backpropagating
      c = (1 + 0j) * c
      js = -1j * s
      one = qml.math.ones_like(c)
      z = qml.math.zeros_like(c)
  
      diags = [one, one, one]
      diags[subspace[0]] = c
      diags[subspace[1]] = c
  
      off_diags = [z, z, z]
      off_diags[qml.math.sum(subspace) - 1] = js
  
      return qml.math.stack(
          [
              stack_last([diags[0], off_diags[0], off_diags[1]]),
              stack_last([off_diags[0], diags[1], off_diags[2]]),
              stack_last([off_diags[1], off_diags[2], diags[2]]),
          ],
          axis=-2,
      )
  
imports: import functools
  import numpy
  import pennylane
  from pennylane.operation import Operation
label_desc: Use image node_id 4 for calling the TRX obj's underlying member method code with example usage: obj.compute_matrix(theta, subspace) and returns: qml