Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mlx-sci

Quantum-information primitives + GPU special functions for Apple Silicon. Stochastic Lanczos QRE, Petz recovery, Wigner symbols, Bessel / hypergeometric / Airy / gamma, matrix-functions, STFT — all native on the Metal GPU through MLX.

mlx-sci speedups vs CPU baseline on M1 Max

Headline speedup of each module against its CPU baseline (NumPy / SciPy / sympy) on an Apple M1 Max. Each bar is the most representative single number per module — see each sub-package's benchmark_results.md for the full curve and break-even points.

mlx-sci is a meta-package that bundles a curated set of focused sub-packages — Airy, Bessel, Gamma, Hypergeometric, Wigner, matrix exponential, STFT, Fisher information, quantum relative entropy, and an optional statevector circuit simulator — under one consistent namespace (mlx_sci.quantum, mlx_sci.special, mlx_sci.linalg, mlx_sci.signal). Each sub-package is independently installable, so you can either pull the whole stack or pick à la carte.

Everything runs on the Apple GPU through MLX. There is no CUDA path, no host->device shuffling, and no framework dependency beyond MLX + NumPy.

Install

pip install mlx-sci # bundles all sub-packages
pip install "mlx-sci[sim]"# ... plus the optional circuit simulator# or pick à la carte
pip install mlx-airy mlx-bessel mlx-expm mlx-fisher mlx-gamma
pip install mlx-hyp2f1 mlx-qre mlx-stft mlx-wigner
pip install mlx-quantum-sim # optional, not on PyPI yet

Python >= 3.10, Apple Silicon (M1/M2/M3/M4), MLX >= 0.30.

Quick Start

importmlx.coreasmxfrommlx_sciimportquantum, special, linalg, signal# ── Quantum information ────────────────────────────────────────────# Quantum relative entropy via Stochastic Lanczos quadrature.# O(k * N^2) — beats the exact eigh path by ~2 orders at N >= 1000# and is the only path that completes at N = 2000 on the Metal GPU.rho=quantum.random_density_matrix(2000)
sigma=quantum.random_density_matrix(2000)
D_slq=quantum.quantum_relative_entropy_lanczos(rho, sigma, k=25, m=20)
# Exact eigh path is still available for small / batched inputsrho_s=quantum.random_density_matrix(256)
sigma_s=quantum.random_density_matrix(256)
D_exact=quantum.quantum_relative_entropy(rho_s, sigma_s)
# Petz recovery bound: F(rho, R o N(rho)) >= exp(-Sigma/2)ok=quantum.verify_petz_bound(kraus, rho_s, sigma_s) # noqa: F821# ── Special functions ──────────────────────────────────────────────# Wigner 3j — one million coupling coefficients in a single dispatchN=1_000_000j1=mx.ones(N); j2=mx.ones(N); j3=2*mx.ones(N)
m=mx.zeros(N)
w3j=special.wigner_3j(j1, j2, j3, m, m, m)
# Airy Ai/Bi over a real gridAi, Ai_p, Bi, Bi_p=special.airy(mx.linspace(-15.0, 15.0, 10_000))
# Gauss hypergeometric — auto-routes to a fused Metal kernel when |z|<0.5a=mx.array(0.5); b=mx.array(1.0); c=mx.array(1.5)
z=mx.linspace(0.01, 0.95, 1_000_000)
F=special.hyp2f1(a, b, c, z)
# Vectorised gamma / lgamma / digamma on GPUy=special.gamma(mx.linspace(0.1, 30.0, 1_000_000))
# ── Linear algebra ─────────────────────────────────────────────────# Matrix exponential (Pade-13 + scaling-squaring) on GPUH=mx.random.normal((1024, 1024))
U=linalg.expm(-1j*H*0.1)
# ── Signal processing ──────────────────────────────────────────────# Class-based STFT layer (mlx-stft 0.1.2 API)stft=signal.STFT(n_fft=1024, hop_length=256,
window=signal.hann_window(1024))
audio=mx.random.normal((480_000,)) # 30 s @ 16 kHzspec=stft(audio)

Modules at a glance

ModuleSource sub-packageScopeOne-liner
mlx_sci.special.airymlx-airyAiry Ai/Bi + derivativesAll four outputs in one call.
mlx_sci.special.gammamlx-gammagamma, lgamma, digamma, betaVectorised on GPU.
mlx_sci.special.hyp2f1mlx-hyp2f1Gauss 2F1, 1F1, 0F1Fused metal_kernel collapses ~200 MLX ops into 1 dispatch.
mlx_sci.special.BesselTablemlx-besselSpherical Bessel j_l(x), j_l'(x)Build once, evaluate over arbitrary x grids.
mlx_sci.special.wigner_*mlx-wignerWigner 3j / 6j / 9j, Clebsch-GordanRacah formula on GPU; millions per call.
mlx_sci.linalg.expmmlx-expmmatrix expm / logm / sqrtm / FrechetPade-13 + scaling-squaring on GPU.
mlx_sci.signal.STFTmlx-stftSTFT / ISTFT layers + windowsClass-based; CompiledSTFT for fixed-shape fusion.
mlx_sci.quantum.qremlx-qreD(rho || sigma), von Neumann entropyExact eigh + Stochastic Lanczos quadrature.
mlx_sci.quantum.petzmlx-qrePetz recovery map, fidelity, retrodictionF >= exp(-Sigma/2) verifier built in.
mlx_sci.quantum.channelsmlx-qreThermal / depolarizing / dephasing channelsIncluding the gravitational thermal_attenuator(eta).
mlx_sci.quantum.fishermlx-fisherFisher information matrix, natural-gradCosmology-scale J^T W J on GPU.
mlx_sci.quantum.sim(opt)mlx-quantum-simStatevector simulator, batched + noisyOptional extra (pip install mlx-sci[sim]). Ideal + WILLOW / HERON / T9 noise profiles.

Performance

All numbers below were measured on an Apple M1 Max, MLX 0.30-0.31, NumPy 2.x, SciPy 1.16. SciPy / NumPy reference is float64 on the CPU (Accelerate / LAPACK); MLX paths are float32 on the Apple GPU.

ModuleWhat it acceleratesHeadline speedup (M1 Max)Break-even
mlx_sci.special.BesselTableSpherical Bessel j_l (eval-only)579x @ N_ell=525, N_x=10kN_x >= 5k (or table re-used)
mlx_sci.special.airyAiry Ai/Bi + derivatives6.7x @ N=1MN >= ~30-50k
mlx_sci.special.gammagamma / lgamma / digammagamma 10.4x, lgamma 6.4x @ N=1MN >= ~50k
mlx_sci.special.hyp2f1Gauss 2F1 (fused Metal kernel)7.4x @ N=1MN >= ~100k
mlx_sci.linalg.expmMatrix exponential (Pade-13)2.08x real @ n=1024, 1.96x complex @ n=256n >= 1024 real / n >= 256 complex
mlx_sci.special.wigner_3jWigner 3j/6j/9j (Racah)2000x @ batch=1k vs sympybatch >= ~1k
mlx_sci.signal.stftSTFT / mel spectrogram10.0x @ 30 s audio (16 kHz)duration >= ~5 s
mlx_sci.quantum.fisherFisher J^T W J / large matmul39x @ 32k x 512matrix size dependent
mlx_sci.quantum.qre (eigh)Quantum relative entropy1.93x @ N=1000N >= ~500
mlx_sci.quantum.qre (Lanczos)QRE via Stochastic Lanczos657x @ N=2000 vs NumPy exact, 84x @ N=1000N >= 1000 (exact times out at N=2000)
mlx_sci.quantum.simStatevector simulatorsee sub-package READMEqubit-count dependent

See each sub-package's benchmark_results.md for the full curve, break-even points, and accuracy tables.

Why MLX, not CUDA / NumPy?

  • Apple Silicon native. No CUDA, no ROCm, no CPU offload dance — the Metal GPU on your laptop is the same one this stack is benchmarked on. No external dependencies beyond MLX + NumPy.
  • Lazy evaluation. MLX builds a deferred graph; the entire computation is materialised once at mx.eval time. We exploit this in mlx-qre's Stochastic Lanczos hot path so the whole k-step recurrence becomes a single GPU command-buffer.
  • mx.compile fusion. Fusable element-wise + reduction subgraphs are JIT-compiled into single kernels.
  • mx.fast.metal_kernel for hot inner loops. When auto-fusion cannot collapse a 200-op Taylor series into one dispatch, we drop in a hand-written Metal kernel — the 7.4x hyp2f1 speedup over SciPy comes from exactly this trick (the underlying *_metal symbols are internal; users keep calling hyp2f1/hyp1f1/hyp0f1 and the routing is transparent).
  • Honest about break-even. Every sub-package documents the N below which SciPy on CPU still wins. We do not claim wins where we lose; we publish the cross-over point and recommend the right tool for the size.

API stability

mlx-sci is at v0.2.2. The 0.x series is still iterating — minor versions may add re-exports and refactor module layout. We commit to keeping the headline functions (airy, gamma, hyp2f1, expm, stft, quantum_relative_entropy, MLXQuantumSimulator) source- compatible across the 0.x line. A v1.0 release will lock the public surface.

Sigma = 2 ln Q ecosystem

mlx-qre and mlx-quantum-sim are the numerical backbone for a small constellation of physics projects organised around the identity Sigma = 2 ln Q:

  • anatropic — entropy production / second-law violation tests on near-term quantum hardware.
  • petz-recovery-unification — Petz recovery map experiments and fidelity bounds.
  • tau-chrono — time-symmetry / Khronon-foliation experiments on the IQM Tuna-9 / Tuna-17 backends.

If you only care about the numerics, you can ignore that side entirely; the sub-packages are framework-agnostic.

Citation

If mlx-sci saves you time, please cite either the meta-package or the specific sub-package(s) you actually used:

@software{mlx_sci,
author = {Huang, Sheng-Kai},
title = {mlx-sci: GPU-accelerated SciPy + quantum-information for Apple Silicon},
year = {2026},
url = {https://github.com/akaiHuang/mlx-sci},
version = {0.2.0},
}

Each sub-package (mlx-airy, mlx-bessel, mlx-expm, mlx-fisher, mlx-gamma, mlx-hyp2f1, mlx-qre, mlx-stft, mlx-wigner, mlx-quantum-sim) ships its own short BibTeX entry in its README; cite the one(s) you actually exercised, not the umbrella, where the distinction matters.

License

MIT.

About

The missing scipy toolkit for Apple Silicon — GPU-accelerated special functions, linear algebra, signal processing, and quantum information via MLX

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mlx-sci

Quantum-information primitives + GPU special functions for Apple Silicon. Stochastic Lanczos QRE, Petz recovery, Wigner symbols, Bessel / hypergeometric / Airy / gamma, matrix-functions, STFT — all native on the Metal GPU through MLX.

mlx-sci speedups vs CPU baseline on M1 Max

Headline speedup of each module against its CPU baseline (NumPy / SciPy / sympy) on an Apple M1 Max. Each bar is the most representative single number per module — see each sub-package's benchmark_results.md for the full curve and break-even points.

mlx-sci is a meta-package that bundles a curated set of focused sub-packages — Airy, Bessel, Gamma, Hypergeometric, Wigner, matrix exponential, STFT, Fisher information, quantum relative entropy, and an optional statevector circuit simulator — under one consistent namespace (mlx_sci.quantum, mlx_sci.special, mlx_sci.linalg, mlx_sci.signal). Each sub-package is independently installable, so you can either pull the whole stack or pick à la carte.

Everything runs on the Apple GPU through MLX. There is no CUDA path, no host->device shuffling, and no framework dependency beyond MLX + NumPy.

Install

pip install mlx-sci # bundles all sub-packages
pip install "mlx-sci[sim]"# ... plus the optional circuit simulator# or pick à la carte
pip install mlx-airy mlx-bessel mlx-expm mlx-fisher mlx-gamma
pip install mlx-hyp2f1 mlx-qre mlx-stft mlx-wigner
pip install mlx-quantum-sim # optional, not on PyPI yet

Python >= 3.10, Apple Silicon (M1/M2/M3/M4), MLX >= 0.30.

Quick Start

importmlx.coreasmxfrommlx_sciimportquantum, special, linalg, signal# ── Quantum information ────────────────────────────────────────────# Quantum relative entropy via Stochastic Lanczos quadrature.# O(k * N^2) — beats the exact eigh path by ~2 orders at N >= 1000# and is the only path that completes at N = 2000 on the Metal GPU.rho=quantum.random_density_matrix(2000)
sigma=quantum.random_density_matrix(2000)
D_slq=quantum.quantum_relative_entropy_lanczos(rho, sigma, k=25, m=20)
# Exact eigh path is still available for small / batched inputsrho_s=quantum.random_density_matrix(256)
sigma_s=quantum.random_density_matrix(256)
D_exact=quantum.quantum_relative_entropy(rho_s, sigma_s)
# Petz recovery bound: F(rho, R o N(rho)) >= exp(-Sigma/2)ok=quantum.verify_petz_bound(kraus, rho_s, sigma_s) # noqa: F821# ── Special functions ──────────────────────────────────────────────# Wigner 3j — one million coupling coefficients in a single dispatchN=1_000_000j1=mx.ones(N); j2=mx.ones(N); j3=2*mx.ones(N)
m=mx.zeros(N)
w3j=special.wigner_3j(j1, j2, j3, m, m, m)
# Airy Ai/Bi over a real gridAi, Ai_p, Bi, Bi_p=special.airy(mx.linspace(-15.0, 15.0, 10_000))
# Gauss hypergeometric — auto-routes to a fused Metal kernel when |z|<0.5a=mx.array(0.5); b=mx.array(1.0); c=mx.array(1.5)
z=mx.linspace(0.01, 0.95, 1_000_000)
F=special.hyp2f1(a, b, c, z)
# Vectorised gamma / lgamma / digamma on GPUy=special.gamma(mx.linspace(0.1, 30.0, 1_000_000))
# ── Linear algebra ─────────────────────────────────────────────────# Matrix exponential (Pade-13 + scaling-squaring) on GPUH=mx.random.normal((1024, 1024))
U=linalg.expm(-1j*H*0.1)
# ── Signal processing ──────────────────────────────────────────────# Class-based STFT layer (mlx-stft 0.1.2 API)stft=signal.STFT(n_fft=1024, hop_length=256,
window=signal.hann_window(1024))
audio=mx.random.normal((480_000,)) # 30 s @ 16 kHzspec=stft(audio)

Modules at a glance

ModuleSource sub-packageScopeOne-liner
mlx_sci.special.airymlx-airyAiry Ai/Bi + derivativesAll four outputs in one call.
mlx_sci.special.gammamlx-gammagamma, lgamma, digamma, betaVectorised on GPU.
mlx_sci.special.hyp2f1mlx-hyp2f1Gauss 2F1, 1F1, 0F1Fused metal_kernel collapses ~200 MLX ops into 1 dispatch.
mlx_sci.special.BesselTablemlx-besselSpherical Bessel j_l(x), j_l'(x)Build once, evaluate over arbitrary x grids.
mlx_sci.special.wigner_*mlx-wignerWigner 3j / 6j / 9j, Clebsch-GordanRacah formula on GPU; millions per call.
mlx_sci.linalg.expmmlx-expmmatrix expm / logm / sqrtm / FrechetPade-13 + scaling-squaring on GPU.
mlx_sci.signal.STFTmlx-stftSTFT / ISTFT layers + windowsClass-based; CompiledSTFT for fixed-shape fusion.
mlx_sci.quantum.qremlx-qreD(rho || sigma), von Neumann entropyExact eigh + Stochastic Lanczos quadrature.
mlx_sci.quantum.petzmlx-qrePetz recovery map, fidelity, retrodictionF >= exp(-Sigma/2) verifier built in.
mlx_sci.quantum.channelsmlx-qreThermal / depolarizing / dephasing channelsIncluding the gravitational thermal_attenuator(eta).
mlx_sci.quantum.fishermlx-fisherFisher information matrix, natural-gradCosmology-scale J^T W J on GPU.
mlx_sci.quantum.sim(opt)mlx-quantum-simStatevector simulator, batched + noisyOptional extra (pip install mlx-sci[sim]). Ideal + WILLOW / HERON / T9 noise profiles.

Performance

All numbers below were measured on an Apple M1 Max, MLX 0.30-0.31, NumPy 2.x, SciPy 1.16. SciPy / NumPy reference is float64 on the CPU (Accelerate / LAPACK); MLX paths are float32 on the Apple GPU.

ModuleWhat it acceleratesHeadline speedup (M1 Max)Break-even
mlx_sci.special.BesselTableSpherical Bessel j_l (eval-only)579x @ N_ell=525, N_x=10kN_x >= 5k (or table re-used)
mlx_sci.special.airyAiry Ai/Bi + derivatives6.7x @ N=1MN >= ~30-50k
mlx_sci.special.gammagamma / lgamma / digammagamma 10.4x, lgamma 6.4x @ N=1MN >= ~50k
mlx_sci.special.hyp2f1Gauss 2F1 (fused Metal kernel)7.4x @ N=1MN >= ~100k
mlx_sci.linalg.expmMatrix exponential (Pade-13)2.08x real @ n=1024, 1.96x complex @ n=256n >= 1024 real / n >= 256 complex
mlx_sci.special.wigner_3jWigner 3j/6j/9j (Racah)2000x @ batch=1k vs sympybatch >= ~1k
mlx_sci.signal.stftSTFT / mel spectrogram10.0x @ 30 s audio (16 kHz)duration >= ~5 s
mlx_sci.quantum.fisherFisher J^T W J / large matmul39x @ 32k x 512matrix size dependent
mlx_sci.quantum.qre (eigh)Quantum relative entropy1.93x @ N=1000N >= ~500
mlx_sci.quantum.qre (Lanczos)QRE via Stochastic Lanczos657x @ N=2000 vs NumPy exact, 84x @ N=1000N >= 1000 (exact times out at N=2000)
mlx_sci.quantum.simStatevector simulatorsee sub-package READMEqubit-count dependent

See each sub-package's benchmark_results.md for the full curve, break-even points, and accuracy tables.

Why MLX, not CUDA / NumPy?

  • Apple Silicon native. No CUDA, no ROCm, no CPU offload dance — the Metal GPU on your laptop is the same one this stack is benchmarked on. No external dependencies beyond MLX + NumPy.
  • Lazy evaluation. MLX builds a deferred graph; the entire computation is materialised once at mx.eval time. We exploit this in mlx-qre's Stochastic Lanczos hot path so the whole k-step recurrence becomes a single GPU command-buffer.
  • mx.compile fusion. Fusable element-wise + reduction subgraphs are JIT-compiled into single kernels.
  • mx.fast.metal_kernel for hot inner loops. When auto-fusion cannot collapse a 200-op Taylor series into one dispatch, we drop in a hand-written Metal kernel — the 7.4x hyp2f1 speedup over SciPy comes from exactly this trick (the underlying *_metal symbols are internal; users keep calling hyp2f1/hyp1f1/hyp0f1 and the routing is transparent).
  • Honest about break-even. Every sub-package documents the N below which SciPy on CPU still wins. We do not claim wins where we lose; we publish the cross-over point and recommend the right tool for the size.

API stability

mlx-sci is at v0.2.2. The 0.x series is still iterating — minor versions may add re-exports and refactor module layout. We commit to keeping the headline functions (airy, gamma, hyp2f1, expm, stft, quantum_relative_entropy, MLXQuantumSimulator) source- compatible across the 0.x line. A v1.0 release will lock the public surface.

Sigma = 2 ln Q ecosystem

mlx-qre and mlx-quantum-sim are the numerical backbone for a small constellation of physics projects organised around the identity Sigma = 2 ln Q:

  • anatropic — entropy production / second-law violation tests on near-term quantum hardware.
  • petz-recovery-unification — Petz recovery map experiments and fidelity bounds.
  • tau-chrono — time-symmetry / Khronon-foliation experiments on the IQM Tuna-9 / Tuna-17 backends.

If you only care about the numerics, you can ignore that side entirely; the sub-packages are framework-agnostic.

Citation

If mlx-sci saves you time, please cite either the meta-package or the specific sub-package(s) you actually used:

@software{mlx_sci,
author = {Huang, Sheng-Kai},
title = {mlx-sci: GPU-accelerated SciPy + quantum-information for Apple Silicon},
year = {2026},
url = {https://github.com/akaiHuang/mlx-sci},
version = {0.2.0},
}

Each sub-package (mlx-airy, mlx-bessel, mlx-expm, mlx-fisher, mlx-gamma, mlx-hyp2f1, mlx-qre, mlx-stft, mlx-wigner, mlx-quantum-sim) ships its own short BibTeX entry in its README; cite the one(s) you actually exercised, not the umbrella, where the distinction matters.

License

MIT.

About

The missing scipy toolkit for Apple Silicon — GPU-accelerated special functions, linear algebra, signal processing, and quantum information via MLX

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mlx-sci

Quantum-information primitives + GPU special functions for Apple Silicon. Stochastic Lanczos QRE, Petz recovery, Wigner symbols, Bessel / hypergeometric / Airy / gamma, matrix-functions, STFT — all native on the Metal GPU through MLX.

mlx-sci speedups vs CPU baseline on M1 Max

Headline speedup of each module against its CPU baseline (NumPy / SciPy / sympy) on an Apple M1 Max. Each bar is the most representative single number per module — see each sub-package's benchmark_results.md for the full curve and break-even points.

mlx-sci is a meta-package that bundles a curated set of focused sub-packages — Airy, Bessel, Gamma, Hypergeometric, Wigner, matrix exponential, STFT, Fisher information, quantum relative entropy, and an optional statevector circuit simulator — under one consistent namespace (mlx_sci.quantum, mlx_sci.special, mlx_sci.linalg, mlx_sci.signal). Each sub-package is independently installable, so you can either pull the whole stack or pick à la carte.

Everything runs on the Apple GPU through MLX. There is no CUDA path, no host->device shuffling, and no framework dependency beyond MLX + NumPy.

Install

pip install mlx-sci # bundles all sub-packages
pip install "mlx-sci[sim]"# ... plus the optional circuit simulator# or pick à la carte
pip install mlx-airy mlx-bessel mlx-expm mlx-fisher mlx-gamma
pip install mlx-hyp2f1 mlx-qre mlx-stft mlx-wigner
pip install mlx-quantum-sim # optional, not on PyPI yet

Python >= 3.10, Apple Silicon (M1/M2/M3/M4), MLX >= 0.30.

Quick Start

importmlx.coreasmxfrommlx_sciimportquantum, special, linalg, signal# ── Quantum information ────────────────────────────────────────────# Quantum relative entropy via Stochastic Lanczos quadrature.# O(k * N^2) — beats the exact eigh path by ~2 orders at N >= 1000# and is the only path that completes at N = 2000 on the Metal GPU.rho=quantum.random_density_matrix(2000)
sigma=quantum.random_density_matrix(2000)
D_slq=quantum.quantum_relative_entropy_lanczos(rho, sigma, k=25, m=20)
# Exact eigh path is still available for small / batched inputsrho_s=quantum.random_density_matrix(256)
sigma_s=quantum.random_density_matrix(256)
D_exact=quantum.quantum_relative_entropy(rho_s, sigma_s)
# Petz recovery bound: F(rho, R o N(rho)) >= exp(-Sigma/2)ok=quantum.verify_petz_bound(kraus, rho_s, sigma_s) # noqa: F821# ── Special functions ──────────────────────────────────────────────# Wigner 3j — one million coupling coefficients in a single dispatchN=1_000_000j1=mx.ones(N); j2=mx.ones(N); j3=2*mx.ones(N)
m=mx.zeros(N)
w3j=special.wigner_3j(j1, j2, j3, m, m, m)
# Airy Ai/Bi over a real gridAi, Ai_p, Bi, Bi_p=special.airy(mx.linspace(-15.0, 15.0, 10_000))
# Gauss hypergeometric — auto-routes to a fused Metal kernel when |z|<0.5a=mx.array(0.5); b=mx.array(1.0); c=mx.array(1.5)
z=mx.linspace(0.01, 0.95, 1_000_000)
F=special.hyp2f1(a, b, c, z)
# Vectorised gamma / lgamma / digamma on GPUy=special.gamma(mx.linspace(0.1, 30.0, 1_000_000))
# ── Linear algebra ─────────────────────────────────────────────────# Matrix exponential (Pade-13 + scaling-squaring) on GPUH=mx.random.normal((1024, 1024))
U=linalg.expm(-1j*H*0.1)
# ── Signal processing ──────────────────────────────────────────────# Class-based STFT layer (mlx-stft 0.1.2 API)stft=signal.STFT(n_fft=1024, hop_length=256,
window=signal.hann_window(1024))
audio=mx.random.normal((480_000,)) # 30 s @ 16 kHzspec=stft(audio)

Modules at a glance

ModuleSource sub-packageScopeOne-liner
mlx_sci.special.airymlx-airyAiry Ai/Bi + derivativesAll four outputs in one call.
mlx_sci.special.gammamlx-gammagamma, lgamma, digamma, betaVectorised on GPU.
mlx_sci.special.hyp2f1mlx-hyp2f1Gauss 2F1, 1F1, 0F1Fused metal_kernel collapses ~200 MLX ops into 1 dispatch.
mlx_sci.special.BesselTablemlx-besselSpherical Bessel j_l(x), j_l'(x)Build once, evaluate over arbitrary x grids.
mlx_sci.special.wigner_*mlx-wignerWigner 3j / 6j / 9j, Clebsch-GordanRacah formula on GPU; millions per call.
mlx_sci.linalg.expmmlx-expmmatrix expm / logm / sqrtm / FrechetPade-13 + scaling-squaring on GPU.
mlx_sci.signal.STFTmlx-stftSTFT / ISTFT layers + windowsClass-based; CompiledSTFT for fixed-shape fusion.
mlx_sci.quantum.qremlx-qreD(rho || sigma), von Neumann entropyExact eigh + Stochastic Lanczos quadrature.
mlx_sci.quantum.petzmlx-qrePetz recovery map, fidelity, retrodictionF >= exp(-Sigma/2) verifier built in.
mlx_sci.quantum.channelsmlx-qreThermal / depolarizing / dephasing channelsIncluding the gravitational thermal_attenuator(eta).
mlx_sci.quantum.fishermlx-fisherFisher information matrix, natural-gradCosmology-scale J^T W J on GPU.
mlx_sci.quantum.sim(opt)mlx-quantum-simStatevector simulator, batched + noisyOptional extra (pip install mlx-sci[sim]). Ideal + WILLOW / HERON / T9 noise profiles.

Performance

All numbers below were measured on an Apple M1 Max, MLX 0.30-0.31, NumPy 2.x, SciPy 1.16. SciPy / NumPy reference is float64 on the CPU (Accelerate / LAPACK); MLX paths are float32 on the Apple GPU.

ModuleWhat it acceleratesHeadline speedup (M1 Max)Break-even
mlx_sci.special.BesselTableSpherical Bessel j_l (eval-only)579x @ N_ell=525, N_x=10kN_x >= 5k (or table re-used)
mlx_sci.special.airyAiry Ai/Bi + derivatives6.7x @ N=1MN >= ~30-50k
mlx_sci.special.gammagamma / lgamma / digammagamma 10.4x, lgamma 6.4x @ N=1MN >= ~50k
mlx_sci.special.hyp2f1Gauss 2F1 (fused Metal kernel)7.4x @ N=1MN >= ~100k
mlx_sci.linalg.expmMatrix exponential (Pade-13)2.08x real @ n=1024, 1.96x complex @ n=256n >= 1024 real / n >= 256 complex
mlx_sci.special.wigner_3jWigner 3j/6j/9j (Racah)2000x @ batch=1k vs sympybatch >= ~1k
mlx_sci.signal.stftSTFT / mel spectrogram10.0x @ 30 s audio (16 kHz)duration >= ~5 s
mlx_sci.quantum.fisherFisher J^T W J / large matmul39x @ 32k x 512matrix size dependent
mlx_sci.quantum.qre (eigh)Quantum relative entropy1.93x @ N=1000N >= ~500
mlx_sci.quantum.qre (Lanczos)QRE via Stochastic Lanczos657x @ N=2000 vs NumPy exact, 84x @ N=1000N >= 1000 (exact times out at N=2000)
mlx_sci.quantum.simStatevector simulatorsee sub-package READMEqubit-count dependent

See each sub-package's benchmark_results.md for the full curve, break-even points, and accuracy tables.

Why MLX, not CUDA / NumPy?

  • Apple Silicon native. No CUDA, no ROCm, no CPU offload dance — the Metal GPU on your laptop is the same one this stack is benchmarked on. No external dependencies beyond MLX + NumPy.
  • Lazy evaluation. MLX builds a deferred graph; the entire computation is materialised once at mx.eval time. We exploit this in mlx-qre's Stochastic Lanczos hot path so the whole k-step recurrence becomes a single GPU command-buffer.
  • mx.compile fusion. Fusable element-wise + reduction subgraphs are JIT-compiled into single kernels.
  • mx.fast.metal_kernel for hot inner loops. When auto-fusion cannot collapse a 200-op Taylor series into one dispatch, we drop in a hand-written Metal kernel — the 7.4x hyp2f1 speedup over SciPy comes from exactly this trick (the underlying *_metal symbols are internal; users keep calling hyp2f1/hyp1f1/hyp0f1 and the routing is transparent).
  • Honest about break-even. Every sub-package documents the N below which SciPy on CPU still wins. We do not claim wins where we lose; we publish the cross-over point and recommend the right tool for the size.

API stability

mlx-sci is at v0.2.2. The 0.x series is still iterating — minor versions may add re-exports and refactor module layout. We commit to keeping the headline functions (airy, gamma, hyp2f1, expm, stft, quantum_relative_entropy, MLXQuantumSimulator) source- compatible across the 0.x line. A v1.0 release will lock the public surface.

Sigma = 2 ln Q ecosystem

mlx-qre and mlx-quantum-sim are the numerical backbone for a small constellation of physics projects organised around the identity Sigma = 2 ln Q:

  • anatropic — entropy production / second-law violation tests on near-term quantum hardware.
  • petz-recovery-unification — Petz recovery map experiments and fidelity bounds.
  • tau-chrono — time-symmetry / Khronon-foliation experiments on the IQM Tuna-9 / Tuna-17 backends.

If you only care about the numerics, you can ignore that side entirely; the sub-packages are framework-agnostic.

Citation

If mlx-sci saves you time, please cite either the meta-package or the specific sub-package(s) you actually used:

@software{mlx_sci,
author = {Huang, Sheng-Kai},
title = {mlx-sci: GPU-accelerated SciPy + quantum-information for Apple Silicon},
year = {2026},
url = {https://github.com/akaiHuang/mlx-sci},
version = {0.2.0},
}

Each sub-package (mlx-airy, mlx-bessel, mlx-expm, mlx-fisher, mlx-gamma, mlx-hyp2f1, mlx-qre, mlx-stft, mlx-wigner, mlx-quantum-sim) ships its own short BibTeX entry in its README; cite the one(s) you actually exercised, not the umbrella, where the distinction matters.

License

MIT.

About

The missing scipy toolkit for Apple Silicon — GPU-accelerated special functions, linear algebra, signal processing, and quantum information via MLX

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mlx-sci

Quantum-information primitives + GPU special functions for Apple Silicon. Stochastic Lanczos QRE, Petz recovery, Wigner symbols, Bessel / hypergeometric / Airy / gamma, matrix-functions, STFT — all native on the Metal GPU through MLX.

mlx-sci speedups vs CPU baseline on M1 Max

Headline speedup of each module against its CPU baseline (NumPy / SciPy / sympy) on an Apple M1 Max. Each bar is the most representative single number per module — see each sub-package's benchmark_results.md for the full curve and break-even points.

mlx-sci is a meta-package that bundles a curated set of focused sub-packages — Airy, Bessel, Gamma, Hypergeometric, Wigner, matrix exponential, STFT, Fisher information, quantum relative entropy, and an optional statevector circuit simulator — under one consistent namespace (mlx_sci.quantum, mlx_sci.special, mlx_sci.linalg, mlx_sci.signal). Each sub-package is independently installable, so you can either pull the whole stack or pick à la carte.

Everything runs on the Apple GPU through MLX. There is no CUDA path, no host->device shuffling, and no framework dependency beyond MLX + NumPy.

Install

pip install mlx-sci # bundles all sub-packages
pip install "mlx-sci[sim]"# ... plus the optional circuit simulator# or pick à la carte
pip install mlx-airy mlx-bessel mlx-expm mlx-fisher mlx-gamma
pip install mlx-hyp2f1 mlx-qre mlx-stft mlx-wigner
pip install mlx-quantum-sim # optional, not on PyPI yet

Python >= 3.10, Apple Silicon (M1/M2/M3/M4), MLX >= 0.30.

Quick Start

importmlx.coreasmxfrommlx_sciimportquantum, special, linalg, signal# ── Quantum information ────────────────────────────────────────────# Quantum relative entropy via Stochastic Lanczos quadrature.# O(k * N^2) — beats the exact eigh path by ~2 orders at N >= 1000# and is the only path that completes at N = 2000 on the Metal GPU.rho=quantum.random_density_matrix(2000)
sigma=quantum.random_density_matrix(2000)
D_slq=quantum.quantum_relative_entropy_lanczos(rho, sigma, k=25, m=20)
# Exact eigh path is still available for small / batched inputsrho_s=quantum.random_density_matrix(256)
sigma_s=quantum.random_density_matrix(256)
D_exact=quantum.quantum_relative_entropy(rho_s, sigma_s)
# Petz recovery bound: F(rho, R o N(rho)) >= exp(-Sigma/2)ok=quantum.verify_petz_bound(kraus, rho_s, sigma_s) # noqa: F821# ── Special functions ──────────────────────────────────────────────# Wigner 3j — one million coupling coefficients in a single dispatchN=1_000_000j1=mx.ones(N); j2=mx.ones(N); j3=2*mx.ones(N)
m=mx.zeros(N)
w3j=special.wigner_3j(j1, j2, j3, m, m, m)
# Airy Ai/Bi over a real gridAi, Ai_p, Bi, Bi_p=special.airy(mx.linspace(-15.0, 15.0, 10_000))
# Gauss hypergeometric — auto-routes to a fused Metal kernel when |z|<0.5a=mx.array(0.5); b=mx.array(1.0); c=mx.array(1.5)
z=mx.linspace(0.01, 0.95, 1_000_000)
F=special.hyp2f1(a, b, c, z)
# Vectorised gamma / lgamma / digamma on GPUy=special.gamma(mx.linspace(0.1, 30.0, 1_000_000))
# ── Linear algebra ─────────────────────────────────────────────────# Matrix exponential (Pade-13 + scaling-squaring) on GPUH=mx.random.normal((1024, 1024))
U=linalg.expm(-1j*H*0.1)
# ── Signal processing ──────────────────────────────────────────────# Class-based STFT layer (mlx-stft 0.1.2 API)stft=signal.STFT(n_fft=1024, hop_length=256,
window=signal.hann_window(1024))
audio=mx.random.normal((480_000,)) # 30 s @ 16 kHzspec=stft(audio)

Modules at a glance

ModuleSource sub-packageScopeOne-liner
mlx_sci.special.airymlx-airyAiry Ai/Bi + derivativesAll four outputs in one call.
mlx_sci.special.gammamlx-gammagamma, lgamma, digamma, betaVectorised on GPU.
mlx_sci.special.hyp2f1mlx-hyp2f1Gauss 2F1, 1F1, 0F1Fused metal_kernel collapses ~200 MLX ops into 1 dispatch.
mlx_sci.special.BesselTablemlx-besselSpherical Bessel j_l(x), j_l'(x)Build once, evaluate over arbitrary x grids.
mlx_sci.special.wigner_*mlx-wignerWigner 3j / 6j / 9j, Clebsch-GordanRacah formula on GPU; millions per call.
mlx_sci.linalg.expmmlx-expmmatrix expm / logm / sqrtm / FrechetPade-13 + scaling-squaring on GPU.
mlx_sci.signal.STFTmlx-stftSTFT / ISTFT layers + windowsClass-based; CompiledSTFT for fixed-shape fusion.
mlx_sci.quantum.qremlx-qreD(rho || sigma), von Neumann entropyExact eigh + Stochastic Lanczos quadrature.
mlx_sci.quantum.petzmlx-qrePetz recovery map, fidelity, retrodictionF >= exp(-Sigma/2) verifier built in.
mlx_sci.quantum.channelsmlx-qreThermal / depolarizing / dephasing channelsIncluding the gravitational thermal_attenuator(eta).
mlx_sci.quantum.fishermlx-fisherFisher information matrix, natural-gradCosmology-scale J^T W J on GPU.
mlx_sci.quantum.sim(opt)mlx-quantum-simStatevector simulator, batched + noisyOptional extra (pip install mlx-sci[sim]). Ideal + WILLOW / HERON / T9 noise profiles.

Performance

All numbers below were measured on an Apple M1 Max, MLX 0.30-0.31, NumPy 2.x, SciPy 1.16. SciPy / NumPy reference is float64 on the CPU (Accelerate / LAPACK); MLX paths are float32 on the Apple GPU.

ModuleWhat it acceleratesHeadline speedup (M1 Max)Break-even
mlx_sci.special.BesselTableSpherical Bessel j_l (eval-only)579x @ N_ell=525, N_x=10kN_x >= 5k (or table re-used)
mlx_sci.special.airyAiry Ai/Bi + derivatives6.7x @ N=1MN >= ~30-50k
mlx_sci.special.gammagamma / lgamma / digammagamma 10.4x, lgamma 6.4x @ N=1MN >= ~50k
mlx_sci.special.hyp2f1Gauss 2F1 (fused Metal kernel)7.4x @ N=1MN >= ~100k
mlx_sci.linalg.expmMatrix exponential (Pade-13)2.08x real @ n=1024, 1.96x complex @ n=256n >= 1024 real / n >= 256 complex
mlx_sci.special.wigner_3jWigner 3j/6j/9j (Racah)2000x @ batch=1k vs sympybatch >= ~1k
mlx_sci.signal.stftSTFT / mel spectrogram10.0x @ 30 s audio (16 kHz)duration >= ~5 s
mlx_sci.quantum.fisherFisher J^T W J / large matmul39x @ 32k x 512matrix size dependent
mlx_sci.quantum.qre (eigh)Quantum relative entropy1.93x @ N=1000N >= ~500
mlx_sci.quantum.qre (Lanczos)QRE via Stochastic Lanczos657x @ N=2000 vs NumPy exact, 84x @ N=1000N >= 1000 (exact times out at N=2000)
mlx_sci.quantum.simStatevector simulatorsee sub-package READMEqubit-count dependent

See each sub-package's benchmark_results.md for the full curve, break-even points, and accuracy tables.

Why MLX, not CUDA / NumPy?

  • Apple Silicon native. No CUDA, no ROCm, no CPU offload dance — the Metal GPU on your laptop is the same one this stack is benchmarked on. No external dependencies beyond MLX + NumPy.
  • Lazy evaluation. MLX builds a deferred graph; the entire computation is materialised once at mx.eval time. We exploit this in mlx-qre's Stochastic Lanczos hot path so the whole k-step recurrence becomes a single GPU command-buffer.
  • mx.compile fusion. Fusable element-wise + reduction subgraphs are JIT-compiled into single kernels.
  • mx.fast.metal_kernel for hot inner loops. When auto-fusion cannot collapse a 200-op Taylor series into one dispatch, we drop in a hand-written Metal kernel — the 7.4x hyp2f1 speedup over SciPy comes from exactly this trick (the underlying *_metal symbols are internal; users keep calling hyp2f1/hyp1f1/hyp0f1 and the routing is transparent).
  • Honest about break-even. Every sub-package documents the N below which SciPy on CPU still wins. We do not claim wins where we lose; we publish the cross-over point and recommend the right tool for the size.

API stability

mlx-sci is at v0.2.2. The 0.x series is still iterating — minor versions may add re-exports and refactor module layout. We commit to keeping the headline functions (airy, gamma, hyp2f1, expm, stft, quantum_relative_entropy, MLXQuantumSimulator) source- compatible across the 0.x line. A v1.0 release will lock the public surface.

Sigma = 2 ln Q ecosystem

mlx-qre and mlx-quantum-sim are the numerical backbone for a small constellation of physics projects organised around the identity Sigma = 2 ln Q:

  • anatropic — entropy production / second-law violation tests on near-term quantum hardware.
  • petz-recovery-unification — Petz recovery map experiments and fidelity bounds.
  • tau-chrono — time-symmetry / Khronon-foliation experiments on the IQM Tuna-9 / Tuna-17 backends.

If you only care about the numerics, you can ignore that side entirely; the sub-packages are framework-agnostic.

Citation

If mlx-sci saves you time, please cite either the meta-package or the specific sub-package(s) you actually used:

@software{mlx_sci,
author = {Huang, Sheng-Kai},
title = {mlx-sci: GPU-accelerated SciPy + quantum-information for Apple Silicon},
year = {2026},
url = {https://github.com/akaiHuang/mlx-sci},
version = {0.2.0},
}

Each sub-package (mlx-airy, mlx-bessel, mlx-expm, mlx-fisher, mlx-gamma, mlx-hyp2f1, mlx-qre, mlx-stft, mlx-wigner, mlx-quantum-sim) ships its own short BibTeX entry in its README; cite the one(s) you actually exercised, not the umbrella, where the distinction matters.

License

MIT.

About

The missing scipy toolkit for Apple Silicon — GPU-accelerated special functions, linear algebra, signal processing, and quantum information via MLX

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mlx-sci

Quantum-information primitives + GPU special functions for Apple Silicon. Stochastic Lanczos QRE, Petz recovery, Wigner symbols, Bessel / hypergeometric / Airy / gamma, matrix-functions, STFT — all native on the Metal GPU through MLX.

mlx-sci speedups vs CPU baseline on M1 Max

Headline speedup of each module against its CPU baseline (NumPy / SciPy / sympy) on an Apple M1 Max. Each bar is the most representative single number per module — see each sub-package's benchmark_results.md for the full curve and break-even points.

mlx-sci is a meta-package that bundles a curated set of focused sub-packages — Airy, Bessel, Gamma, Hypergeometric, Wigner, matrix exponential, STFT, Fisher information, quantum relative entropy, and an optional statevector circuit simulator — under one consistent namespace (mlx_sci.quantum, mlx_sci.special, mlx_sci.linalg, mlx_sci.signal). Each sub-package is independently installable, so you can either pull the whole stack or pick à la carte.

Everything runs on the Apple GPU through MLX. There is no CUDA path, no host->device shuffling, and no framework dependency beyond MLX + NumPy.

Install

pip install mlx-sci # bundles all sub-packages
pip install "mlx-sci[sim]"# ... plus the optional circuit simulator# or pick à la carte
pip install mlx-airy mlx-bessel mlx-expm mlx-fisher mlx-gamma
pip install mlx-hyp2f1 mlx-qre mlx-stft mlx-wigner
pip install mlx-quantum-sim # optional, not on PyPI yet

Python >= 3.10, Apple Silicon (M1/M2/M3/M4), MLX >= 0.30.

Quick Start

importmlx.coreasmxfrommlx_sciimportquantum, special, linalg, signal# ── Quantum information ────────────────────────────────────────────# Quantum relative entropy via Stochastic Lanczos quadrature.# O(k * N^2) — beats the exact eigh path by ~2 orders at N >= 1000# and is the only path that completes at N = 2000 on the Metal GPU.rho=quantum.random_density_matrix(2000)
sigma=quantum.random_density_matrix(2000)
D_slq=quantum.quantum_relative_entropy_lanczos(rho, sigma, k=25, m=20)
# Exact eigh path is still available for small / batched inputsrho_s=quantum.random_density_matrix(256)
sigma_s=quantum.random_density_matrix(256)
D_exact=quantum.quantum_relative_entropy(rho_s, sigma_s)
# Petz recovery bound: F(rho, R o N(rho)) >= exp(-Sigma/2)ok=quantum.verify_petz_bound(kraus, rho_s, sigma_s) # noqa: F821# ── Special functions ──────────────────────────────────────────────# Wigner 3j — one million coupling coefficients in a single dispatchN=1_000_000j1=mx.ones(N); j2=mx.ones(N); j3=2*mx.ones(N)
m=mx.zeros(N)
w3j=special.wigner_3j(j1, j2, j3, m, m, m)
# Airy Ai/Bi over a real gridAi, Ai_p, Bi, Bi_p=special.airy(mx.linspace(-15.0, 15.0, 10_000))
# Gauss hypergeometric — auto-routes to a fused Metal kernel when |z|<0.5a=mx.array(0.5); b=mx.array(1.0); c=mx.array(1.5)
z=mx.linspace(0.01, 0.95, 1_000_000)
F=special.hyp2f1(a, b, c, z)
# Vectorised gamma / lgamma / digamma on GPUy=special.gamma(mx.linspace(0.1, 30.0, 1_000_000))
# ── Linear algebra ─────────────────────────────────────────────────# Matrix exponential (Pade-13 + scaling-squaring) on GPUH=mx.random.normal((1024, 1024))
U=linalg.expm(-1j*H*0.1)
# ── Signal processing ──────────────────────────────────────────────# Class-based STFT layer (mlx-stft 0.1.2 API)stft=signal.STFT(n_fft=1024, hop_length=256,
window=signal.hann_window(1024))
audio=mx.random.normal((480_000,)) # 30 s @ 16 kHzspec=stft(audio)

Modules at a glance

ModuleSource sub-packageScopeOne-liner
mlx_sci.special.airymlx-airyAiry Ai/Bi + derivativesAll four outputs in one call.
mlx_sci.special.gammamlx-gammagamma, lgamma, digamma, betaVectorised on GPU.
mlx_sci.special.hyp2f1mlx-hyp2f1Gauss 2F1, 1F1, 0F1Fused metal_kernel collapses ~200 MLX ops into 1 dispatch.
mlx_sci.special.BesselTablemlx-besselSpherical Bessel j_l(x), j_l'(x)Build once, evaluate over arbitrary x grids.
mlx_sci.special.wigner_*mlx-wignerWigner 3j / 6j / 9j, Clebsch-GordanRacah formula on GPU; millions per call.
mlx_sci.linalg.expmmlx-expmmatrix expm / logm / sqrtm / FrechetPade-13 + scaling-squaring on GPU.
mlx_sci.signal.STFTmlx-stftSTFT / ISTFT layers + windowsClass-based; CompiledSTFT for fixed-shape fusion.
mlx_sci.quantum.qremlx-qreD(rho || sigma), von Neumann entropyExact eigh + Stochastic Lanczos quadrature.
mlx_sci.quantum.petzmlx-qrePetz recovery map, fidelity, retrodictionF >= exp(-Sigma/2) verifier built in.
mlx_sci.quantum.channelsmlx-qreThermal / depolarizing / dephasing channelsIncluding the gravitational thermal_attenuator(eta).
mlx_sci.quantum.fishermlx-fisherFisher information matrix, natural-gradCosmology-scale J^T W J on GPU.
mlx_sci.quantum.sim(opt)mlx-quantum-simStatevector simulator, batched + noisyOptional extra (pip install mlx-sci[sim]). Ideal + WILLOW / HERON / T9 noise profiles.

Performance

All numbers below were measured on an Apple M1 Max, MLX 0.30-0.31, NumPy 2.x, SciPy 1.16. SciPy / NumPy reference is float64 on the CPU (Accelerate / LAPACK); MLX paths are float32 on the Apple GPU.

ModuleWhat it acceleratesHeadline speedup (M1 Max)Break-even
mlx_sci.special.BesselTableSpherical Bessel j_l (eval-only)579x @ N_ell=525, N_x=10kN_x >= 5k (or table re-used)
mlx_sci.special.airyAiry Ai/Bi + derivatives6.7x @ N=1MN >= ~30-50k
mlx_sci.special.gammagamma / lgamma / digammagamma 10.4x, lgamma 6.4x @ N=1MN >= ~50k
mlx_sci.special.hyp2f1Gauss 2F1 (fused Metal kernel)7.4x @ N=1MN >= ~100k
mlx_sci.linalg.expmMatrix exponential (Pade-13)2.08x real @ n=1024, 1.96x complex @ n=256n >= 1024 real / n >= 256 complex
mlx_sci.special.wigner_3jWigner 3j/6j/9j (Racah)2000x @ batch=1k vs sympybatch >= ~1k
mlx_sci.signal.stftSTFT / mel spectrogram10.0x @ 30 s audio (16 kHz)duration >= ~5 s
mlx_sci.quantum.fisherFisher J^T W J / large matmul39x @ 32k x 512matrix size dependent
mlx_sci.quantum.qre (eigh)Quantum relative entropy1.93x @ N=1000N >= ~500
mlx_sci.quantum.qre (Lanczos)QRE via Stochastic Lanczos657x @ N=2000 vs NumPy exact, 84x @ N=1000N >= 1000 (exact times out at N=2000)
mlx_sci.quantum.simStatevector simulatorsee sub-package READMEqubit-count dependent

See each sub-package's benchmark_results.md for the full curve, break-even points, and accuracy tables.

Why MLX, not CUDA / NumPy?

  • Apple Silicon native. No CUDA, no ROCm, no CPU offload dance — the Metal GPU on your laptop is the same one this stack is benchmarked on. No external dependencies beyond MLX + NumPy.
  • Lazy evaluation. MLX builds a deferred graph; the entire computation is materialised once at mx.eval time. We exploit this in mlx-qre's Stochastic Lanczos hot path so the whole k-step recurrence becomes a single GPU command-buffer.
  • mx.compile fusion. Fusable element-wise + reduction subgraphs are JIT-compiled into single kernels.
  • mx.fast.metal_kernel for hot inner loops. When auto-fusion cannot collapse a 200-op Taylor series into one dispatch, we drop in a hand-written Metal kernel — the 7.4x hyp2f1 speedup over SciPy comes from exactly this trick (the underlying *_metal symbols are internal; users keep calling hyp2f1/hyp1f1/hyp0f1 and the routing is transparent).
  • Honest about break-even. Every sub-package documents the N below which SciPy on CPU still wins. We do not claim wins where we lose; we publish the cross-over point and recommend the right tool for the size.

API stability

mlx-sci is at v0.2.2. The 0.x series is still iterating — minor versions may add re-exports and refactor module layout. We commit to keeping the headline functions (airy, gamma, hyp2f1, expm, stft, quantum_relative_entropy, MLXQuantumSimulator) source- compatible across the 0.x line. A v1.0 release will lock the public surface.

Sigma = 2 ln Q ecosystem

mlx-qre and mlx-quantum-sim are the numerical backbone for a small constellation of physics projects organised around the identity Sigma = 2 ln Q:

  • anatropic — entropy production / second-law violation tests on near-term quantum hardware.
  • petz-recovery-unification — Petz recovery map experiments and fidelity bounds.
  • tau-chrono — time-symmetry / Khronon-foliation experiments on the IQM Tuna-9 / Tuna-17 backends.

If you only care about the numerics, you can ignore that side entirely; the sub-packages are framework-agnostic.

Citation

If mlx-sci saves you time, please cite either the meta-package or the specific sub-package(s) you actually used:

@software{mlx_sci,
author = {Huang, Sheng-Kai},
title = {mlx-sci: GPU-accelerated SciPy + quantum-information for Apple Silicon},
year = {2026},
url = {https://github.com/akaiHuang/mlx-sci},
version = {0.2.0},
}

Each sub-package (mlx-airy, mlx-bessel, mlx-expm, mlx-fisher, mlx-gamma, mlx-hyp2f1, mlx-qre, mlx-stft, mlx-wigner, mlx-quantum-sim) ships its own short BibTeX entry in its README; cite the one(s) you actually exercised, not the umbrella, where the distinction matters.

License

MIT.

About

The missing scipy toolkit for Apple Silicon — GPU-accelerated special functions, linear algebra, signal processing, and quantum information via MLX

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mlx-sci

Quantum-information primitives + GPU special functions for Apple Silicon. Stochastic Lanczos QRE, Petz recovery, Wigner symbols, Bessel / hypergeometric / Airy / gamma, matrix-functions, STFT — all native on the Metal GPU through MLX.

mlx-sci speedups vs CPU baseline on M1 Max

Headline speedup of each module against its CPU baseline (NumPy / SciPy / sympy) on an Apple M1 Max. Each bar is the most representative single number per module — see each sub-package's benchmark_results.md for the full curve and break-even points.

mlx-sci is a meta-package that bundles a curated set of focused sub-packages — Airy, Bessel, Gamma, Hypergeometric, Wigner, matrix exponential, STFT, Fisher information, quantum relative entropy, and an optional statevector circuit simulator — under one consistent namespace (mlx_sci.quantum, mlx_sci.special, mlx_sci.linalg, mlx_sci.signal). Each sub-package is independently installable, so you can either pull the whole stack or pick à la carte.

Everything runs on the Apple GPU through MLX. There is no CUDA path, no host->device shuffling, and no framework dependency beyond MLX + NumPy.

Install

pip install mlx-sci # bundles all sub-packages
pip install "mlx-sci[sim]"# ... plus the optional circuit simulator# or pick à la carte
pip install mlx-airy mlx-bessel mlx-expm mlx-fisher mlx-gamma
pip install mlx-hyp2f1 mlx-qre mlx-stft mlx-wigner
pip install mlx-quantum-sim # optional, not on PyPI yet

Python >= 3.10, Apple Silicon (M1/M2/M3/M4), MLX >= 0.30.

Quick Start

importmlx.coreasmxfrommlx_sciimportquantum, special, linalg, signal# ── Quantum information ────────────────────────────────────────────# Quantum relative entropy via Stochastic Lanczos quadrature.# O(k * N^2) — beats the exact eigh path by ~2 orders at N >= 1000# and is the only path that completes at N = 2000 on the Metal GPU.rho=quantum.random_density_matrix(2000)
sigma=quantum.random_density_matrix(2000)
D_slq=quantum.quantum_relative_entropy_lanczos(rho, sigma, k=25, m=20)
# Exact eigh path is still available for small / batched inputsrho_s=quantum.random_density_matrix(256)
sigma_s=quantum.random_density_matrix(256)
D_exact=quantum.quantum_relative_entropy(rho_s, sigma_s)
# Petz recovery bound: F(rho, R o N(rho)) >= exp(-Sigma/2)ok=quantum.verify_petz_bound(kraus, rho_s, sigma_s) # noqa: F821# ── Special functions ──────────────────────────────────────────────# Wigner 3j — one million coupling coefficients in a single dispatchN=1_000_000j1=mx.ones(N); j2=mx.ones(N); j3=2*mx.ones(N)
m=mx.zeros(N)
w3j=special.wigner_3j(j1, j2, j3, m, m, m)
# Airy Ai/Bi over a real gridAi, Ai_p, Bi, Bi_p=special.airy(mx.linspace(-15.0, 15.0, 10_000))
# Gauss hypergeometric — auto-routes to a fused Metal kernel when |z|<0.5a=mx.array(0.5); b=mx.array(1.0); c=mx.array(1.5)
z=mx.linspace(0.01, 0.95, 1_000_000)
F=special.hyp2f1(a, b, c, z)
# Vectorised gamma / lgamma / digamma on GPUy=special.gamma(mx.linspace(0.1, 30.0, 1_000_000))
# ── Linear algebra ─────────────────────────────────────────────────# Matrix exponential (Pade-13 + scaling-squaring) on GPUH=mx.random.normal((1024, 1024))
U=linalg.expm(-1j*H*0.1)
# ── Signal processing ──────────────────────────────────────────────# Class-based STFT layer (mlx-stft 0.1.2 API)stft=signal.STFT(n_fft=1024, hop_length=256,
window=signal.hann_window(1024))
audio=mx.random.normal((480_000,)) # 30 s @ 16 kHzspec=stft(audio)

Modules at a glance

ModuleSource sub-packageScopeOne-liner
mlx_sci.special.airymlx-airyAiry Ai/Bi + derivativesAll four outputs in one call.
mlx_sci.special.gammamlx-gammagamma, lgamma, digamma, betaVectorised on GPU.
mlx_sci.special.hyp2f1mlx-hyp2f1Gauss 2F1, 1F1, 0F1Fused metal_kernel collapses ~200 MLX ops into 1 dispatch.
mlx_sci.special.BesselTablemlx-besselSpherical Bessel j_l(x), j_l'(x)Build once, evaluate over arbitrary x grids.
mlx_sci.special.wigner_*mlx-wignerWigner 3j / 6j / 9j, Clebsch-GordanRacah formula on GPU; millions per call.
mlx_sci.linalg.expmmlx-expmmatrix expm / logm / sqrtm / FrechetPade-13 + scaling-squaring on GPU.
mlx_sci.signal.STFTmlx-stftSTFT / ISTFT layers + windowsClass-based; CompiledSTFT for fixed-shape fusion.
mlx_sci.quantum.qremlx-qreD(rho || sigma), von Neumann entropyExact eigh + Stochastic Lanczos quadrature.
mlx_sci.quantum.petzmlx-qrePetz recovery map, fidelity, retrodictionF >= exp(-Sigma/2) verifier built in.
mlx_sci.quantum.channelsmlx-qreThermal / depolarizing / dephasing channelsIncluding the gravitational thermal_attenuator(eta).
mlx_sci.quantum.fishermlx-fisherFisher information matrix, natural-gradCosmology-scale J^T W J on GPU.
mlx_sci.quantum.sim(opt)mlx-quantum-simStatevector simulator, batched + noisyOptional extra (pip install mlx-sci[sim]). Ideal + WILLOW / HERON / T9 noise profiles.

Performance

All numbers below were measured on an Apple M1 Max, MLX 0.30-0.31, NumPy 2.x, SciPy 1.16. SciPy / NumPy reference is float64 on the CPU (Accelerate / LAPACK); MLX paths are float32 on the Apple GPU.

ModuleWhat it acceleratesHeadline speedup (M1 Max)Break-even
mlx_sci.special.BesselTableSpherical Bessel j_l (eval-only)579x @ N_ell=525, N_x=10kN_x >= 5k (or table re-used)
mlx_sci.special.airyAiry Ai/Bi + derivatives6.7x @ N=1MN >= ~30-50k
mlx_sci.special.gammagamma / lgamma / digammagamma 10.4x, lgamma 6.4x @ N=1MN >= ~50k
mlx_sci.special.hyp2f1Gauss 2F1 (fused Metal kernel)7.4x @ N=1MN >= ~100k
mlx_sci.linalg.expmMatrix exponential (Pade-13)2.08x real @ n=1024, 1.96x complex @ n=256n >= 1024 real / n >= 256 complex
mlx_sci.special.wigner_3jWigner 3j/6j/9j (Racah)2000x @ batch=1k vs sympybatch >= ~1k
mlx_sci.signal.stftSTFT / mel spectrogram10.0x @ 30 s audio (16 kHz)duration >= ~5 s
mlx_sci.quantum.fisherFisher J^T W J / large matmul39x @ 32k x 512matrix size dependent
mlx_sci.quantum.qre (eigh)Quantum relative entropy1.93x @ N=1000N >= ~500
mlx_sci.quantum.qre (Lanczos)QRE via Stochastic Lanczos657x @ N=2000 vs NumPy exact, 84x @ N=1000N >= 1000 (exact times out at N=2000)
mlx_sci.quantum.simStatevector simulatorsee sub-package READMEqubit-count dependent

See each sub-package's benchmark_results.md for the full curve, break-even points, and accuracy tables.

Why MLX, not CUDA / NumPy?

  • Apple Silicon native. No CUDA, no ROCm, no CPU offload dance — the Metal GPU on your laptop is the same one this stack is benchmarked on. No external dependencies beyond MLX + NumPy.
  • Lazy evaluation. MLX builds a deferred graph; the entire computation is materialised once at mx.eval time. We exploit this in mlx-qre's Stochastic Lanczos hot path so the whole k-step recurrence becomes a single GPU command-buffer.
  • mx.compile fusion. Fusable element-wise + reduction subgraphs are JIT-compiled into single kernels.
  • mx.fast.metal_kernel for hot inner loops. When auto-fusion cannot collapse a 200-op Taylor series into one dispatch, we drop in a hand-written Metal kernel — the 7.4x hyp2f1 speedup over SciPy comes from exactly this trick (the underlying *_metal symbols are internal; users keep calling hyp2f1/hyp1f1/hyp0f1 and the routing is transparent).
  • Honest about break-even. Every sub-package documents the N below which SciPy on CPU still wins. We do not claim wins where we lose; we publish the cross-over point and recommend the right tool for the size.

API stability

mlx-sci is at v0.2.2. The 0.x series is still iterating — minor versions may add re-exports and refactor module layout. We commit to keeping the headline functions (airy, gamma, hyp2f1, expm, stft, quantum_relative_entropy, MLXQuantumSimulator) source- compatible across the 0.x line. A v1.0 release will lock the public surface.

Sigma = 2 ln Q ecosystem

mlx-qre and mlx-quantum-sim are the numerical backbone for a small constellation of physics projects organised around the identity Sigma = 2 ln Q:

  • anatropic — entropy production / second-law violation tests on near-term quantum hardware.
  • petz-recovery-unification — Petz recovery map experiments and fidelity bounds.
  • tau-chrono — time-symmetry / Khronon-foliation experiments on the IQM Tuna-9 / Tuna-17 backends.

If you only care about the numerics, you can ignore that side entirely; the sub-packages are framework-agnostic.

Citation

If mlx-sci saves you time, please cite either the meta-package or the specific sub-package(s) you actually used:

@software{mlx_sci,
author = {Huang, Sheng-Kai},
title = {mlx-sci: GPU-accelerated SciPy + quantum-information for Apple Silicon},
year = {2026},
url = {https://github.com/akaiHuang/mlx-sci},
version = {0.2.0},
}

Each sub-package (mlx-airy, mlx-bessel, mlx-expm, mlx-fisher, mlx-gamma, mlx-hyp2f1, mlx-qre, mlx-stft, mlx-wigner, mlx-quantum-sim) ships its own short BibTeX entry in its README; cite the one(s) you actually exercised, not the umbrella, where the distinction matters.

License

MIT.

About

The missing scipy toolkit for Apple Silicon — GPU-accelerated special functions, linear algebra, signal processing, and quantum information via MLX

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mlx-sci

Quantum-information primitives + GPU special functions for Apple Silicon. Stochastic Lanczos QRE, Petz recovery, Wigner symbols, Bessel / hypergeometric / Airy / gamma, matrix-functions, STFT — all native on the Metal GPU through MLX.

mlx-sci speedups vs CPU baseline on M1 Max

Headline speedup of each module against its CPU baseline (NumPy / SciPy / sympy) on an Apple M1 Max. Each bar is the most representative single number per module — see each sub-package's benchmark_results.md for the full curve and break-even points.

mlx-sci is a meta-package that bundles a curated set of focused sub-packages — Airy, Bessel, Gamma, Hypergeometric, Wigner, matrix exponential, STFT, Fisher information, quantum relative entropy, and an optional statevector circuit simulator — under one consistent namespace (mlx_sci.quantum, mlx_sci.special, mlx_sci.linalg, mlx_sci.signal). Each sub-package is independently installable, so you can either pull the whole stack or pick à la carte.

Everything runs on the Apple GPU through MLX. There is no CUDA path, no host->device shuffling, and no framework dependency beyond MLX + NumPy.

Install

pip install mlx-sci # bundles all sub-packages
pip install "mlx-sci[sim]"# ... plus the optional circuit simulator# or pick à la carte
pip install mlx-airy mlx-bessel mlx-expm mlx-fisher mlx-gamma
pip install mlx-hyp2f1 mlx-qre mlx-stft mlx-wigner
pip install mlx-quantum-sim # optional, not on PyPI yet

Python >= 3.10, Apple Silicon (M1/M2/M3/M4), MLX >= 0.30.

Quick Start

importmlx.coreasmxfrommlx_sciimportquantum, special, linalg, signal# ── Quantum information ────────────────────────────────────────────# Quantum relative entropy via Stochastic Lanczos quadrature.# O(k * N^2) — beats the exact eigh path by ~2 orders at N >= 1000# and is the only path that completes at N = 2000 on the Metal GPU.rho=quantum.random_density_matrix(2000)
sigma=quantum.random_density_matrix(2000)
D_slq=quantum.quantum_relative_entropy_lanczos(rho, sigma, k=25, m=20)
# Exact eigh path is still available for small / batched inputsrho_s=quantum.random_density_matrix(256)
sigma_s=quantum.random_density_matrix(256)
D_exact=quantum.quantum_relative_entropy(rho_s, sigma_s)
# Petz recovery bound: F(rho, R o N(rho)) >= exp(-Sigma/2)ok=quantum.verify_petz_bound(kraus, rho_s, sigma_s) # noqa: F821# ── Special functions ──────────────────────────────────────────────# Wigner 3j — one million coupling coefficients in a single dispatchN=1_000_000j1=mx.ones(N); j2=mx.ones(N); j3=2*mx.ones(N)
m=mx.zeros(N)
w3j=special.wigner_3j(j1, j2, j3, m, m, m)
# Airy Ai/Bi over a real gridAi, Ai_p, Bi, Bi_p=special.airy(mx.linspace(-15.0, 15.0, 10_000))
# Gauss hypergeometric — auto-routes to a fused Metal kernel when |z|<0.5a=mx.array(0.5); b=mx.array(1.0); c=mx.array(1.5)
z=mx.linspace(0.01, 0.95, 1_000_000)
F=special.hyp2f1(a, b, c, z)
# Vectorised gamma / lgamma / digamma on GPUy=special.gamma(mx.linspace(0.1, 30.0, 1_000_000))
# ── Linear algebra ─────────────────────────────────────────────────# Matrix exponential (Pade-13 + scaling-squaring) on GPUH=mx.random.normal((1024, 1024))
U=linalg.expm(-1j*H*0.1)
# ── Signal processing ──────────────────────────────────────────────# Class-based STFT layer (mlx-stft 0.1.2 API)stft=signal.STFT(n_fft=1024, hop_length=256,
window=signal.hann_window(1024))
audio=mx.random.normal((480_000,)) # 30 s @ 16 kHzspec=stft(audio)

Modules at a glance

ModuleSource sub-packageScopeOne-liner
mlx_sci.special.airymlx-airyAiry Ai/Bi + derivativesAll four outputs in one call.
mlx_sci.special.gammamlx-gammagamma, lgamma, digamma, betaVectorised on GPU.
mlx_sci.special.hyp2f1mlx-hyp2f1Gauss 2F1, 1F1, 0F1Fused metal_kernel collapses ~200 MLX ops into 1 dispatch.
mlx_sci.special.BesselTablemlx-besselSpherical Bessel j_l(x), j_l'(x)Build once, evaluate over arbitrary x grids.
mlx_sci.special.wigner_*mlx-wignerWigner 3j / 6j / 9j, Clebsch-GordanRacah formula on GPU; millions per call.
mlx_sci.linalg.expmmlx-expmmatrix expm / logm / sqrtm / FrechetPade-13 + scaling-squaring on GPU.
mlx_sci.signal.STFTmlx-stftSTFT / ISTFT layers + windowsClass-based; CompiledSTFT for fixed-shape fusion.
mlx_sci.quantum.qremlx-qreD(rho || sigma), von Neumann entropyExact eigh + Stochastic Lanczos quadrature.
mlx_sci.quantum.petzmlx-qrePetz recovery map, fidelity, retrodictionF >= exp(-Sigma/2) verifier built in.
mlx_sci.quantum.channelsmlx-qreThermal / depolarizing / dephasing channelsIncluding the gravitational thermal_attenuator(eta).
mlx_sci.quantum.fishermlx-fisherFisher information matrix, natural-gradCosmology-scale J^T W J on GPU.
mlx_sci.quantum.sim(opt)mlx-quantum-simStatevector simulator, batched + noisyOptional extra (pip install mlx-sci[sim]). Ideal + WILLOW / HERON / T9 noise profiles.

Performance

All numbers below were measured on an Apple M1 Max, MLX 0.30-0.31, NumPy 2.x, SciPy 1.16. SciPy / NumPy reference is float64 on the CPU (Accelerate / LAPACK); MLX paths are float32 on the Apple GPU.

ModuleWhat it acceleratesHeadline speedup (M1 Max)Break-even
mlx_sci.special.BesselTableSpherical Bessel j_l (eval-only)579x @ N_ell=525, N_x=10kN_x >= 5k (or table re-used)
mlx_sci.special.airyAiry Ai/Bi + derivatives6.7x @ N=1MN >= ~30-50k
mlx_sci.special.gammagamma / lgamma / digammagamma 10.4x, lgamma 6.4x @ N=1MN >= ~50k
mlx_sci.special.hyp2f1Gauss 2F1 (fused Metal kernel)7.4x @ N=1MN >= ~100k
mlx_sci.linalg.expmMatrix exponential (Pade-13)2.08x real @ n=1024, 1.96x complex @ n=256n >= 1024 real / n >= 256 complex
mlx_sci.special.wigner_3jWigner 3j/6j/9j (Racah)2000x @ batch=1k vs sympybatch >= ~1k
mlx_sci.signal.stftSTFT / mel spectrogram10.0x @ 30 s audio (16 kHz)duration >= ~5 s
mlx_sci.quantum.fisherFisher J^T W J / large matmul39x @ 32k x 512matrix size dependent
mlx_sci.quantum.qre (eigh)Quantum relative entropy1.93x @ N=1000N >= ~500
mlx_sci.quantum.qre (Lanczos)QRE via Stochastic Lanczos657x @ N=2000 vs NumPy exact, 84x @ N=1000N >= 1000 (exact times out at N=2000)
mlx_sci.quantum.simStatevector simulatorsee sub-package READMEqubit-count dependent

See each sub-package's benchmark_results.md for the full curve, break-even points, and accuracy tables.

Why MLX, not CUDA / NumPy?

  • Apple Silicon native. No CUDA, no ROCm, no CPU offload dance — the Metal GPU on your laptop is the same one this stack is benchmarked on. No external dependencies beyond MLX + NumPy.
  • Lazy evaluation. MLX builds a deferred graph; the entire computation is materialised once at mx.eval time. We exploit this in mlx-qre's Stochastic Lanczos hot path so the whole k-step recurrence becomes a single GPU command-buffer.
  • mx.compile fusion. Fusable element-wise + reduction subgraphs are JIT-compiled into single kernels.
  • mx.fast.metal_kernel for hot inner loops. When auto-fusion cannot collapse a 200-op Taylor series into one dispatch, we drop in a hand-written Metal kernel — the 7.4x hyp2f1 speedup over SciPy comes from exactly this trick (the underlying *_metal symbols are internal; users keep calling hyp2f1/hyp1f1/hyp0f1 and the routing is transparent).
  • Honest about break-even. Every sub-package documents the N below which SciPy on CPU still wins. We do not claim wins where we lose; we publish the cross-over point and recommend the right tool for the size.

API stability

mlx-sci is at v0.2.2. The 0.x series is still iterating — minor versions may add re-exports and refactor module layout. We commit to keeping the headline functions (airy, gamma, hyp2f1, expm, stft, quantum_relative_entropy, MLXQuantumSimulator) source- compatible across the 0.x line. A v1.0 release will lock the public surface.

Sigma = 2 ln Q ecosystem

mlx-qre and mlx-quantum-sim are the numerical backbone for a small constellation of physics projects organised around the identity Sigma = 2 ln Q:

  • anatropic — entropy production / second-law violation tests on near-term quantum hardware.
  • petz-recovery-unification — Petz recovery map experiments and fidelity bounds.
  • tau-chrono — time-symmetry / Khronon-foliation experiments on the IQM Tuna-9 / Tuna-17 backends.

If you only care about the numerics, you can ignore that side entirely; the sub-packages are framework-agnostic.

Citation

If mlx-sci saves you time, please cite either the meta-package or the specific sub-package(s) you actually used:

@software{mlx_sci,
author = {Huang, Sheng-Kai},
title = {mlx-sci: GPU-accelerated SciPy + quantum-information for Apple Silicon},
year = {2026},
url = {https://github.com/akaiHuang/mlx-sci},
version = {0.2.0},
}

Each sub-package (mlx-airy, mlx-bessel, mlx-expm, mlx-fisher, mlx-gamma, mlx-hyp2f1, mlx-qre, mlx-stft, mlx-wigner, mlx-quantum-sim) ships its own short BibTeX entry in its README; cite the one(s) you actually exercised, not the umbrella, where the distinction matters.

License

MIT.

About

The missing scipy toolkit for Apple Silicon — GPU-accelerated special functions, linear algebra, signal processing, and quantum information via MLX

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

mlx-sci

Quantum-information primitives + GPU special functions for Apple Silicon. Stochastic Lanczos QRE, Petz recovery, Wigner symbols, Bessel / hypergeometric / Airy / gamma, matrix-functions, STFT — all native on the Metal GPU through MLX.

mlx-sci speedups vs CPU baseline on M1 Max

Headline speedup of each module against its CPU baseline (NumPy / SciPy / sympy) on an Apple M1 Max. Each bar is the most representative single number per module — see each sub-package's benchmark_results.md for the full curve and break-even points.

mlx-sci is a meta-package that bundles a curated set of focused sub-packages — Airy, Bessel, Gamma, Hypergeometric, Wigner, matrix exponential, STFT, Fisher information, quantum relative entropy, and an optional statevector circuit simulator — under one consistent namespace (mlx_sci.quantum, mlx_sci.special, mlx_sci.linalg, mlx_sci.signal). Each sub-package is independently installable, so you can either pull the whole stack or pick à la carte.

Everything runs on the Apple GPU through MLX. There is no CUDA path, no host->device shuffling, and no framework dependency beyond MLX + NumPy.

Install

pip install mlx-sci # bundles all sub-packages
pip install "mlx-sci[sim]"# ... plus the optional circuit simulator# or pick à la carte
pip install mlx-airy mlx-bessel mlx-expm mlx-fisher mlx-gamma
pip install mlx-hyp2f1 mlx-qre mlx-stft mlx-wigner
pip install mlx-quantum-sim # optional, not on PyPI yet

Python >= 3.10, Apple Silicon (M1/M2/M3/M4), MLX >= 0.30.

Quick Start

importmlx.coreasmxfrommlx_sciimportquantum, special, linalg, signal# ── Quantum information ────────────────────────────────────────────# Quantum relative entropy via Stochastic Lanczos quadrature.# O(k * N^2) — beats the exact eigh path by ~2 orders at N >= 1000# and is the only path that completes at N = 2000 on the Metal GPU.rho=quantum.random_density_matrix(2000)
sigma=quantum.random_density_matrix(2000)
D_slq=quantum.quantum_relative_entropy_lanczos(rho, sigma, k=25, m=20)
# Exact eigh path is still available for small / batched inputsrho_s=quantum.random_density_matrix(256)
sigma_s=quantum.random_density_matrix(256)
D_exact=quantum.quantum_relative_entropy(rho_s, sigma_s)
# Petz recovery bound: F(rho, R o N(rho)) >= exp(-Sigma/2)ok=quantum.verify_petz_bound(kraus, rho_s, sigma_s) # noqa: F821# ── Special functions ──────────────────────────────────────────────# Wigner 3j — one million coupling coefficients in a single dispatchN=1_000_000j1=mx.ones(N); j2=mx.ones(N); j3=2*mx.ones(N)
m=mx.zeros(N)
w3j=special.wigner_3j(j1, j2, j3, m, m, m)
# Airy Ai/Bi over a real gridAi, Ai_p, Bi, Bi_p=special.airy(mx.linspace(-15.0, 15.0, 10_000))
# Gauss hypergeometric — auto-routes to a fused Metal kernel when |z|<0.5a=mx.array(0.5); b=mx.array(1.0); c=mx.array(1.5)
z=mx.linspace(0.01, 0.95, 1_000_000)
F=special.hyp2f1(a, b, c, z)
# Vectorised gamma / lgamma / digamma on GPUy=special.gamma(mx.linspace(0.1, 30.0, 1_000_000))
# ── Linear algebra ─────────────────────────────────────────────────# Matrix exponential (Pade-13 + scaling-squaring) on GPUH=mx.random.normal((1024, 1024))
U=linalg.expm(-1j*H*0.1)
# ── Signal processing ──────────────────────────────────────────────# Class-based STFT layer (mlx-stft 0.1.2 API)stft=signal.STFT(n_fft=1024, hop_length=256,
window=signal.hann_window(1024))
audio=mx.random.normal((480_000,)) # 30 s @ 16 kHzspec=stft(audio)

Modules at a glance

ModuleSource sub-packageScopeOne-liner
mlx_sci.special.airymlx-airyAiry Ai/Bi + derivativesAll four outputs in one call.
mlx_sci.special.gammamlx-gammagamma, lgamma, digamma, betaVectorised on GPU.
mlx_sci.special.hyp2f1mlx-hyp2f1Gauss 2F1, 1F1, 0F1Fused metal_kernel collapses ~200 MLX ops into 1 dispatch.
mlx_sci.special.BesselTablemlx-besselSpherical Bessel j_l(x), j_l'(x)Build once, evaluate over arbitrary x grids.
mlx_sci.special.wigner_*mlx-wignerWigner 3j / 6j / 9j, Clebsch-GordanRacah formula on GPU; millions per call.
mlx_sci.linalg.expmmlx-expmmatrix expm / logm / sqrtm / FrechetPade-13 + scaling-squaring on GPU.
mlx_sci.signal.STFTmlx-stftSTFT / ISTFT layers + windowsClass-based; CompiledSTFT for fixed-shape fusion.
mlx_sci.quantum.qremlx-qreD(rho || sigma), von Neumann entropyExact eigh + Stochastic Lanczos quadrature.
mlx_sci.quantum.petzmlx-qrePetz recovery map, fidelity, retrodictionF >= exp(-Sigma/2) verifier built in.
mlx_sci.quantum.channelsmlx-qreThermal / depolarizing / dephasing channelsIncluding the gravitational thermal_attenuator(eta).
mlx_sci.quantum.fishermlx-fisherFisher information matrix, natural-gradCosmology-scale J^T W J on GPU.
mlx_sci.quantum.sim(opt)mlx-quantum-simStatevector simulator, batched + noisyOptional extra (pip install mlx-sci[sim]). Ideal + WILLOW / HERON / T9 noise profiles.

Performance

All numbers below were measured on an Apple M1 Max, MLX 0.30-0.31, NumPy 2.x, SciPy 1.16. SciPy / NumPy reference is float64 on the CPU (Accelerate / LAPACK); MLX paths are float32 on the Apple GPU.

ModuleWhat it acceleratesHeadline speedup (M1 Max)Break-even
mlx_sci.special.BesselTableSpherical Bessel j_l (eval-only)579x @ N_ell=525, N_x=10kN_x >= 5k (or table re-used)
mlx_sci.special.airyAiry Ai/Bi + derivatives6.7x @ N=1MN >= ~30-50k
mlx_sci.special.gammagamma / lgamma / digammagamma 10.4x, lgamma 6.4x @ N=1MN >= ~50k
mlx_sci.special.hyp2f1Gauss 2F1 (fused Metal kernel)7.4x @ N=1MN >= ~100k
mlx_sci.linalg.expmMatrix exponential (Pade-13)2.08x real @ n=1024, 1.96x complex @ n=256n >= 1024 real / n >= 256 complex
mlx_sci.special.wigner_3jWigner 3j/6j/9j (Racah)2000x @ batch=1k vs sympybatch >= ~1k
mlx_sci.signal.stftSTFT / mel spectrogram10.0x @ 30 s audio (16 kHz)duration >= ~5 s
mlx_sci.quantum.fisherFisher J^T W J / large matmul39x @ 32k x 512matrix size dependent
mlx_sci.quantum.qre (eigh)Quantum relative entropy1.93x @ N=1000N >= ~500
mlx_sci.quantum.qre (Lanczos)QRE via Stochastic Lanczos657x @ N=2000 vs NumPy exact, 84x @ N=1000N >= 1000 (exact times out at N=2000)
mlx_sci.quantum.simStatevector simulatorsee sub-package READMEqubit-count dependent

See each sub-package's benchmark_results.md for the full curve, break-even points, and accuracy tables.

Why MLX, not CUDA / NumPy?

  • Apple Silicon native. No CUDA, no ROCm, no CPU offload dance — the Metal GPU on your laptop is the same one this stack is benchmarked on. No external dependencies beyond MLX + NumPy.
  • Lazy evaluation. MLX builds a deferred graph; the entire computation is materialised once at mx.eval time. We exploit this in mlx-qre's Stochastic Lanczos hot path so the whole k-step recurrence becomes a single GPU command-buffer.
  • mx.compile fusion. Fusable element-wise + reduction subgraphs are JIT-compiled into single kernels.
  • mx.fast.metal_kernel for hot inner loops. When auto-fusion cannot collapse a 200-op Taylor series into one dispatch, we drop in a hand-written Metal kernel — the 7.4x hyp2f1 speedup over SciPy comes from exactly this trick (the underlying *_metal symbols are internal; users keep calling hyp2f1/hyp1f1/hyp0f1 and the routing is transparent).
  • Honest about break-even. Every sub-package documents the N below which SciPy on CPU still wins. We do not claim wins where we lose; we publish the cross-over point and recommend the right tool for the size.

API stability

mlx-sci is at v0.2.2. The 0.x series is still iterating — minor versions may add re-exports and refactor module layout. We commit to keeping the headline functions (airy, gamma, hyp2f1, expm, stft, quantum_relative_entropy, MLXQuantumSimulator) source- compatible across the 0.x line. A v1.0 release will lock the public surface.

Sigma = 2 ln Q ecosystem

mlx-qre and mlx-quantum-sim are the numerical backbone for a small constellation of physics projects organised around the identity Sigma = 2 ln Q:

  • anatropic — entropy production / second-law violation tests on near-term quantum hardware.
  • petz-recovery-unification — Petz recovery map experiments and fidelity bounds.
  • tau-chrono — time-symmetry / Khronon-foliation experiments on the IQM Tuna-9 / Tuna-17 backends.

If you only care about the numerics, you can ignore that side entirely; the sub-packages are framework-agnostic.

Citation

If mlx-sci saves you time, please cite either the meta-package or the specific sub-package(s) you actually used:

@software{mlx_sci,
author = {Huang, Sheng-Kai},
title = {mlx-sci: GPU-accelerated SciPy + quantum-information for Apple Silicon},
year = {2026},
url = {https://github.com/akaiHuang/mlx-sci},
version = {0.2.0},
}

Each sub-package (mlx-airy, mlx-bessel, mlx-expm, mlx-fisher, mlx-gamma, mlx-hyp2f1, mlx-qre, mlx-stft, mlx-wigner, mlx-quantum-sim) ships its own short BibTeX entry in its README; cite the one(s) you actually exercised, not the umbrella, where the distinction matters.

License

MIT.

About

The missing scipy toolkit for Apple Silicon — GPU-accelerated special functions, linear algebra, signal processing, and quantum information via MLX

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages