faster-diffbloch
Drop-in Apple Silicon Metal GPU and optimized CPU acceleration for diffBloch electron crystallography structure refinement.
Up to 1.80× faster than PyTorch CPU in measured end-to-end forward-plus-backward benchmarks, with a Metal GPU path for Apple Silicon and an optimized CPU path for macOS and Linux.
| Package | Documentation | Source repository | Original project |
|---|---|---|---|
| PyPI · piwheels | diffFlow documentation and benchmarks | github.com/godofecht/diffFlow | diffbloch.com |
Operating System and Platform Support
| Operating System / Hardware | CPU Acceleration (device="cpu") |
GPU Acceleration (device="gpu") |
Backend Runtime |
|---|---|---|---|
| macOS Apple Silicon (M1/M2/M3/M4/Max/Ultra) | Supported | Supported | Native Metal Compute Shaders + Apple Accelerate BLAS |
| macOS Intel (x86_64) | Supported | Fallback to CPU | Apple Accelerate BLAS |
| Linux (x86_64 / aarch64) | Supported | Fallback to CPU | OpenBLAS / C11 BLAS |
| Windows | PyTorch Reference | PyTorch Reference | Pure PyTorch Reference Fallback |
Runtime platform guards automatically detect your operating system and hardware configuration. When device="gpu" is requested on Linux, faster-diffbloch automatically selects the optimized CPU backend with an informative warning.
Why faster-diffBloch?
faster-diffbloch keeps the diffBloch workflow and public API intact while moving
the expensive propagation and gradient work onto an accelerated native backend.
You get the same scientific calculation, with a faster path on supported hardware
and a safe PyTorch fallback when the native backend is unavailable.
The package is validated against the diffBloch test suite and reference results. It passes all 738 diffBloch tests, 55 additional conformance tests, and reproduces the experimental quartz refinement result.
Performance
End-to-end forward-plus-backward timing on an Apple M4 Max, measured across the same diffBloch workload at different beam counts:
| Beams | faster-diffBloch | PyTorch | Speedup |
|---|---|---|---|
| 31 | 0.90 ms | 1.62 ms | 1.80× |
| 61 | 1.37 ms | 2.24 ms | 1.63× |
| 91 | 2.84 ms | 3.99 ms | 1.41× |
| 163 | 7.67 ms | 10.98 ms | 1.43× |
| 579 | 89.81 ms | 135.77 ms | 1.51× |
That is 1.41×–1.80× faster than PyTorch CPU across the measured cases, including the largest 579-beam case. The same benchmark is 1.21× faster than the Mojo reference at 31 beams, remains ahead through 163 beams, and is essentially level at 579 beams.
On Apple Silicon, the Metal GPU path is also available. In the package's M4 Max comparison run at 579 beams, it measured 2.24× faster than PyTorch CPU for the forward pass and 2.63× faster than PyTorch MPS for forward plus backward.
These figures are workload benchmarks, not a promise that every crystal, hardware configuration, or beam count will see the same result. The CPU table uses single-threaded PyTorch and the same Apple Accelerate environment for a like-for-like comparison.
Package benchmark snapshot
| Implementation | Forward | Forward + Backward | Speedup vs PyTorch CPU | Speedup vs PyTorch MPS |
|---|---|---|---|---|
| PyTorch CPU | 25.7 ms | 130.3 ms | 1.00x | 1.17x |
| PyTorch MPS (fallback) | 26.2 ms | 153.0 ms | 0.85x | 1.00x |
| faster-diffBloch CPU | 24.4 ms | 83.5 ms | 1.56x | 1.83x |
| faster-diffBloch Metal GPU | 13.1 ms | 58.1 ms | 2.24x | 2.63x |
Installation
pip install faster-diffbloch
Usage
1. Drop-in CLI
Use diffbloch-fast or faster-diffbloch anywhere you would use diffbloch:
diffbloch-fast infer examples/Colmey_et_al_2026/data/quartz-no-abs
diffbloch-fast refine examples/Colmey_et_al_2026/data/quartz-no-abs
2. Python API Injection
Enable acceleration inside any existing diffBloch script:
import faster_diffbloch
# Enable Metal GPU acceleration (macOS Apple Silicon)
faster_diffbloch.enable(device="gpu")
# Or CPU acceleration (macOS and Linux)
faster_diffbloch.enable(device="cpu")
# Run standard diffBloch code
import diffBloch
# All propagate and matrix_exp calls now route through faster-diffBloch
Metadata
Release files for faster-diffbloch 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| faster_diffbloch-0.1.2.tar.gz | 24.0 kB | Without provenance | Details for faster_diffbloch-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| faster_diffbloch-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for faster_diffbloch-0.1.2-py3-none-any.whl |
Total release size: 52.1 kB
Release files / faster_diffbloch-0.1.2.tar.gz
| Download URL | faster_diffbloch-0.1.2.tar.gz |
|---|---|
| Size | 24.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
924be3f42cb18a78936550bbad3499b2e640d6588585485a01e82e9f8edd1214
|
|
BLAKE2b-256 checksum How to use checksums |
0b1487399e856432a4989ab79b71c033699aee09de7e6d2129159aaeba32ffe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / faster_diffbloch-0.1.2-py3-none-any.whl
| Download URL | faster_diffbloch-0.1.2-py3-none-any.whl |
|---|---|
| Size | 28.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67c04de5e03f66d1ab7841f555f1d6e60871d24e5c53edcaf19070193695824e
|
|
BLAKE2b-256 checksum How to use checksums |
dc32d8fcd83733bdbdcfbad97b358be0046df1f75bca90d3d2a562055447d9ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for faster-diffbloch 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.