Quadpy
:triangular_ruler: Numerical integration (quadrature, cubature) in Python
Install / Use
/learn @sigma-py/QuadpyREADME
More than 1500 numerical integration schemes for line segments, circles, disks, triangles, quadrilaterals, spheres, balls, tetrahedra, hexahedra, wedges, pyramids, n-spheres, n-balls, n-cubes, n-simplices, the 1D half-space with weight functions exp(-r), the 2D space with weight functions exp(-r), the 3D space with weight functions exp(-r), the nD space with weight functions exp(-r), the 1D space with weight functions exp(-r<sup>2</sup>), the 2D space with weight functions exp(-r<sup>2</sup>), the 3D space with weight functions exp(-r<sup>2</sup>), and the nD space with weight functions exp(-r<sup>2</sup>), for fast integration of real-, complex-, and vector-valued functions.
Installation
Install quadpy from PyPI with
pip install quadpy
See here on how to get a license.
Using quadpy
Quadpy provides integration schemes for many different 1D, 2D, even nD domains.
To start off easy: If you'd numerically integrate any function over any given 1D interval, do
import numpy as np
import quadpy
def f(x):
return np.sin(x) - x
val, err = quadpy.quad(f, 0.0, 6.0)
This is like scipy with the addition that quadpy handles complex-, vector-, matrix-valued integrands, and "intervals" in spaces of arbitrary dimension.
To integrate over a triangle, do
import numpy as np
import quadpy
def f(x):
return np.sin(x[0]) * np.sin(x[1])
triangle = np.array([[0.0, 0.0], [1.0, 0.0], [0.7, 0.5]])
# get a "good" scheme of degree 10
scheme = quadpy.t2.get_good_scheme(10)
val = scheme.integrate(f, triangle)
Most domains have get_good_scheme(degree). If you would like to use a
particular scheme, you can pick one from the dictionary quadpy.t2.schemes.
All schemes have
<!--pytest.mark.skip-->scheme.points
scheme.weights
scheme.degree
scheme.source
scheme.test_tolerance
scheme.show()
scheme.integrate(
# ...
)
and many have
<!--pytest.mark.skip-->scheme.points_symbolic
scheme.weights_symbolic
You can explore schemes on the command line with, e.g.,
quadpy info s2 rabinowitz_richter_3
<quadrature scheme for S2>
name: Rabinowitz-Richter 2
source: Perfectly Symmetric Two-Dimensional Integration Formulas with Minimal Numbers of Points
Philip Rabinowitz, Nira Richter
Mathematics of Computation, vol. 23, no. 108, pp. 765-779, 1969
https://doi.org/10.1090/S0025-5718-1969-0258281-4
degree: 9
num points/weights: 21
max/min weight ratio: 7.632e+01
test tolerance: 9.417e-15
point position: outside
all weights positive: True
Also try quadpy show!
quadpy is fully vectorized, so if you like to compute the integral of a function on many
domains at once, you can provide them all in one integrate() call, e.g.,
# shape (3, 5, 2), i.e., (corners, num_triangles, xy_coords)
triangles = np.stack(
[
[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]],
[[1.2, 0.6], [1.3, 0.7], [1.4, 0.8]],
[[26.0, 31.0], [24.0, 27.0], [33.0, 28]],
[[0.1, 0.3], [0.4, 0.4], [0.7, 0.1]],
[[8.6, 6.0], [9.4, 5.6], [7.5, 7.4]],
],
axis=-2,
)
The same goes for functions with vectorized output, e.g.,
def f(x):
return [np.sin(x[0]), np.sin(x[1])]
More examples under test/examples_test.py.
Read more about the dimensionality of the input/output arrays in the wiki.
Advanced topics:
Schemes
Line segment (C<sub>1</sub>)
<img src="https://raw.githubusercontent.com/sigma-py/quadpy/main/plots/line-segment-gauss-legendre-20.svg" width="50%">- Chebyshev-Gauss (type 1 and 2, arbitrary degree)
- Clenshaw-Curtis (arbitrary degree)
- Fejér (type 1 and 2, arbitrary degree)
- Gauss-Jacobi (arbitrary degree)
- Gauss-Legendre (arbitrary degree)
- Gauss-Lobatto (arbitrary degree)
- Gauss-Kronrod (arbitrary degree)
- Gauss-Patterson (9 nested schemes up to degree 767)
- Gauss-Radau (arbitrary degree)
- Newton-Cotes (open and closed, arbitrary degree)
See here for how to generate Gauss formulas for your own weight functions.
Example:
import numpy as np
import quadpy
scheme = quadpy.c1.gauss_patterson(5)
scheme.show()
val = scheme.integrate(lambda x: np.exp(x), [0.0, 1.0])
1D half-space with weight function exp(-r) (E<sub>1</sub><sup>r</sup>)
<img src="https://raw.githubusercontent.com/sigma-py/quadpy/main/plots/e1r-gauss-laguerre-3.svg" width="50%">Example:
import quadpy
scheme = quadpy.e1r.gauss_laguerre(5, alpha=0)
scheme.show()
val = scheme.integrate(lambda x: x**2)
1D space with weight function exp(-r<sup>2</sup>) (E<sub>1</sub><sup>r<sup>2</sup></sup>)
<img src="https://raw.githubusercontent.com/sigma-py/quadpy/main/plots/e1r2-gauss-hermite-8.svg" width="50%">- Gauss-Hermite (arbitrary degree)
- Genz-Keister (1996, 8 nested schemes up to degree 67)
Example:
import quadpy
scheme = quadpy.e1r2.gauss_hermite(5)
scheme.show()
val = scheme.integrate(lambda x: x**2)
Circle (U<sub>2</sub>)
<img src="https://raw.githubusercontent.com/sigma-py/quadpy/main/plots/circle-krylov-30.svg" width="25%">- Krylov (1959, arbitrary degree)
Example:
import numpy as np
import quadpy
scheme = quadpy.u2.get_good_scheme(7)
scheme.show()
val = scheme.integrate(lambda x: np.exp(x[0]), [0.0, 0.0], 1.0)
Triangle (T<sub>2</sub>)
<img src="https://raw.githubusercontent.com/sigma-py/quadpy/main/plots/triangle-dunavant-15.svg" width="25%">Apart from the classical centroid, vertex, and seven-point schemes we have
- Hammer-Marlowe-Stroud (1956, 5 schemes up to degree 5)
- Albrecht-Collatz (1958, degree 3)
- Stroud (1971, conical product scheme of degree 7)
- Franke (1971, 2 schemes of degree 7)
- Strang-Fix/Cowper (1973, 10 schemes up to degree 7),
- Lyness-Jespersen (1975, 21 schemes up to degree 11, two of which are used in TRIEX),
- Lether (1976, degree 2n-2, arbitrary n, not symmetric),
- Hillion (1977, 10 schemes up to degree 3),
- Laursen-Gellert (1978, 17 schemes up to degree 10),
- CUBTRI (Laurie, 1982, degree 8),
- Dunavant (1985, 20 schemes up to degree 20),
- Cools-Haegemans (1987, degrees 8 and 11),
- Gatermann (1988, degree 7)
- Berntsen-Espelid (1990, 4 schemes of degree 13, the first one being DCUTRI),
- Liu-Vinokur (1998, 13 schemes up to degree 5),
- Griener-Schmid, (1999, 2 schemes of degree 6),
- Walkington (2000, 5 schemes up to degree 5),
- Wandzura-Xiao (2003, 6 schemes up to degree 30),
- Taylor-Wingate-Bos (2005, 5 schemes up to degree 14),
- Zhang-Cui-Liu (2009, 3 schemes up to degree 20),
- Xiao-Gimbutas (2010, 50 schemes up to degree 50),
- Vioreanu-Rokhlin (2014, 20 sche
Security Score
Audited on Feb 5, 2026
