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
# install from PyPI
python -m pip install torq-quantum
# optional: editable install for local development
python -m pip install -e .
Note: the PyPI package name is torq-quantum, while the Python import path is torq.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torq_quantum-0.1.2.tar.gz.
File metadata
- Download URL: torq_quantum-0.1.2.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd55ac5fbfe3aed7466cf08743b56217ba25e1a84ce5991ea61e00493d858d48
|
|
| MD5 |
5bc6d3cdb8d3def39261cdf9a2a68398
|
|
| BLAKE2b-256 |
7d9990667b6f9c385513c87bad5dce2fd511b512daa7531238586978747daafa
|
File details
Details for the file torq_quantum-0.1.2-py3-none-any.whl.
File metadata
- Download URL: torq_quantum-0.1.2-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d6404241202e4010272738e69ea0051c05c069abd530c8b621071a465e5ff8d
|
|
| MD5 |
f75d2faac8ed5f0e81cf85fd5dd4880c
|
|
| BLAKE2b-256 |
17c55cd567dc7286360f8da688fa9a770d87152fd643290edabbc84ac06712f0
|