Differentiable Bloch-Wave Electron Diffraction with faster-diffbloch
Published: August 10, 2026 · Read Time: 5 min read · Category: Scientific Computing
Author: Quilio Research (Signal Processing & Computing Group)
Accelerating dynamical electron scattering simulations with Metal GPU shaders and optimized CPU kernels, outperforming PyTorch by up to 1.80x.
Dynamical Electron Scattering
Bloch-wave formulations compute electron beam scattering through crystalline structures by solving matrix eigenvalue problems. Simulating large numbers of diffraction beams requires repeated diagonalizations and matrix exponentials.
Standard implementations rely on high-level Python libraries such as PyTorch. While functional, framework overhead and generic tensor allocations limit compute density during parameter optimization loops.
Metal Acceleration Pipeline
faster-diffbloch is open source and available on PyPI. It exposes a direct Python interface backed by dedicated Metal and CPU SIMD kernels, allowing automated orientation refinement.
import faster_diffbloch as fdb
# Initialize simulator with Metal GPU backend
sim = fdb.BlochSimulator(backend="metal", max_beams=579)
# Forward dynamical scattering calculation
pattern = sim.compute_diffraction(
crystal_cif="silicon.cif",
zone_axis=[1, 1, 0],
voltage_kv=200.0,
thickness_nm=45.0
)
print(f"Computed {pattern.num_beams} beam intensities in {pattern.elapsed_ms:.2f} ms")
Benchmark Comparisons
Performance was measured on an Apple M4 Max across forward and backward simulation passes. The test suite evaluates diffraction patterns across 31 to 579 simultaneous beam configurations.
| Beam Count | PyTorch (Metal backend) | faster-diffbloch (Custom Metal) | Speedup Factor |
|---|---|---|---|
| 31 beams | 14.2 ms | 10.1 ms | 1.41x faster |
| 117 beams | 42.8 ms | 27.4 ms | 1.56x faster |
| 325 beams | 118.5 ms | 71.8 ms | 1.65x faster |
| 579 beams | 312.0 ms | 173.3 ms | 1.80x faster |
Gradient Backward Pass
Differentiable simulation requires accurate adjoint state calculations for crystal orientation and thickness parameters. Custom backward kernels compute matrix derivatives in a single memory pass, eliminating redundant state storage.