class_docstr: Returns the gradient as a callable function of hybrid quantum-classical functions.
  :func:`~.qjit` and Autograd compatible.
  
  By default, gradients are computed for arguments which contain
  the property ``requires_grad=True``. Alternatively, the ``argnum`` keyword argument
  can be specified to compute gradients for function arguments without this property,
  such as scalars, lists, tuples, dicts, or vanilla NumPy arrays. Setting
  ``argnum`` to the index of an argument with ``requires_grad=False`` will raise
  a ``NonDifferentiableError``.
  
  When the output gradient function is executed, both the forward pass
  *and* the backward pass will be performed in order to compute the gradient.
  The value of the forward pass is available via the :attr:`~.forward` property.
  
  .. warning::
      ``grad`` is intended to be used with the Autograd interface only.
  
  .. note::
  
      When used with :func:`~.qjit`, this function currently only supports the
      Catalyst compiler. See :func:`catalyst.grad` for more details.
  
      Please see the Catalyst :doc:`quickstart guide <catalyst:dev/quick_start>`,
      as well as the :doc:`sharp bits and debugging tips <catalyst:dev/sharp_bits>`
      page for an overview of the differences between Catalyst and PennyLane.
  
  Args:
      func (function): a plain QNode, or a Python function that contains
          a combination of quantum and classical nodes
  
      argnum (int, list(int), None): Which argument(s) to take the gradient
          with respect to. By default, the arguments themselves are used
          to determine differentiability, by examining the ``requires_grad``
          property.
  
      method (str): Specifies the gradient method when used with the :func:`~.qjit`
          decorator. Outside of :func:`~.qjit`, this keyword argument
          has no effect and should not be set. In just-in-time (JIT) mode,
          this can be any of ``["auto", "fd"]``, where:
  
          - ``"auto"`` represents deferring the quantum differentiation to the method
            specified by the QNode, while the classical computation is differentiated
            using traditional auto-diff. Catalyst supports ``"parameter-shift"`` and
            ``"adjoint"`` on internal QNodes. QNodes with ``diff_method="finite-diff"``
            are not supported with ``"auto"``.
  
          - ``"fd"`` represents first-order finite-differences for the entire hybrid
            function.
  
      h (float): The step-size value for the finite-difference (``"fd"``) method within
          :func:`~.qjit` decorated functions. This value has
          no effect in non-compiled functions.
  
  Returns:
      function: The function that returns the gradient of the input
      function with respect to the differentiable arguments, or, if specified,
      the arguments in ``argnum``.
class_docstr_tok: ["Returns","the","gradient","as","a","callable","function","of","hybrid","quantum-classical","functions",".",":","func",":","`","~.qjit","`","and","Autograd","compatible",".","By","default",",","gradients","are","computed","for","arguments","which","contain","the","property","``","requires_grad=True","``",".","Alternatively",",","the","``","argnum","``","keyword","argument","can","be","specified","to","compute","gradients","for","function","arguments","without","this","property",",","such","as","scalars",",","lists",",","tuples",",","dicts",",","or","vanilla","NumPy","arrays",".","Setting","``","argnum","``","to","the","index","of","an","argument","with","``","requires_grad=False","``","will","raise","a","``","NonDifferentiableError","``",".","When","the","output","gradient","function","is","executed",",","both","the","forward","pass","*","and","*","the","backward","pass","will","be","performed","in","order","to","compute","the","gradient",".","The","value","of","the","forward","pass","is","available","via","the",":","attr",":","`","~.forward","`","property",".","..","warning",":",":","``","grad","``","is","intended","to","be","used","with","the","Autograd","interface","only",".","..","note",":",":","When","used","with",":","func",":","`","~.qjit","`",",","this","function","currently","only","supports","the","Catalyst","compiler",".","See",":","func",":","`","catalyst.grad","`","for","more","details",".","Please","see","the","Catalyst",":","doc",":","`","quickstart","guide","<","catalyst",":","dev\/quick_start",">","`",",","as","well","as","the",":","doc",":","`","sharp","bits","and","debugging","tips","<","catalyst",":","dev\/sharp_bits",">","`","page","for","an","overview","of","the","differences","between","Catalyst","and","PennyLane",".","Args",":","func","(","function",")",":","a","plain","QNode",",","or","a","Python","function","that","contains","a","combination","of","quantum","and","classical","nodes","argnum","(","int",",","list","(","int",")",",","None",")",":","Which","argument","(","s",")","to","take","the","gradient","with","respect","to",".","By","default",",","the","arguments","themselves","are","used","to","determine","differentiability",",","by","examining","the","``","requires_grad","``","property",".","method","(","str",")",":","Specifies","the","gradient","method","when","used","with","the",":","func",":","`","~.qjit","`","decorator",".","Outside","of",":","func",":","`","~.qjit","`",",","this","keyword","argument","has","no","effect","and","should","not","be","set",".","In","just-in-time","(","JIT",")","mode",",","this","can","be","any","of","``","[","``","auto","''",",","``","fd","''","]","``",",","where",":","-","``","``","auto","''","``","represents","deferring","the","quantum","differentiation","to","the","method","specified","by","the","QNode",",","while","the","classical","computation","is","differentiated","using","traditional","auto-diff",".","Catalyst","supports","``","``","parameter-shift","''","``","and","``","``","adjoint","''","``","on","internal","QNodes",".","QNodes","with","``","diff_method=","''","finite-diff","''","``","are","not","supported","with","``","``","auto","''","``",".","-","``","``","fd","''","``","represents","first-order","finite-differences","for","the","entire","hybrid","function",".","h","(","float",")",":","The","step-size","value","for","the","finite-difference","(","``","``","fd","''","``",")","method","within",":","func",":","`","~.qjit","`","decorated","functions",".","This","value","has","no","effect","in","non-compiled","functions",".","Returns",":","function",":","The","function","that","returns","the","gradient","of","the","input","function","with","respect","to","the","differentiable","arguments",",","or",",","if","specified",",","the","arguments","in","``","argnum","``","."]
docstr: Get the required gradient function.
  
  * If the differentiable argnum was provided on initialization,
    this has been pre-computed and is available via self._grad_fn
  
  * Otherwise, we must dynamically construct the gradient function by
    inspecting as to which of the parameter arguments are marked
    as differentiable.
docstr_tok: ["Get","the","required","gradient","function",".","*","If","the","differentiable","argnum","was","provided","on","initialization",",","this","has","been","pre-computed","and","is","available","via","self._grad_fn","*","Otherwise",",","we","must","dynamically","construct","the","gradient","function","by","inspecting","as","to","which","of","the","parameter","arguments","are","marked","as","differentiable","."]
code: def _get_grad_fn(self, args):
      """Get the required gradient function.
  
      * If the differentiable argnum was provided on initialization,
        this has been pre-computed and is available via self._grad_fn
  
      * Otherwise, we must dynamically construct the gradient function by
        inspecting as to which of the parameter arguments are marked
        as differentiable.
      """
      if self._grad_fn is not None:
          return self._grad_fn, self._argnum
  
      # Inspect the arguments for differentiability, and
      # compute the autograd gradient function with required argnums
      # dynamically.
      argnum = []
  
      for idx, arg in enumerate(args):
          trainable = getattr(arg, "requires_grad", None) or isinstance(
              arg, ArrayBox
          )
          if trainable:
              if arg.dtype.name[:3] == "int":
                  raise ValueError(
                      "Autograd does not support differentiation of ints."
                  )
              argnum.append(idx)
  
      if len(argnum) == 1:
          argnum = argnum[0]
  
      # Known pylint issue with function signatures and decorators:
      # pylint:disable=unexpected-keyword-arg,no-value-for-parameter
      return self._grad_with_forward(self._fun, argnum=argnum), argnum
  
file_path: pennylane/pennylane/_grad.py
imports: import warnings
  from autograd import jacobian
  from autograd.core import make_vjp
  from autograd.numpy.numpy_boxes import ArrayBox
  from autograd.extend import vspace
  from autograd.wrap_util import unary_to_nary
  from pennylane.compiler import compiler
  from pennylane.compiler.compiler import CompileError
label_desc: Use image node_id 3 for calling the grad obj's underlying member method code with example usage: obj._get_grad_fn(args) and returns: self,  argnum, self,  self