Skip to main content

GPU-accelerated Quantum Relative Entropy on Apple Silicon via MLX

Project description

mlx-qre

GPU-accelerated Quantum Relative Entropy on Apple Silicon via MLX.

$$\Sigma = D(\rho | \sigma) = \mathrm{Tr}[\rho(\ln\rho - \ln\sigma)]$$

Installation

pip install -e .

Requires Python 3.10+ and Apple Silicon (M1/M2/M3/M4).

Quick Start

import mlx.core as mx
from mlx_qre import quantum_relative_entropy, random_density_matrix

# Two 100x100 density matrices on GPU
rho = random_density_matrix(100)
sigma = random_density_matrix(100)

# Compute D(rho || sigma) — eigendecomposition runs on Metal GPU
D = quantum_relative_entropy(rho, sigma)
mx.eval(D)
print(f"D(rho || sigma) = {D.item():.6f}")

# Batched: 500 pairs simultaneously
rho_batch = random_density_matrix(50, batch_size=500)
sigma_batch = random_density_matrix(50, batch_size=500)
D_batch = quantum_relative_entropy(rho_batch, sigma_batch)

Features

Module Function Description
qre quantum_relative_entropy(rho, sigma) D(rho || sigma) via GPU eigendecomposition
qre von_neumann_entropy(rho) S(rho) = -Tr[rho ln rho]
qre relative_entropy_pure_state(psi, sigma) Efficient D for pure states: -ln(psi|sigma|psi)
classical kl_divergence(p, q) Classical KL divergence
classical jensen_shannon_divergence(p, q) Symmetric JSD
classical renyi_divergence(p, q, alpha) Renyi divergence of order alpha
channels thermal_attenuator(eta) Gravitational channel eta = -g_00
channels channel_entropy_production(K, rho, sigma) Sigma through channel
channels depolarizing_channel(p) Depolarizing noise
channels dephasing_channel(gamma) Dephasing noise
petz petz_recovery_map(K, sigma) Construct Petz recovery R
petz petz_recovery_fidelity(rho, sigma, K) F(rho, R o N(rho))
petz verify_petz_bound(rho, sigma, K) Check F >= exp(-Sigma/2)
petz retrodiction_quality(rho, sigma, K) tau = 1 - F

Use Cases

  • Gravitational entropy production: Sigma_grav = D(N_eta(rho) || N_eta(sigma)) with eta = 1/Q^2
  • Quantum channel analysis: entropy production, data processing inequality
  • Petz recovery bounds: F >= exp(-Sigma/2), retrodiction quality
  • Quantum ML: kernel methods using QRE as a distance measure
  • Neural entropy: EEG/neural signal entropy production analysis

Benchmark

python -m mlx_qre.benchmark

Compares MLX (Apple Silicon GPU) vs NumPy (CPU) across matrix sizes N = 10 to 1000.

Tests

pip install -e ".[dev]"
pytest tests/ -v

Theory

The quantum relative entropy D(rho || sigma) is the quantum generalization of KL divergence. In the retrocausality framework:

  • Sigma = 2 ln Q: unified entropy production formula
  • Petz bound: F >= exp(-Sigma/2) quantifies retrodiction cost
  • tau = 1 - F: retrodiction deficit (0 = perfect, 1 = irreversible)
  • Zero-entropy limit: Sigma -> 0 implies perfect retrodiction (no time arrow)

License

MIT License. Copyright (c) 2026 Sheng-Kai Huang.

Project details


Download files

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

Source Distribution

mlx_qre-0.1.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

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

mlx_qre-0.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file mlx_qre-0.1.0.tar.gz.

File metadata

  • Download URL: mlx_qre-0.1.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mlx_qre-0.1.0.tar.gz
Algorithm Hash digest
SHA256 481b38d4904128f936a274dfdbc181e6b3556d96d73de0e5f283792fd1c73e6e
MD5 5684b7aa87b1a42aaab6bbdbf9f5b7a2
BLAKE2b-256 a431a5897a021650464f1d38f9449f04a7ed304f92ff35115e4d20de2bc671cb

See more details on using hashes here.

File details

Details for the file mlx_qre-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mlx_qre-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mlx_qre-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28a5479b96f0e502badaabbd35bd19f8ff09f26676e03aed57f5debb89c8c99d
MD5 ce12e6d106fd24a59a486be63fb40880
BLAKE2b-256 d1e1f8d6b384062365a662ec6f88d6d647e06cb4d0f4f8da23702c5b043b091b

See more details on using hashes here.

Supported by

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