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.4.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.4-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

ilt_inversion-0.1.4-cp313-cp313-win_amd64.whl (422.7 kB view details)

Uploaded CPython 3.13Windows x86-64

ilt_inversion-0.1.4-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.4-cp313-cp313-macosx_11_0_arm64.whl (318.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ilt_inversion-0.1.4-cp312-cp312-win_amd64.whl (422.7 kB view details)

Uploaded CPython 3.12Windows x86-64

ilt_inversion-0.1.4-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.4-cp312-cp312-macosx_11_0_arm64.whl (318.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ilt_inversion-0.1.4-cp311-cp311-win_amd64.whl (424.0 kB view details)

Uploaded CPython 3.11Windows x86-64

ilt_inversion-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (404.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

ilt_inversion-0.1.4-cp310-cp310-win_amd64.whl (424.1 kB view details)

Uploaded CPython 3.10Windows x86-64

ilt_inversion-0.1.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: ilt_inversion-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 4995f10ab222f5ad2b5a409c9f6888fa0e6239b60c00348168e9c85044de39f7
MD5 b2c0497f79cdbc85529f87eafc86bbd8
BLAKE2b-256 82affae5a9215a2a8db1fb713a93add2be180e7bbaaa53c21441e8dc8b3c8b0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: ilt_inversion-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f76aba4b4b426b81e77ef964a90fb4932c19895038705d63f5e66a067d1e358c
MD5 981d7c1be9caff530d99afe00294b5af
BLAKE2b-256 40053a48b00e875cd18eb2044541fbd3975bf4aa1ff5fc9ad67a4860fd2df774

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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.4-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4ad235fb89d50065a8d3e1faa785e305e3d85abc9c89af098a72a4a90a01cad1
MD5 9a6c5e640b0a9dec7063465189d505f8
BLAKE2b-256 c20ee669058ea9f7156e095aca48665daf2735f4a6d6d1a258d71602749dab3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-cp313-cp313-win_amd64.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.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6d69bf256c21ebdd43f2f26a728d281af37e413862e6de68263e49e24ef4360
MD5 35365d2cca1cae12230fcdbb04e2692c
BLAKE2b-256 21bcf7d63158947084f90547e333f5819d3100711a339a91b8e7bd56b87304d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b99d40a90390d9961790a46d5fbe90f5005f5ccb0e72b788af091e1170a0bd8
MD5 074555a2c171fa1ab5b0900ac999bfb3
BLAKE2b-256 4f179f26185c1ee3c146ac19e59dcd6edccb645ba57f98f4c7fd9f2638ef11db

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3ac8f912f53c2a0d2e5569d72dfcf095179f32e475e03ec0aaa93dd771c704f6
MD5 f25a647253f76e45a74fd4d7ff319b48
BLAKE2b-256 3b0dccd8bfafe8fe15c36c040db6f1baee2fdbe5b80a9e5c16ffca9dada5db49

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-cp312-cp312-win_amd64.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.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a51ee98c23cc988ed85ac5b0df4e353a2b494b9914c389394f7d2aea0f7802b4
MD5 c05a94742a671e2df2d220bb280bc8ce
BLAKE2b-256 1eac33bdf91d257a3c51f64d1d6d67a18ff113508019f1116245069fbb6f0cea

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 174f75a7bfa4169eb0129e544160d3cda9cb79a13cc874f0846e358e683e4dea
MD5 6ecd41188bccea7b960c2347fb609bd6
BLAKE2b-256 2d551dbb0842126e29ae229f90b5f6cd62d07cf33a48031ed49a36eabe57de37

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 492ec89d822d7a6d4070de8a799c941d1243a5cdec85b58a955e747efb5424a2
MD5 73062f3268845367c538604c92822e4f
BLAKE2b-256 be52db4dec2779e998411ea877753a30f2ea1256146b4de7bd8c72f1c8a866d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-cp311-cp311-win_amd64.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.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aecb421cec2490a7e5660568b249615970880187b43e8aa78c7a0a66ff62124b
MD5 9f8bffa3c4819f583c9d2fa022e502da
BLAKE2b-256 1e563ac31d1548f42ba997e3e8d1ae69298610eefdddaa586169b3f8d48e05dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd4fcaf4b9a53f8768c1105899d15eb70a8049ce061e499001d353fa62a55e1a
MD5 3c4c3acef29a19f4a6e9de37dce00e4f
BLAKE2b-256 0a5f74a9dcc09718b84b9a852164a63b55e759ca343847c4c4faed615cc0b700

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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.4-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0bbd11a272535b5e9de1529f9bf6c77b391812317af2b7027396936c4a614ccd
MD5 03bcd7bed0f155e2f4bc61947a37be05
BLAKE2b-256 c0b874dbb3cf74b0568e2c0cc355c4896f056bf69243b14082f73f555ec55d77

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-cp310-cp310-win_amd64.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.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42f49da63ab0052440e7ecde08b108a34c5f857e2220f1753f40925535a9d751
MD5 131af5dff0bbe7bb73b13b9bcca77ebb
BLAKE2b-256 7eb65b5d2180f7c50421963e313879ba69235068d9398441d242713253812579

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ilt_inversion-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42e3d477ef2a0f761654709b55cca4db2638237e42b3071e741e7c3c90e04d9d
MD5 7de7f407f89cd859f13ef2fa498c51a5
BLAKE2b-256 024b02e7680cc08c3e9d3d99d8327daa2636518c6cc6a453d904eae9db82b71e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ilt_inversion-0.1.4-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