quadax.adaptive_quadrature

quadax.adaptive_quadrature(rule: AbstractQuadratureRule, fun: Callable[[...], Array], interval: Array | ndarray | bool | number | bool | int | float | complex, args: tuple = (), full_output: bool = False, epsabs: Array | ndarray | bool | number | bool | int | float | complex | None = None, epsrel: Array | ndarray | bool | number | bool | int | float | complex | None = None, max_ninter: int = 50, adjoint: AbstractAdjoint = DirectAdjoint(), extrapolate: bool = True, throw: bool = False, **kwargs)Source

Global adaptive quadrature with user specified local rule.

This is a lower level routine allowing for custom local quadrature rules. For most applications the higher order methods quadgk(), quadcc(), quadts() are preferable.

Parameters:
  • rule (AbstractQuadratureRule) – Local quadrature rule to use.

  • fun (callable) – Function to integrate, should have a signature of the form fun(x, *args) -> float, Array. Should be JAX transformable.

  • interval (array-like) – Lower and upper limits of integration with possible breakpoints. Use np.inf to denote infinite intervals. Its dtype sets the working precision: the integrand is called with an x of this dtype, and the result follows it unless the integrand upcasts. Integer types or python floats fall back to the JAX default. Must be real; complex integrands are supported, complex limits are not.

  • args (tuple, optional) – Extra arguments passed to fun.

  • full_output (bool, optional) – If True, return the full state of the integrator. See below for more information.

  • epsabs (float, optional) – Absolute and relative error tolerance. Default is the square root of the machine precision of the working dtype, ie of interval, or of the integrand’s own dtype if that is the coarser of the two. Algorithm tries to obtain an accuracy of abs(i-result) <= max(epsabs, epsrel*abs(i)) where i = integral of fun over interval, and result is the numerical approximation.

  • epsrel (float, optional) – Absolute and relative error tolerance. Default is the square root of the machine precision of the working dtype, ie of interval, or of the integrand’s own dtype if that is the coarser of the two. Algorithm tries to obtain an accuracy of abs(i-result) <= max(epsabs, epsrel*abs(i)) where i = integral of fun over interval, and result is the numerical approximation.

  • max_ninter (int, optional) – An upper bound on the number of sub-intervals used in the adaptive algorithm.

  • extrapolate (bool, optional) – Whether to accelerate convergence by applying Wynn’s epsilon algorithm to the sequence of running totals, on by default. Not needed for smooth integrands on finite domains, but can help significantly if there are algebraic singularities or infinite intervals. The additional cost is small and constant, so it is only worth switching off for a very cheap integrand where performance is critical.

  • adjoint (AbstractAdjoint, optional) – How to compute derivatives of the quadrature. Default is DirectAdjoint(), which gives the exact derivative of the discretized problem, and is the cheaper option for a cheap integrand. LeibnizAdjoint gives the derivative its own error control (ie, can better approximate the true continuous derivative), and is faster when the integrand is expensive or max_ninter is generous; see Adjoints for when that is worth paying for.

  • throw (bool, optional) – Whether to raise an error if the routine does not converge. If True, a run that terminates for any reason other than reaching the requested tolerance raises with the message its status carries. If False, the default, that status is reported on the returned info and left to the caller to act on.

  • kwargs (dict) – Additional keyword arguments passed to rule.

Returns:

  • y (float, Array) – The integral of fun from a to b.

  • info (QuadratureInfo) – Named tuple with the following fields:

    • err : (float) Estimate of the error in the approximation.

    • neval : (int) Total number of rule evaluations.

    • status : (int) Code for why the routine terminated, one of quadax.STATUS. STATUS.normal (0) means the requested tolerances were reached; every other code names a difficulty, whose message is print(quadax.STATUS[status]). Where a run meets more than one condition the most severe is reported.

    • info : (dict or None) Other information returned by the algorithm. Only present if full_output is True. Contains the following:

      • ’ninter’ : (int) The number, K, of sub-intervals produced in the subdivision process.

      • ’a_arr’ : (ndarray) rank-1 array of length max_ninter, the first K elements of which are the left end points of the (remapped) sub-intervals in the partition of the integration range.

      • ’b_arr’ : (ndarray) rank-1 array of length max_ninter, the first K elements of which are the right end points of the (remapped) sub-intervals.

      • ’r_arr’ : (ndarray) rank-1 array of length max_ninter, the first K elements of which are the integral approximations on the sub-intervals.

      • ’e_arr’ : (ndarray) rank-1 array of length max_ninter, the first K elements of which are the moduli of the absolute error estimates on the sub-intervals.