Skip to content

torchquad v0.7.0

Latest

Choose a tag to compare

@gomezzz gomezzz released this 12 Nov 12:36
54655c5

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, Lattice and
    RandomizedLatinHypercube join Sobol and are passed the same way, as
    rng=.... Halton places no constraint on N; Lattice with tent=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, Boole and
    GaussLegendre accept N=(n_0, n_1, ...), in integrate and 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 GaussLegendre works — the quadrature weights were
    applied in place to the tensor the integrand returned, which broke
    backpropagation for any integrand ending in exp, sqrt, tanh, sigmoid,
    a division or a power. Present since 0.4.0.
  • Logging you can actually control — set_log_level() and
    TORCHQUAD_LOG_LEVEL now 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=False is 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. Trapezoid returned 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] returned 0.
  • An integrand that returns float32 under float64 precision with Gaussian
    quadrature now yields a float64 result, with a warning, instead of
    discarding the weights' precision.
  • Sobol in float32 on 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.2 and SciPy >=1.9.2.
    pip keeps serving 0.6.0 to Python 3.10.
  • set_precision() raises a ValueError for a data type other than
    float32 or float64 and for an unknown backend. It used to print an error
    and fall back to float32.
  • set_precision() no longer changes PyTorch's default device. Use
    enable_cuda() or set_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 the TQ- 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-forge

Thanks

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.