Skip to main content

Tensor Operations for Research in Quantum systems.

Project description

TorQ Quantum Library

Lightweight, Torch-based statevector utilities built for fast quantum layers inside neural networks.

Developed while writing the paper: Quantum Physics-Informed Neural Networks for Maxwell’s Equations: Circuit Design, “Black Hole” Barren Plateaus Mitigation, and GPU Acceleration

by Ziv Chen, Gal G. Shaviner, Hemanth Chandravamsi, Shimon Pisnoy, Steven H. Frankel, Uzi Pereg

https://arxiv.org/abs/2506.23246

When to use

  • You want a fast, differentiable quantum layer inside a PyTorch model (QLayer/Circuit).
  • You train with large batches on GPU and care about throughput.
  • You need ideal (noise-free) analytic expectation values, not shot-based measurements. The noise and shots are features planned to be added in the future.

When not to use

  • You need realistic hardware noise models or error channels.
  • You need shot-based measurements or sampling.
  • You need hardware-specific circuit compilation.

What this library optimizes for

  • Speed as part of a neural network forward/backward pass.
  • Batched, parallel evaluation (many inputs at once).
  • Single-GPU execution for training pipelines.

This library was optimized and benchmarked primarily on single NVIDIA L40s and A100 GPUs. Performance on other GPUs has not been tuned and may differ. Multi-GPU usage is not currently available.

Current supported features

  • Quantum circuit construction with 6 common ansatzes:

    • basic_entangling
    • strongly_entangling
    • cross_mesh
    • cross_mesh_2_rots
    • cross_mesh_cx_rot
    • no_entanglement_ansatz
  • 5 Angle embedding scaling methods: (intended for usage with a tanh activation function before the quantum layer)

    • acos: acos(angles) -> output in [0, pi]
    • asin: asin(angles) + pi/2 -> output in [0, pi]
    • scale_with_bias(scale): (angles + 1) * (scale/2) -> output in [0, pi] # usually scale is set to pi
    • scale(scale): angles * scale -> output in [-pi, pi] # usually scale is set to pi
    • None: angles -> output in [-1, 1]
  • Data reuploading (significant cost addition for the simulation running time and memory)

  • Measurement of local expectation values (default Pauli-Z)

  • Differentiable with PyTorch autograd

  • To benchmark performance against PennyLane, please use the TorQ-bench repository: https://github.com/zivchen9993/TorQ-bench

Limitations

  • Statevector simulation only (memory scales as O(2^n)).
  • Analytic measurements only; no sampling/shots.
  • Ideal, noise-free gates and measurements.

Install

pip install -e .

Quickstart

import torch
from torq.simple import Circuit, CircuitConfig

n_qubits = 4
n_layers = 2

cfg = CircuitConfig(data_reupload_every=0)
circuit = Circuit(n_qubits=n_qubits, n_layers=n_layers, ansatz_name="basic_entangling", config=cfg)

x = torch.rand(8, n_qubits)
y = circuit(x)

Angle scaling example: (intended for usage with a tanh activation function before the quantum layer).

import torch
from torq.simple import Circuit, CircuitConfig

cfg = CircuitConfig(angle_scaling_method="scale", angle_scaling=torch.pi)
circuit = Circuit(n_qubits=4, n_layers=2, ansatz_name="basic_entangling", config=cfg)

x = torch.rand(8, 4)
y = circuit(x)

Data reuploading

import torch
from torq.simple import Circuit, CircuitConfig

cfg = CircuitConfig(data_reupload_every=2)
circuit = Circuit(n_qubits=4, n_layers=2, ansatz_name="cross_mesh", config=cfg)

x = torch.rand(8, 4)
y = circuit(x)

Low-level functions

from torq.simple import (
    angle_embedding,
    data_reuploading_gates,
    data_reuploading,
    get_initial_state,
    measure,
)

License

MIT. See LICENSE.

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

torq_quantum-0.1.1.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

torq_quantum-0.1.1-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for torq_quantum-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b62c9ff5f738c99d1c60bfff68aae9616ddf8a2998b299a217d8e28837ce033a
MD5 06b83521a77dd0e75c39b970b5cc72eb
BLAKE2b-256 609c97651a9b845e14c56f97d1c1f1b669e59c59c1dfb7311f1a5148d24b0839

See more details on using hashes here.

File details

Details for the file torq_quantum-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: torq_quantum-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for torq_quantum-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e77c182513ba76a8279c747bbfcb64edc4b596559796831c360010afb1b2b13
MD5 95f01a25f941c34f5174119217ffba5c
BLAKE2b-256 0ad49d5a1d3edf35fefc74286cc5854fca77744527dd2d4d5817996dfcf30002

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