class_docstr: Gate from the group :math:`SU(N)` with :math:`N=2^n` for :math:`n` qubits.
  
  We use the following parametrization of a special unitary operator:
  
  .. math::
  
      U(\bm{\theta}) &= \exp\{A(\bm{\theta})\}\\
      A(\bm{\theta}) &= \sum_{m=1}^d i \theta_m P_m\\
      P_m &\in \{I, X, Y, Z\}^{\otimes n} \setminus \{I^{\otimes n}\}
  
  This means, :math:`U(\bm{\theta})` is the exponential of the operator :math:`A(\bm{\theta})`,
  which in turn is a linear combination of Pauli words with coefficients :math:`i\bm{\theta}`
  and satisfies :math:`A(\bm{\theta})^\dagger=-A(\bm{\theta})` (it is *skew-Hermitian*).
  Note that this gate takes an exponential number :math:`d=4^n-1` of parameters.
  See below for more theoretical background and details regarding differentiability.
  
  **Details:**
  
  * Number of wires: Any
  * Number of parameters: 1
  * Number of dimensions per parameter: (1,)
  * Gradient recipe:
  
  .. math::
  
      \frac{\partial}{\partial\theta_\ell} f(U(\bm{\theta})) &= \sum_{m=1}^d 2i\omega_{\ell m}
      \frac{\mathrm{d}}{\mathrm{d} t}
      f\left(\exp\left\{-i\frac{t}{2}G_m\right\} U(\bm{\theta})\right)\\
      &= \sum_{m=1}^d i\omega_{\ell m}
      \left[
      f\left(\exp\left\{-i\frac{\pi}{4}G_m\right\} U(\bm{\theta})\right)
      -f\left(\exp\left\{i\frac{\pi}{4}G_m\right\} U(\bm{\theta})\right)
      \right]
  
  where :math:`f` is an expectation value depending on :math:`U(\bm{\theta})` and the derivative
  of the Pauli rotation gates :math:`\exp\left\{-i\frac{t}{2}G_m\right\}` follows from
  the two-term parameter-shift rule (also see: :class:`~.PauliRot`). For details on
  the gradient recipe, also consider the theoretical background section below.
  
  Args:
      theta (tensor_like): Pauli coordinates of the exponent :math:`A(\bm{\theta})`.
          See details below for the order of the Pauli words.
      wires (Sequence[int] or int): The wire(s) the operation acts on
      id (str or None): String representing the operation (optional)
  
  Raises:
      ValueError: If the shape of the input does not match the Lie algebra
          dimension :math:`d=4^n-1` for :math:`n` wires.
  
  .. note::
  
      This operation should only be used to parametrize special unitaries that
      can not easily be represented by other operations, as it incurs
      computational cost that scale exponentially with the wires it acts on.
  
  The parameter ``theta`` refers to all Pauli words (except for the identity) in
  lexicographical order, which looks like the following for one and two qubits:
  
  >>> qml.ops.qubit.special_unitary.pauli_basis_strings(1) # 4**1-1 = 3 Pauli words
  ['X', 'Y', 'Z']
  >>> qml.ops.qubit.special_unitary.pauli_basis_strings(2) # 4**2-1 = 15 Pauli words
  ['IX', 'IY', 'IZ', 'XI', 'XX', 'XY', 'XZ', 'YI', 'YX', 'YY', 'YZ', 'ZI', 'ZX', 'ZY', 'ZZ']
  
  .. warning::
  
      This operation only is differentiable when using the JAX, Torch or Tensorflow
      interfaces, even when using hardware-compatible differentiation techniques like
      the parameter-shift rule.
  
  
  .. warning::
  
      This operation supports broadcasting and hardware-compatible differentiation
      techniques like the parameter-shift rule. However, the two features can not be
      used simultaneously.
  
  **Examples**
  
  Simple examples of this operation are single-qubit Pauli rotation gates, which can be
  created by setting all but one parameter :math:`\theta_m` to zero:
  
  >>> x = 0.412
  >>> theta = x * np.array([1, 0, 0]) # The first entry belongs to the Pauli word "X"
  >>> su = qml.SpecialUnitary(theta, wires=0)
  >>> prot = qml.PauliRot(-2 * x, "X", wires=0) # PauliRot introduces a prefactor -0.5
  >>> rx = qml.RX(-2 * x, 0) # RX introduces a prefactor -0.5
  >>> qml.math.allclose(su.matrix(), prot.matrix())
  True
  >>> qml.math.allclose(su.matrix(), rx.matrix())
  True
  
  Note that for specific operations like the ``RX`` rotation gate above, it is
  strongly recommended to use the specialized implementation ``qml.RX`` rather
  than ``PauliRot`` or ``SpecialUnitary``.
  However, ``SpecialUnitary`` gates go beyond such rotations: Multiple Pauli words
  can be activated simultaneously, giving access to more complex operations.
  For two qubits, this could look like this:
  
  >>> wires = [0, 1]
  # Activating the Pauli words ["IY", "IZ", "XX", "XY", "YY", "YZ", "ZY", "ZZ"]
  >>> theta = 0.3 * np.array([0, 1, 2, 0, -1, 1, 0, 0, 0, 1, 1, 1, 0, 0, -1])
  >>> len(theta) == 4 ** len(wires) - 1 # theta contains one parameter per Pauli word
  True
  >>> su = qml.SpecialUnitary(theta, wires=wires)
  >>> su.matrix()
  array([[ 0.56397118+0.52139241j,  0.30652227+0.02438052j,
           0.13555302+0.22630716j,  0.0689876 -0.49110826j],
         [-0.15454843+0.00998377j,  0.88294943+0.01496327j,
          -0.25396275-0.10785888j, -0.26041566+0.22857073j],
         [-0.2876174 -0.2443733j ,  0.25423439+0.05896445j,
           0.71621665+0.50686226j,  0.1380692 +0.02252197j],
         [-0.34495668-0.35307844j,  0.10817019-0.21404059j,
          -0.29040522+0.00830631j,  0.15015337-0.76933485j]])
  
  The ``SpecialUnitary`` operation also can be differentiated with hardware-compatible
  differentiation techniques if the JAX, Torch or Tensorflow interface is used.
  See the theoretical background section below for details.
  
  .. details::
      :title: Theoretical background
      :href: theory
  
      We consider special unitaries parametrized in the following way:
  
      .. math::
  
          U(\bm{\theta}) &= \exp\{A(\bm{\theta})\}\\
          A(\bm{\theta}) &= \sum_{m=1}^d i \theta_m G_m\\
          G_m &\in \mathcal{P^{(n)}}=\{I, X, Y, Z\}^{\otimes n} \setminus \{I^{\otimes n}\}
  
      where :math:`n` is the number of qubits and :math:`\theta_m` are :math:`d=4^n-1`
      real-valued parameters. This parametrization allows us to express any special unitary
      for the given number of qubits.
  
      Note that this differs from a sequence of all possible Pauli rotation gates because
      for non-commuting Pauli words :math:`G_1, G_2` we have
      :math:`\exp\{i\theta_1G_1\}\exp\{i\theta_2G_2\}\neq \exp\{i(\theta_1G_1+\theta_2G_2)\}`.
  
      **Differentiation**
  
      The partial derivatives of :math:`U(\bm{\theta})` above can be expressed as
  
      .. math::
  
          \frac{\partial}{\partial \theta_\ell} U(\bm{\theta}) &= U(\bm{\theta})
          \frac{\mathrm{d}}{\mathrm{d}t}\exp\left(t\Omega_\ell(\bm{\theta})\right)\large|_{t=0}\\
          &=U(\bm{\theta})\Omega_\ell(\bm{\theta})
  
      where :math:`\Omega_\ell(\bm{\theta})` is the *effective generator* belonging to the partial
      derivative :math:`\partial_\ell U(\bm{\theta})` at the parameters :math:`\bm{\theta}`.
      It can be computed via
  
      .. math::
  
          \Omega_\ell(\bm{\theta}) = U(\bm{\theta})^\dagger
          \left(\frac{\partial}{\partial \theta_\ell}\mathfrak{Re}[U(\bm{\theta})]
          +i\frac{\partial}{\partial \theta_\ell}\mathfrak{Im}[U(\bm{\theta})]\right)
  
      where we may compute the derivatives of the real and imaginary parts of :math:`U(\bm{\theta})`
      using auto-differentiation.
  
      Each effective generator :math:`\Omega_\ell(\bm{\theta})` that reproduces a partial derivative
      can be decomposed in the Pauli basis of :math:`\mathfrak{su}(N)` via
  
      .. math::
  
          \Omega_\ell(\bm{\theta}) = \sum_{m=1}^d \omega_{\ell m}(\bm{\theta}) G_m.
  
      As the Pauli words are orthonormal with respect to the
      `trace, or Frobenius, inner product <https://en.wikipedia.org/wiki/Frobenius_inner_product>`__
      (rescaled by :math:`2^{-n}`), we can compute the coefficients using this
      inner product (:math:`G_m` is Hermitian, so we skip the adjoint :math:`{}^\dagger`):
  
      .. math::
  
          \omega_{\ell m}(\bm{\theta}) = \frac{1}{2^n}\operatorname{tr}
          \left\{G_m \Omega_\ell(\bm{\theta}) \right\}
  
      The coefficients satisfy :math:`\omega_{\ell m}^\ast=-\omega_{\ell m}` because
      :math:`\Omega_\ell(\bm{\theta})` is skew-Hermitian. Therefore they are purely imaginary.
  
      Now we turn to the derivative of an expectation value-based function which uses a circuit
      with a ``SpecialUnitary`` operation. Absorbing the remaining circuit into the
      quantum state :math:`\rho` and the observable :math:`H`, this can be written as
  
      .. math::
  
          f(U(\bm{\theta})) &= \operatorname{Tr}\left\{H U(\bm{\theta})\rho
          U^\dagger(\bm{\theta})\right\}\\
          \partial_\ell f(U(\bm{\theta})) &= \operatorname{Tr}\left\{H U(\bm{\theta})
          [\Omega_\ell(\bm{\theta}),\rho] U^\dagger(\bm{\theta})\right\}
  
      Inserting the decomposition for the effective generator from above, we may rewrite this as
      a combination of derivatives of Pauli rotation gates:
  
      .. math::
  
          \partial_\ell f(U(\bm{\theta}))
          &= \operatorname{Tr}\left\{H U(\bm{\theta})
          \left[\sum_{m=1}^d \omega_{\ell m}(\bm{\theta}) G_m,\rho\right]
          U^\dagger(\bm{\theta})\right\}\\
          &= \sum_{m=1}^d 2i\omega_{\ell m}(\bm{\theta})
          \frac{\mathrm{d}}{\mathrm{d}t}f\left(R_{G_m}(t)U(\bm{\theta})\right)\bigg|_{t=0}.
  
      Here we abbreviated a Pauli rotation gate as :math:`R_{G_m}(t) = \exp\{-i\frac{t}{2} G_m\}`.
      As all partial derivatives are combinations of these Pauli rotation derivatives, we may
      write the gradient of :math:`f` as
  
      .. math::
  
          \nabla f(U(\bm{\theta})) = \overline{\omega}(\bm{\theta}) \cdot \bm{\mathrm{d}f}
  
      where we defined the matrix :math:`\overline{\omega_{\ell m}}=2i\omega_{\ell m}` and
      the vector of Pauli rotation derivatives
      :math:`\mathrm{d}f_m=\frac{\mathrm{d}}{\mathrm{d}t}
      f\left(R_{G_m}(t)U(\bm{\theta})\right)\bigg|_{t=0}`.
      These derivatives can be computed with the
      standard parameter-shift rule because Pauli words satisfy the condition :math:`G_m^2=1`
      (see e.g. `Mitarai et al. (2018) <https://arxiv.org/abs/1803.00745>`_).
      Provided that we can implement the ``SpecialUnitary`` gate
      itself, this allows us to compute :math:`\bm{\mathrm{d}f}` in a hardware-compatible
      manner using :math:`2d` quantum circuits.
  
      Note that for ``SpecialUnitary`` we frequently handle objects that have one or
      multiple dimensions of exponentially large size :math:`d=4^n-1`, and that the number
      of quantum circuits for the differentiation scales accordingly. This strongly affects
      the number of qubits to which we can apply a ``SpecialUnitary`` gate in practice.
class_docstr_tok: ["Gate","from","the","group",":","math",":","`","SU","(","N",")","`","with",":","math",":","`","N=2^n","`","for",":","math",":","`","n","`","qubits",".","We","use","the","following","parametrization","of","a","special","unitary","operator",":","..","math",":",":","U","(","\\bm","{","\\theta","}",")","&","=","\\exp\\","{","A","(","\\bm","{","\\theta","}",")","\\","}","\\\\","A","(","\\bm","{","\\theta","}",")","&","=","\\sum_","{","m=1","}","^d","i","\\theta_m","P_m\\\\","P_m","&","\\in","\\","{","I",",","X",",","Y",",","Z\\","}","^","{","\\otimes","n","}","\\setminus","\\","{","I^","{","\\otimes","n","}","\\","}","This","means",",",":","math",":","`","U","(","\\bm","{","\\theta","}",")","`","is","the","exponential","of","the","operator",":","math",":","`","A","(","\\bm","{","\\theta","}",")","`",",","which","in","turn","is","a","linear","combination","of","Pauli","words","with","coefficients",":","math",":","`","i\\bm","{","\\theta","}","`","and","satisfies",":","math",":","`","A","(","\\bm","{","\\theta","}",")","^\\dagger=-A","(","\\bm","{","\\theta","}",")","`","(","it","is","*","skew-Hermitian","*",")",".","Note","that","this","gate","takes","an","exponential","number",":","math",":","`","d=4^n-1","`","of","parameters",".","See","below","for","more","theoretical","background","and","details","regarding","differentiability",".","*","*","Details",":","*","*","*","Number","of","wires",":","Any","*","Number","of","parameters",":","1","*","Number","of","dimensions","per","parameter",":","(","1",",",")","*","Gradient","recipe",":","..","math",":",":","\\frac","{","\\partial","}","{","\\partial\\theta_\\ell","}","f","(","U","(","\\bm","{","\\theta","}",")",")","&","=","\\sum_","{","m=1","}","^d","2i\\omega_","{","\\ell","m","}","\\frac","{","\\mathrm","{","d","}","}","{","\\mathrm","{","d","}","t","}","f\\left","(","\\exp\\left\\","{","-i\\frac","{","t","}","{","2","}","G_m\\right\\","}","U","(","\\bm","{","\\theta","}",")","\\right",")","\\\\","&","=","\\sum_","{","m=1","}","^d","i\\omega_","{","\\ell","m","}","\\left","[","f\\left","(","\\exp\\left\\","{","-i\\frac","{","\\pi","}","{","4","}","G_m\\right\\","}","U","(","\\bm","{","\\theta","}",")","\\right",")","-f\\left","(","\\exp\\left\\","{","i\\frac","{","\\pi","}","{","4","}","G_m\\right\\","}","U","(","\\bm","{","\\theta","}",")","\\right",")","\\right","]","where",":","math",":","`","f","`","is","an","expectation","value","depending","on",":","math",":","`","U","(","\\bm","{","\\theta","}",")","`","and","the","derivative","of","the","Pauli","rotation","gates",":","math",":","`","\\exp\\left\\","{","-i\\frac","{","t","}","{","2","}","G_m\\right\\","}","`","follows","from","the","two-term","parameter-shift","rule","(","also","see",":",":","class",":","`","~.PauliRot","`",")",".","For","details","on","the","gradient","recipe",",","also","consider","the","theoretical","background","section","below",".","Args",":","theta","(","tensor_like",")",":","Pauli","coordinates","of","the","exponent",":","math",":","`","A","(","\\bm","{","\\theta","}",")","`",".","See","details","below","for","the","order","of","the","Pauli","words",".","wires","(","Sequence","[","int","]","or","int",")",":","The","wire","(","s",")","the","operation","acts","on","id","(","str","or","None",")",":","String","representing","the","operation","(","optional",")","Raises",":","ValueError",":","If","the","shape","of","the","input","does","not","match","the","Lie","algebra","dimension",":","math",":","`","d=4^n-1","`","for",":","math",":","`","n","`","wires",".","..","note",":",":","This","operation","should","only","be","used","to","parametrize","special","unitaries","that","can","not","easily","be","represented","by","other","operations",",","as","it","incurs","computational","cost","that","scale","exponentially","with","the","wires","it","acts","on",".","The","parameter","``","theta","``","refers","to","all","Pauli","words","(","except","for","the","identity",")","in","lexicographical","order",",","which","looks","like","the","following","for","one","and","two","qubits",":",">",">",">","qml.ops.qubit.special_unitary.pauli_basis_strings","(","1",")","#","4","*","*","1-1","=","3","Pauli","words","[","'","X","'",",","'","Y","'",",","'","Z","'","]",">",">",">","qml.ops.qubit.special_unitary.pauli_basis_strings","(","2",")","#","4","*","*","2-1","=","15","Pauli","words","[","'IX","'",",","'IY","'",",","'IZ","'",",","'XI","'",",","'XX","'",",","'XY","'",",","'XZ","'",",","'YI","'",",","'YX","'",",","'YY","'",",","'YZ","'",",","'ZI","'",",","'ZX","'",",","'ZY","'",",","'ZZ","'","]","..","warning",":",":","This","operation","only","is","differentiable","when","using","the","JAX",",","Torch","or","Tensorflow","interfaces",",","even","when","using","hardware-compatible","differentiation","techniques","like","the","parameter-shift","rule",".","..","warning",":",":","This","operation","supports","broadcasting","and","hardware-compatible","differentiation","techniques","like","the","parameter-shift","rule",".","However",",","the","two","features","can","not","be","used","simultaneously",".","*","*","Examples","*","*","Simple","examples","of","this","operation","are","single-qubit","Pauli","rotation","gates",",","which","can","be","created","by","setting","all","but","one","parameter",":","math",":","`","\\theta_m","`","to","zero",":",">",">",">","x","=","0.412",">",">",">","theta","=","x","*","np.array","(","[","1",",","0",",","0","]",")","#","The","first","entry","belongs","to","the","Pauli","word","``","X","''",">",">",">","su","=","qml.SpecialUnitary","(","theta",",","wires=0",")",">",">",">","prot","=","qml.PauliRot","(","-2","*","x",",","``","X","''",",","wires=0",")","#","PauliRot","introduces","a","prefactor","-0.5",">",">",">","rx","=","qml.RX","(","-2","*","x",",","0",")","#","RX","introduces","a","prefactor","-0.5",">",">",">","qml.math.allclose","(","su.matrix","(",")",",","prot.matrix","(",")",")","True",">",">",">","qml.math.allclose","(","su.matrix","(",")",",","rx.matrix","(",")",")","True","Note","that","for","specific","operations","like","the","``","RX","``","rotation","gate","above",",","it","is","strongly","recommended","to","use","the","specialized","implementation","``","qml.RX","``","rather","than","``","PauliRot","``","or","``","SpecialUnitary","``",".","However",",","``","SpecialUnitary","``","gates","go","beyond","such","rotations",":","Multiple","Pauli","words","can","be","activated","simultaneously",",","giving","access","to","more","complex","operations",".","For","two","qubits",",","this","could","look","like","this",":",">",">",">","wires","=","[","0",",","1","]","#","Activating","the","Pauli","words","[","``","IY","''",",","``","IZ","''",",","``","XX","''",",","``","XY","''",",","``","YY","''",",","``","YZ","''",",","``","ZY","''",",","``","ZZ","''","]",">",">",">","theta","=","0.3","*","np.array","(","[","0",",","1",",","2",",","0",",","-1",",","1",",","0",",","0",",","0",",","1",",","1",",","1",",","0",",","0",",","-1","]",")",">",">",">","len","(","theta",")","==","4","*","*","len","(","wires",")","-","1","#","theta","contains","one","parameter","per","Pauli","word","True",">",">",">","su","=","qml.SpecialUnitary","(","theta",",","wires=wires",")",">",">",">","su.matrix","(",")","array","(","[","[","0.56397118+0.52139241j",",","0.30652227+0.02438052j",",","0.13555302+0.22630716j",",","0.0689876","-0.49110826j","]",",","[","-0.15454843+0.00998377j",",","0.88294943+0.01496327j",",","-0.25396275-0.10785888j",",","-0.26041566+0.22857073j","]",",","[","-0.2876174","-0.2443733j",",","0.25423439+0.05896445j",",","0.71621665+0.50686226j",",","0.1380692","+0.02252197j","]",",","[","-0.34495668-0.35307844j",",","0.10817019-0.21404059j",",","-0.29040522+0.00830631j",",","0.15015337-0.76933485j","]","]",")","The","``","SpecialUnitary","``","operation","also","can","be","differentiated","with","hardware-compatible","differentiation","techniques","if","the","JAX",",","Torch","or","Tensorflow","interface","is","used",".","See","the","theoretical","background","section","below","for","details",".","..","details",":",":",":","title",":","Theoretical","background",":","href",":","theory","We","consider","special","unitaries","parametrized","in","the","following","way",":","..","math",":",":","U","(","\\bm","{","\\theta","}",")","&","=","\\exp\\","{","A","(","\\bm","{","\\theta","}",")","\\","}","\\\\","A","(","\\bm","{","\\theta","}",")","&","=","\\sum_","{","m=1","}","^d","i","\\theta_m","G_m\\\\","G_m","&","\\in","\\mathcal","{","P^","{","(","n",")","}","}","=\\","{","I",",","X",",","Y",",","Z\\","}","^","{","\\otimes","n","}","\\setminus","\\","{","I^","{","\\otimes","n","}","\\","}","where",":","math",":","`","n","`","is","the","number","of","qubits","and",":","math",":","`","\\theta_m","`","are",":","math",":","`","d=4^n-1","`","real-valued","parameters",".","This","parametrization","allows","us","to","express","any","special","unitary","for","the","given","number","of","qubits",".","Note","that","this","differs","from","a","sequence","of","all","possible","Pauli","rotation","gates","because","for","non-commuting","Pauli","words",":","math",":","`","G_1",",","G_2","`","we","have",":","math",":","`","\\exp\\","{","i\\theta_1G_1\\","}","\\exp\\","{","i\\theta_2G_2\\","}","\\neq","\\exp\\","{","i","(","\\theta_1G_1+\\theta_2G_2",")","\\","}","`",".","*","*","Differentiation","*","*","The","partial","derivatives","of",":","math",":","`","U","(","\\bm","{","\\theta","}",")","`","above","can","be","expressed","as","..","math",":",":","\\frac","{","\\partial","}","{","\\partial","\\theta_\\ell","}","U","(","\\bm","{","\\theta","}",")","&","=","U","(","\\bm","{","\\theta","}",")","\\frac","{","\\mathrm","{","d","}","}","{","\\mathrm","{","d","}","t","}","\\exp\\left","(","t\\Omega_\\ell","(","\\bm","{","\\theta","}",")","\\right",")","\\large|_","{","t=0","}","\\\\","&","=U","(","\\bm","{","\\theta","}",")","\\Omega_\\ell","(","\\bm","{","\\theta","}",")","where",":","math",":","`","\\Omega_\\ell","(","\\bm","{","\\theta","}",")","`","is","the","*","effective","generator","*","belonging","to","the","partial","derivative",":","math",":","`","\\partial_\\ell","U","(","\\bm","{","\\theta","}",")","`","at","the","parameters",":","math",":","`","\\bm","{","\\theta","}","`",".","It","can","be","computed","via","..","math",":",":","\\Omega_\\ell","(","\\bm","{","\\theta","}",")","=","U","(","\\bm","{","\\theta","}",")","^\\dagger","\\left","(","\\frac","{","\\partial","}","{","\\partial","\\theta_\\ell","}","\\mathfrak","{","Re","}","[","U","(","\\bm","{","\\theta","}",")","]","+i\\frac","{","\\partial","}","{","\\partial","\\theta_\\ell","}","\\mathfrak","{","Im","}","[","U","(","\\bm","{","\\theta","}",")","]","\\right",")","where","we","may","compute","the","derivatives","of","the","real","and","imaginary","parts","of",":","math",":","`","U","(","\\bm","{","\\theta","}",")","`","using","auto-differentiation",".","Each","effective","generator",":","math",":","`","\\Omega_\\ell","(","\\bm","{","\\theta","}",")","`","that","reproduces","a","partial","derivative","can","be","decomposed","in","the","Pauli","basis","of",":","math",":","`","\\mathfrak","{","su","}","(","N",")","`","via","..","math",":",":","\\Omega_\\ell","(","\\bm","{","\\theta","}",")","=","\\sum_","{","m=1","}","^d","\\omega_","{","\\ell","m","}","(","\\bm","{","\\theta","}",")","G_m",".","As","the","Pauli","words","are","orthonormal","with","respect","to","the","`","trace",",","or","Frobenius",",","inner","product","<","https",":","\/\/en.wikipedia.org\/wiki\/Frobenius_inner_product",">","`","__","(","rescaled","by",":","math",":","`","2^","{","-n","}","`",")",",","we","can","compute","the","coefficients","using","this","inner","product","(",":","math",":","`","G_m","`","is","Hermitian",",","so","we","skip","the","adjoint",":","math",":","`","{","}","^\\dagger","`",")",":","..","math",":",":","\\omega_","{","\\ell","m","}","(","\\bm","{","\\theta","}",")","=","\\frac","{","1","}","{","2^n","}","\\operatorname","{","tr","}","\\left\\","{","G_m","\\Omega_\\ell","(","\\bm","{","\\theta","}",")","\\right\\","}","The","coefficients","satisfy",":","math",":","`","\\omega_","{","\\ell","m","}","^\\ast=-\\omega_","{","\\ell","m","}","`","because",":","math",":","`","\\Omega_\\ell","(","\\bm","{","\\theta","}",")","`","is","skew-Hermitian",".","Therefore","they","are","purely","imaginary",".","Now","we","turn","to","the","derivative","of","an","expectation","value-based","function","which","uses","a","circuit","with","a","``","SpecialUnitary","``","operation",".","Absorbing","the","remaining","circuit","into","the","quantum","state",":","math",":","`","\\rho","`","and","the","observable",":","math",":","`","H","`",",","this","can","be","written","as","..","math",":",":","f","(","U","(","\\bm","{","\\theta","}",")",")","&","=","\\operatorname","{","Tr","}","\\left\\","{","H","U","(","\\bm","{","\\theta","}",")","\\rho","U^\\dagger","(","\\bm","{","\\theta","}",")","\\right\\","}","\\\\","\\partial_\\ell","f","(","U","(","\\bm","{","\\theta","}",")",")","&","=","\\operatorname","{","Tr","}","\\left\\","{","H","U","(","\\bm","{","\\theta","}",")","[","\\Omega_\\ell","(","\\bm","{","\\theta","}",")",",","\\rho","]","U^\\dagger","(","\\bm","{","\\theta","}",")","\\right\\","}","Inserting","the","decomposition","for","the","effective","generator","from","above",",","we","may","rewrite","this","as","a","combination","of","derivatives","of","Pauli","rotation","gates",":","..","math",":",":","\\partial_\\ell","f","(","U","(","\\bm","{","\\theta","}",")",")","&","=","\\operatorname","{","Tr","}","\\left\\","{","H","U","(","\\bm","{","\\theta","}",")","\\left","[","\\sum_","{","m=1","}","^d","\\omega_","{","\\ell","m","}","(","\\bm","{","\\theta","}",")","G_m",",","\\rho\\right","]","U^\\dagger","(","\\bm","{","\\theta","}",")","\\right\\","}","\\\\","&","=","\\sum_","{","m=1","}","^d","2i\\omega_","{","\\ell","m","}","(","\\bm","{","\\theta","}",")","\\frac","{","\\mathrm","{","d","}","}","{","\\mathrm","{","d","}","t","}","f\\left","(","R_","{","G_m","}","(","t",")","U","(","\\bm","{","\\theta","}",")","\\right",")","\\bigg|_","{","t=0","}",".","Here","we","abbreviated","a","Pauli","rotation","gate","as",":","math",":","`","R_","{","G_m","}","(","t",")","=","\\exp\\","{","-i\\frac","{","t","}","{","2","}","G_m\\","}","`",".","As","all","partial","derivatives","are","combinations","of","these","Pauli","rotation","derivatives",",","we","may","write","the","gradient","of",":","math",":","`","f","`","as","..","math",":",":","\\nabla","f","(","U","(","\\bm","{","\\theta","}",")",")","=","\\overline","{","\\omega","}","(","\\bm","{","\\theta","}",")","\\cdot","\\bm","{","\\mathrm","{","d","}","f","}","where","we","defined","the","matrix",":","math",":","`","\\overline","{","\\omega_","{","\\ell","m","}","}","=2i\\omega_","{","\\ell","m","}","`","and","the","vector","of","Pauli","rotation","derivatives",":","math",":","`","\\mathrm","{","d","}","f_m=\\frac","{","\\mathrm","{","d","}","}","{","\\mathrm","{","d","}","t","}","f\\left","(","R_","{","G_m","}","(","t",")","U","(","\\bm","{","\\theta","}",")","\\right",")","\\bigg|_","{","t=0","}","`",".","These","derivatives","can","be","computed","with","the","standard","parameter-shift","rule","because","Pauli","words","satisfy","the","condition",":","math",":","`","G_m^2=1","`","(","see","e.g",".","`","Mitarai","et","al",".","(","2018",")","<","https",":","\/\/arxiv.org\/abs\/1803.00745",">","`","_",")",".","Provided","that","we","can","implement","the","``","SpecialUnitary","``","gate","itself",",","this","allows","us","to","compute",":","math",":","`","\\bm","{","\\mathrm","{","d","}","f","}","`","in","a","hardware-compatible","manner","using",":","math",":","`","2d","`","quantum","circuits",".","Note","that","for","``","SpecialUnitary","``","we","frequently","handle","objects","that","have","one","or","multiple","dimensions","of","exponentially","large","size",":","math",":","`","d=4^n-1","`",",","and","that","the","number","of","quantum","circuits","for","the","differentiation","scales","accordingly",".","This","strongly","affects","the","number","of","qubits","to","which","we","can","apply","a","``","SpecialUnitary","``","gate","in","practice","."]
docstr: Representation of the operator as a product of other operators.
  
  .. math:: O = O_1 O_2 \dots O_n
  
  This ``Operation`` is decomposed into the corresponding ``QubitUnitary``.
  
  Returns:
      list[Operator]: decomposition of the operator
  
  **Example:**
  
  >>> theta = np.array([0.5, 0.1, -0.3])
  >>> qml.SpecialUnitary(theta, wires=[0]).decomposition()
  [QubitUnitary(array([[ 0.83004499-0.28280371j,  0.0942679 +0.47133952j],
      [-0.0942679 +0.47133952j,  0.83004499+0.28280371j]]), wires=[0])]
docstr_tok: ["Representation","of","the","operator","as","a","product","of","other","operators",".","..","math",":",":","O","=","O_1","O_2","\\dots","O_n","This","``","Operation","``","is","decomposed","into","the","corresponding","``","QubitUnitary","``",".","Returns",":","list","[","Operator","]",":","decomposition","of","the","operator","*","*","Example",":","*","*",">",">",">","theta","=","np.array","(","[","0.5",",","0.1",",","-0.3","]",")",">",">",">","qml.SpecialUnitary","(","theta",",","wires=","[","0","]",")",".decomposition","(",")","[","QubitUnitary","(","array","(","[","[","0.83004499-0.28280371j",",","0.0942679","+0.47133952j","]",",","[","-0.0942679","+0.47133952j",",","0.83004499+0.28280371j","]","]",")",",","wires=","[","0","]",")","]"]
code: def decomposition(self):
      r"""Representation of the operator as a product of other operators.
  
      .. math:: O = O_1 O_2 \dots O_n
  
      This ``Operation`` is decomposed into the corresponding ``QubitUnitary``.
  
      Returns:
          list[Operator]: decomposition of the operator
  
      **Example:**
  
      >>> theta = np.array([0.5, 0.1, -0.3])
      >>> qml.SpecialUnitary(theta, wires=[0]).decomposition()
      [QubitUnitary(array([[ 0.83004499-0.28280371j,  0.0942679 +0.47133952j],
          [-0.0942679 +0.47133952j,  0.83004499+0.28280371j]]), wires=[0])]
      """
      theta = self.data[0]
      if qml.math.requires_grad(theta):
          interface = qml.math.get_interface(theta)
          # Get all Pauli words for the basis of the Lie algebra for this gate
          words = pauli_basis_strings(self.hyperparameters["num_wires"])
  
          # Compute the linear map that transforms between the Pauli basis and effective generators
          # Consider the mathematical derivation for the prefactor 2j
          omega = qml.math.real(
              2j * self.get_one_parameter_coeffs(interface)
          )
  
          # Create zero parameters for each Pauli rotation gate that take over the trace of theta
          detached_theta = qml.math.detach(theta)
          zeros = theta - detached_theta
          # Apply the linear map omega to the zeros to create the correct preprocessing Jacobian
          zeros = qml.math.tensordot(omega, zeros, axes=[[1], [0]])
  
          # Apply Pauli rotations that yield the Pauli basis derivatives
          paulirots = [
              TmpPauliRot(
                  zero, word, wires=self.wires, id="SU(N) byproduct"
              )
              for zero, word in zip(zeros, words)
          ]
          return paulirots + [
              SpecialUnitary(detached_theta, wires=self.wires)
          ]
  
      return [qml.QubitUnitary(self.matrix(), wires=self.wires)]
  
imports: from functools import lru_cache, reduce
  from itertools import product
  import numpy
  import pennylane
  from pennylane.operation import AnyWires, Operation
  from pennylane.ops.qubit.parametric_ops_multi_qubit import PauliRot
label_desc: Use image node_id 6 for calling the SpecialUnitary obj's underlying member method code with example usage: obj.decomposition() and returns: list, unknown