Skip to main content

Fast numerical inverse Laplace transforms: GWR (arbitrary precision) + Fixed Talbot, with optional Rust/MPFR acceleration

Project description

ilt-inversion

Numerical inverse Laplace transforms for Python.

Why?

If you've ever needed to numerically invert a Laplace transform in Python, you've probably discovered that the standard tools either don't exist or fall over quietly when things get difficult.

NumPy and SciPy don't have one. There's no numpy.inverse_laplace or scipy.special.ilt. The standard scientific Python stack just doesn't cover this.

SymPy tries, but it's symbolic. inverse_laplace_transform attempts to find a closed-form f(t) via pattern matching and table lookups. That works for textbook problems - rational functions, simple exponentials - but hand it a Bessel-function ratio or anything defined by a numerical subroutine and it silently returns an unevaluated integral. You can't pass it a Python function that calls a numerical solver.

mpmath has invertlaplace, and it's actually decent. Three methods: de Hoog, Fixed Talbot, and Stehfest. But mpmath doesn't implement GWR, and its de Hoog and Talbot methods evaluate F(s) at complex values of s. That's a problem when your F(s) only works on the real axis - common in reservoir engineering where you're dealing with real-valued Bessel function ratios or feeding in results from a numerical ODE solver. GWR only needs F(s) at real, positive points.

Stehfest is the one everyone implements first, because it's simple and works at f64 precision. Handles smooth, monotonic transforms fine, but give it anything oscillatory or steep and it falls apart. The fixed-precision coefficients hit catastrophic cancellation at higher orders, capping you at ~6-8 significant figures no matter how many terms you throw at it.

David Fulford's gwr_inversion is the package that got this right in Python. It implements GWR with arbitrary precision via mpmath and optional gmpy2 acceleration (~10x speedup) - a clean, correct implementation that made GWR accessible to the Python community. For most general-purpose ILT work, gwr_inversion is all you need and this library owes a debt to it.

Where this library adds value

For straightforward gwr(my_function, times) calls, this library's Python path is essentially the same algorithm as Fulford's, with the same gmpy2 acceleration option. If that's your use case, either package will serve you well.

The differences show up in two specific areas:

Bulk inversion with simple callables. When M is small enough that f64 precision suffices (M <= 7, covering ~15 significant figures), the Rust/MPFR backend bypasses Python entirely and runs the full GWR algorithm in compiled code. That's a ~15x speedup per call, which adds up if you're inverting across large parameter sweeps or Monte Carlo runs. For higher M, the Rust path can't help with a general Python callable (the f64 boundary at the Python-Rust interface becomes the bottleneck), and the Python path with gmpy2 is the right choice - same as Fulford's package.

Bessel-function Laplace domains at full MPFR precision. For Laplace-domain functions built from modified Bessel functions (pressure transient analysis, radial diffusion, heat conduction), the library includes MPFR-precision implementations of I_0, I_1, K_0, K_1 with numerical safeguards that matter when you're evaluating these functions across a wide range of arguments:

  • Dynamic guard bits on the K_0 power series to compensate for catastrophic cancellation between the -(ln(x/2) + gamma) * I_0(x) term and the harmonic series. At x = 20, that's ~18 digits of cancellation that silently corrupts the result if you compute at working precision.
  • Exponentially-scaled forms (I_ne(x) = I_n(x) * exp(-x), K_ne(x) = K_n(x) * exp(x)) that stay O(1) for all x, avoiding the overflow/underflow that hits f64 past x > 700.
  • Optimal truncation of asymptotic expansions for large arguments, switching from the power series at x = 25.

When the Laplace-domain function is implemented entirely in Rust using these Bessel functions (as it is for the Van Everdingen-Hurst radial flow solution in pyResToolbox), the full pipeline - Bessel evaluation, GWR coefficients, Wynn-rho acceleration - runs in compiled MPFR precision without crossing the Python boundary. That's where the ~70x number comes from.

How GWR works

GWR (Valko & Abate, 2004) is a three-stage process. Evaluate F(s) at 2M points along the real axis and combine with pre-computed factorial/binomial coefficients (the Gaver functionals). Apply Wynn-rho sequence acceleration to improve convergence. Extract the best estimate from odd levels of the acceleration tableau.

The factorial coefficients grow as (2M)! and the alternating sums produce catastrophic cancellation. With M=32, the coefficients reach ~10^67 while the result is O(1) - so you need at least 67 decimal digits of working precision, or the answer is pure noise. Standard f64 gives you 15.9 digits. Even quad precision only gets you 33.

The library automatically computes ceil(2.1 * M) decimal digits of working precision to guarantee enough significant figures survive.

Performance tiers

The library picks the fastest backend that will give correct results:

Tier Backend Speedup When used
1 Rust/MPFR ~15-70x M <= 7 (general callables) or internal Bessel evaluation (any M)
2 gmpy2 ~10x M > 7 with general Python callables
3 mpmath baseline Always available

The gmpy2 tier is the same acceleration that Fulford's gwr_inversion already provides - we inherited that design. The Rust/MPFR tier is what's new.

Installation

pip install ilt-inversion

Binary wheels include the Rust/MPFR extension for Linux, macOS, and Windows. If no binary wheel is available for your platform, the pure-Python fallback installs automatically and the Rust acceleration is simply absent.

Optional accelerators for the Python path:

pip install gmpy2         # ~10x faster GWR for high-M
pip install python-flint  # ~15x faster Bessel functions via ARB

Quick start

from ilt import gwr, talbot

# L{e^(-t)} = 1/(s+1)
def F(s):
    return 1 / (s + 1)

# Single time point
result = gwr(F, 1.0)           # 0.36787944... = e^(-1)

# Multiple time points
results = gwr(F, [0.1, 1.0, 10.0])

# Higher accuracy
results = gwr(F, [1.0], M=64)

# Fixed Talbot - faster for well-behaved transforms
result = talbot(F, 1.0)

# Parallel evaluation (fn must be picklable - module-level, not a lambda)
results = gwr(F, times, workers=4)

API

gwr(fn, time, M=32, precin=None, backend='auto', workers=1, as_float=True)

Inverse Laplace transform via Gaver-Wynn-Rho. fn is your Laplace-domain function F(s) or F(s, prec). time accepts a scalar, list, or numpy array (must be > 0). M controls accuracy - 6-12 for smooth transforms, 32 for general use, 768+ for hard oscillatory cases. precin overrides the automatic precision (round(2.1 * M) decimal digits). backend can be 'auto', 'rust', 'gmpy2', or 'mpmath'. workers sets the number of parallel processes for array inputs (default 1 = sequential) - each time point is inverted independently, so this parallelises well, but fn must be picklable (a module-level function, not a lambda or closure). Set as_float=False to get mpmath.mpf values at full precision.

talbot(fn, time, degree=32, as_float=True)

Inverse Laplace transform via Fixed Talbot. Good for well-behaved, non-oscillatory transforms where moderate precision suffices.

besselk(n, x) / besseli(n, x)

Modified Bessel functions K_n(x) and I_n(x) with automatic python-flint/ARB acceleration when available.

Acknowledgements

The GWR algorithm implementation builds on David S. Fulford's gwr_inversion package, which made a clean and correct GWR available to the Python community.

References

  • Valko, P.P. & Abate, J. (2004), "Comparison of Sequence Accelerators for the Gaver Method of Numerical Laplace Transform Inversion", Computers and Mathematics with Applications 48(3): 629-636.
  • Abramowitz, M. & Stegun, I.A. (1964), Handbook of Mathematical Functions, National Bureau of Standards.
  • Van Everdingen, A.F. & Hurst, W. (1949), "The Application of the Laplace Transformation to Flow Problems in Reservoirs", SPE-949305-G.

Licence

GPL-3.0-or-later

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ilt_inversion-0.1.2.tar.gz (31.7 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ilt_inversion-0.1.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

ilt_inversion-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (403.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

ilt_inversion-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (318.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ilt_inversion-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (403.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ilt_inversion-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (318.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ilt_inversion-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (404.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ilt_inversion-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (318.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ilt_inversion-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (405.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

ilt_inversion-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (318.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file ilt_inversion-0.1.2.tar.gz.

File metadata

  • Download URL: ilt_inversion-0.1.2.tar.gz
  • Upload date:
  • Size: 31.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ilt_inversion-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1df91f0b91e97aced9f3e9d77503e403ca51c5acc822663b119fdae1a09e6b06
MD5 ce20ad0e06032a54e277807c21de2b63
BLAKE2b-256 5ada43b0adfd557df11c8242cccbab70dd04ed419d12087caf7fd144971f7c7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2.tar.gz:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ilt_inversion-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ilt_inversion-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 331fd6db7ec407b792078b5b465626b6a4a64c58c67a37dfce015e42b909e4e2
MD5 0087cb49011afd470d7835a7c4acdb4a
BLAKE2b-256 21ab1797ea28e5cb40650d03d5df735ade59f78eea8d307ef05e68a13a8c1702

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-py3-none-any.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 620f7f4246d4995359c8964299415452acb8f8749147691d26c59d2c70bdbc8d
MD5 4c347df4411aec9029e4e34ded1fa424
BLAKE2b-256 dc920e1ff91019594a8cc25931c46db1ba835161e6164a39974baf172a1d26d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a582a0cf62ab5e96b82dc4c9931ba35a0c9a16dd787df9dd812f0b3aaa1c1ed9
MD5 5cf7eb3b0e217ccf91d25a44fca8c86f
BLAKE2b-256 c20719db88d8774883410a76ad04a18b607a1c9555b7946d1ab75c694510c3f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f698b6645f8b2b95d18598f4d7a297d0024ccfe7b5f5d8a50f4b0f057b75d6e7
MD5 ce2d72b5a4cbe3e40f2c46b336c20e62
BLAKE2b-256 3eb2f734e0a7805bdaa28ae0cdca37056c78f26d7fb66d055a7eb51b5b21514e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0bf204c40539008fffcf651fac9bd38801bedecc5792103f3b6eea272248f436
MD5 0dc2f215d601848545e91bc4529cb51b
BLAKE2b-256 6a605a72798ad9c7f83d2b5c2557dce52afb0dd492c1d535f6157c3e7a4beeff

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 52c70fba9cde5b2ae6dc13b3b813f17d8c723e2fe171cea39a9c91116fc50cd3
MD5 435d82b7b677758ebb04f0cc52e6ea81
BLAKE2b-256 4f4d6e7ca5cdcd85963c73b1d03593d4332f42c7345c86314815245fbb6af7a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be92d40e0ceaedc267be1139da8f292c0794fe7c3fc2b0059d13d4f9c20816a9
MD5 5fa49b2acf3c69b9cc6e9e99e450d235
BLAKE2b-256 4812f78be3fd2d319c6252fd52e55a48d92ba0d710812154acdbe4a35a4e6b5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2482be0cf987fdfe7a6c4d8c230e03105a4ef689b1d455eb404e19dbd3deb45a
MD5 08b0d05e149f718055c1a428501cfe09
BLAKE2b-256 bec65e6779c8cae02ea32721e2fc62bbd916ebf2ac07615f971bfc3c2803c67c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ilt_inversion-0.1.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8b19566948d7e409cb2065e70183dc1ad4d65a3e7364a315191898bcc88a3729
MD5 065364fb3c7c9c0643d674c2ea7d93d2
BLAKE2b-256 4af56480cff87bfe3b9278cf250434bf7193eabff0bf4201e10e5c81979bd5e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build-wheels.yml on mwburgoyne/ilt-inversion

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page