Skip to main content

PyTorch Quantum Machine Learning with cuQuantum - Fast Adjoint Differentiation

Project description

torchqml

PyTorch Quantum Machine Learning with cuQuantum - Fast Adjoint Differentiation

Features

  • Adjoint Differentiation: O(G) gradient calculation using cuQuantum's custatevec and optimized C++ kernels.
  • PyTorch Native: Fully integrated with torch.autograd and torch.nn.
  • High Performance: Custom C++/CUDA extension reusing cuStateVec/cuBLAS handles for minimize overhead.

Performance

TorchQML outperforms PennyLane's lightning.gpu backend significantly on NVIDIA GPUs (measured on T4):

Qubits Layers TorchQML (ms) PennyLane (ms) Speedup
4 5 5.72 16.99 3.0x
8 10 13.18 48.69 3.7x
12 10 24.29 69.65 2.9x

Installation

pip install .

Usage

import torch
import torchqml as tq

# Build circuit
qc = tq.QuantumCircuit(2)
qc.h(0)
qc.ry(0, param_index=0)
qc.cx(0, 1)

# Parameters
params = torch.tensor([[0.5]], requires_grad=True)

# Expectation
exp_val = qc.expectation(params, tq.Z(0))

# Backward
exp_val.backward()
print(params.grad)

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

torchqml-0.1.1.tar.gz (16.4 kB view details)

Uploaded Source

File details

Details for the file torchqml-0.1.1.tar.gz.

File metadata

  • Download URL: torchqml-0.1.1.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for torchqml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8d1d47e23aa6e3514b0a1f7866c9b7744b12fedfe58bec5de44765d180e4849a
MD5 47e04715a4386e89aa7178b07a386786
BLAKE2b-256 b6d56d38f4807c20f6cff00a8a7dba311ca741b47bc705a2eec21a5d4d873f91

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