Repository navigation
torchquad 0.7.0
Three new samplers for Monte Carlo integration, grid rules that take a different
number of points along each dimension, and a round of fixes found by testing on
real GPUs — among them gradients through GaussLegendre, which were broken for
most smooth integrands.
Highlights
- Three more samplers for
MonteCarlo—Halton,Latticeand
RandomizedLatinHypercubejoinSoboland are passed the same way, as
rng=....Haltonplaces no constraint onN;Latticewithtent=True
matched or beat Sobol on the tutorial's smooth 3-D integrand; the Latin
hypercube removes most of the variance of near-additive integrands. See
Quasi-Monte Carlo in the tutorial. (#140) - Per-dimension grid sizes —
Trapezoid,Simpson,Booleand
GaussLegendreacceptN=(n_0, n_1, ...), inintegrateand in
get_jit_compiled_integrate. On an integrand that varies quickly along one
axis only,N=(201, 5)reached an error of 1.7e-08 where an even 31 x 31 grid
of the same size reached 3.6e-05. (#123) - Autograd through
GaussLegendreworks — the quadrature weights were
applied in place to the tensor the integrand returned, which broke
backpropagation for any integrand ending inexp,sqrt,tanh,sigmoid,
a division or a power. Present since 0.4.0. - Logging you can actually control —
set_log_level()and
TORCHQUAD_LOG_LEVELnow limit what is printed: nothing below the level, each
record once, and nothing at all from TensorFlow's compiled path while logging
is off. torch_enable_cuda=Falseis honoured —set_up_backend("torch", ..., torch_enable_cuda=False)no longer moves the default device to CUDA just
because something else in the process had used the GPU.
Numerical behaviour
Results are unchanged for floating-point and complex integrands with a
scalar N and a given seed, and no existing test tolerance was loosened. Seeded
streams of RNG(..., torch_save_state=True) are bit-identical to 0.6.0 on the
CPU and on CUDA.
These cases now return different, corrected values:
- Boolean integrands in the Newton-Cotes rules.
Trapezoidreturned 0.5 instead
of 1.0 for an all-true mask. - Integer and Boolean integrands in NumPy Monte Carlo. A constant 1 over
[0, 0.5]returned0. - An integrand that returns
float32underfloat64precision with Gaussian
quadrature now yields afloat64result, with a warning, instead of
discarding the weights' precision. Sobolinfloat32on the NumPy, JAX and TensorFlow backends could return a
point exactly equal to 1. All samplers now stay strictly below 1; every other
point is unchanged.
Known limitation: VEGAS does not reproduce bit for bit for a fixed seed on a
CUDA device, although it does on the CPU (#278). This predates 0.7.0.
Breaking changes / deprecations
- Python 3.11 or newer is required; NumPy
>=1.23.2and SciPy>=1.9.2.
pip keeps serving 0.6.0 to Python 3.10. set_precision()raises aValueErrorfor a data type other than
float32orfloat64and for an unknown backend. It used to print an error
and fall back tofloat32.set_precision()no longer changes PyTorch's default device. Use
enable_cuda()orset_up_backend("torch", ...), which behave as before.set_log_level()no longer adds a handler of its own. Records go to your
application's loguru handlers, so theTQ-prefixed format is gone. In a
plain interpreter they appear through loguru's default stderr handler.
Installation
pip install torchquad==0.7.0
uv add torchquad==0.7.0
conda install torchquad -c conda-forgeThanks
Thanks to everyone who contributed to this release.
Full changelog
Full changelog: v0.6.0...v0.7.0
See CHANGELOG.md
for the complete list.