QuantRS2-Py: Python Bindings for QuantRS2
QuantRS2-Py provides Python bindings for the QuantRS2 quantum computing framework, allowing Python users to access the high-performance Rust implementation with a user-friendly Python API.
Version 0.1.2 🎉
Production-Ready Stable Release! This release benefits from refined SciRS2 v0.1.2 integration and comprehensive platform support:
🖥️ Platform Support
- macOS Optimization: Native Apple Silicon and Intel Mac support with optimized performance
- CUDA/Linux Support: Full CUDA GPU acceleration on Linux platforms
- Cross-Platform Compatibility: Unified codebase supporting Windows, macOS, and Linux
🚀 SciRS2 Integration & Performance
- Enhanced Performance: SciRS2's parallel operations with automatic optimization
- SIMD Acceleration: Hardware-aware vectorized quantum operations
- GPU Computing: Complete GPU backend with CUDA support and memory optimization
- Memory Management: Advanced algorithms for 30+ qubit simulations
- Automatic Backend Selection: Intelligent selection based on problem characteristics
Features
Core Quantum Computing
- Seamless Python Integration: Easy-to-use Python interface for QuantRS2
- High Performance: Leverages Rust's performance while providing Python's usability
- Complete Gate Set: All quantum gates from the core library exposed to Python
- Simulator Access: Run circuits on state vector and other simulators
- GPU Acceleration: Optional GPU acceleration via feature flag
- PyO3-Based: Built using the robust PyO3 framework for Rust-Python interoperability
Advanced Features
🤖 Quantum Machine Learning Suite
- Autograd Quantum ML: Automatic differentiation for quantum machine learning
- Enhanced QGANs: Improved Quantum Generative Adversarial Networks
- Quantum CNNs: Quantum Convolutional Neural Networks implementation
- QNN Training: Parameter-shift rule gradients with adaptive learning rates
- VQE: Multi-ansatz support with hardware-efficient circuits
- QAOA: Quantum Approximate Optimization Algorithm with MaxCut examples
- Quantum PCA: Principal Component Analysis using quantum computing
🛠️ Developer Experience Tools
- Circuit Optimizer: Advanced quantum circuit optimization with ZX-calculus
- Tensor Network Optimization: High-performance tensor network simulations
- Performance Profiler: Comprehensive execution analysis and optimization recommendations
- Enhanced Testing: Expanded test coverage with GPU backend validation
- Resource Estimator: Advanced complexity and performance analysis
🏭 Production Features
- Dynamic Qubit Allocation: Runtime resource management with efficient memory usage
- Hardware Backend Integration: Support for IBM Quantum, Google Quantum AI, and AWS Braket
- Error Mitigation: Zero-noise extrapolation and other mitigation techniques
- Quantum Annealing: QUBO/Ising model optimization framework
- Cryptography Protocols: BB84, E91, and quantum signature implementations
- Comprehensive Examples: 50+ working examples demonstrating all features
Installation
From PyPI
pip install quantrs2
From Source (with GPU support)
pip install git+https://github.com/cool-japan/quantrs.git#subdirectory=py[gpu]
With Machine Learning Support
pip install quantrs2[ml]
Usage
Creating a Bell State
import quantrs2 as qr
import numpy as np
# Create a 2-qubit circuit
circuit = qr.PyCircuit(2)
# Build a Bell state
circuit.h(0)
circuit.cnot(0, 1)
# Run the simulation
result = circuit.run()
# Print the probabilities
probs = result.state_probabilities()
for state, prob in probs.items():
print(f"|{state}⟩: {prob:.6f}")
Advanced Usage Examples
Quantum Machine Learning
Quantum Neural Network (QNN)
from quantrs2.ml import QNN
# Create a QNN with 4 qubits and 2 layers
qnn = QNN(n_qubits=4, n_layers=2)
# Train on quantum data
qnn.fit(X_train, y_train, epochs=100)
# Make predictions
predictions = qnn.predict(X_test)
Variational Quantum Eigensolver (VQE)
from quantrs2.algorithms import VQE
from quantrs2.optimizers import COBYLA
# Define a Hamiltonian
hamiltonian = qr.Hamiltonian.from_string("ZZ + 0.5*XI + 0.5*IX")
# Create VQE instance
vqe = VQE(hamiltonian, ansatz='ry', optimizer=COBYLA())
# Find ground state
result = vqe.run()
print(f"Ground state energy: {result.eigenvalue}")
Hardware Integration
from quantrs2.hardware import IBMQuantumBackend
# Connect to IBM Quantum
backend = IBMQuantumBackend(api_token="your_token")
# Create and execute circuit
circuit = qr.PyCircuit(5)
circuit.h(0)
circuit.cnot(0, 1)
# Execute on real hardware
job = backend.execute(circuit, shots=1024)
result = job.result()
Error Mitigation
from quantrs2.mitigation import ZeroNoiseExtrapolation
# Create a noisy circuit
circuit = qr.PyCircuit(3)
circuit.h(0)
circuit.cnot(0, 1)
circuit.cnot(1, 2)
# Apply zero-noise extrapolation
zne = ZeroNoiseExtrapolation(noise_factors=[1, 3, 5])
mitigated_result = zne.run(circuit)
Quantum Annealing
from quantrs2.anneal import QuboModel
# Define a QUBO problem
Q = {
(0, 0): -1,
(1, 1): -1,
(0, 1): 2
}
# Create and solve
model = QuboModel(Q)
solution = model.solve(sampler='simulated_annealing')
print(f"Optimal solution: {solution.best_sample}")
GPU Acceleration
# Enable GPU acceleration for large circuits
circuit = qr.PyCircuit(20)
# Build your circuit...
# Run with GPU acceleration
result = circuit.run(use_gpu=True)
# Alternatively, check GPU availability
if qr.is_gpu_available():
result = circuit.run(use_gpu=True)
else:
result = circuit.run(use_gpu=False)
# Get results
probs = result.probabilities()
Advanced GPU Linear Algebra
from quantrs2.gpu import GPUBackend, GPULinearAlgebra
# Initialize GPU backend
gpu_backend = GPUBackend()
# Create GPU-accelerated linear algebra operations
gpu_linalg = GPULinearAlgebra(gpu_backend)
# Perform high-performance quantum state operations
large_state = qr.create_quantum_state(25) # 25-qubit state
optimized_state = gpu_linalg.optimize_state(large_state)
# GPU-accelerated tensor network contractions
tensor_result = gpu_linalg.contract_tensor_network(quantum_circuit)
Tensor Network Optimization
from quantrs2.tensor_networks import TensorNetworkOptimizer
# Create and optimize tensor networks
optimizer = TensorNetworkOptimizer()
# Build a complex quantum circuit
circuit = qr.PyCircuit(30)
# Add many gates...
# Optimize using tensor network techniques
optimized_circuit = optimizer.optimize(circuit)
result = optimized_circuit.run()
API Reference
Core Classes
PyCircuit: Main circuit building and executionPySimulationResult: Results from quantum simulations
Module Structure
Machine Learning (quantrs2.ml)
QNN: Quantum Neural Networks with gradient computationVQE: Variational Quantum Eigensolver with multiple ansätzeQuantumGAN: Quantum Generative Adversarial NetworksHEPClassifier: High-Energy Physics quantum classifier
Dynamic Allocation (quantrs2.dynamic_allocation)
QubitAllocator: Runtime qubit resource managementDynamicCircuit: Thread-safe dynamic circuit constructionAllocationStrategy: Multiple allocation optimization strategies
Advanced Algorithms (quantrs2.advanced_algorithms)
AdvancedVQE: Enhanced VQE with multiple optimization methodsEnhancedQAOA: Advanced QAOA with sophisticated optimizationQuantumWalk: Comprehensive quantum walk implementationsQuantumErrorCorrection: Error correction protocol suite
Hardware Backends (quantrs2.hardware_backends)
HardwareBackendManager: Multi-provider backend managementIBMQuantumBackend: IBM Quantum integrationGoogleQuantumBackend: Google Quantum AI integrationAWSBraketBackend: AWS Braket integration
Enhanced Compatibility
enhanced_qiskit_compatibility: Advanced Qiskit integrationenhanced_pennylane_plugin: Comprehensive PennyLane integration
Error Mitigation (quantrs2.mitigation)
ZeroNoiseExtrapolation: Advanced ZNE implementationObservable: Quantum observables with enhanced measurementCircuitFolding: Sophisticated noise scaling utilities
Quantum Annealing (quantrs2.anneal)
QuboModel: Advanced QUBO problem formulationIsingModel: Enhanced Ising model optimizationPenaltyOptimizer: Sophisticated constrained optimization
Performance
QuantRS2-Py v0.1.2 delivers exceptional performance for production quantum computing:
Simulation Capabilities
- Large-Scale Simulation: Efficiently simulates 30+ qubits on standard hardware
- GPU Acceleration: Complete GPU backend with CUDA support for massive speedups
- Memory Optimization: Advanced SciRS2-powered algorithms for efficient memory usage
- SIMD Vectorization: Hardware-aware vectorized operations on all platforms
Platform Optimization
- macOS Native: Optimized for Apple Silicon and Intel Macs
- CUDA/Linux: Full GPU acceleration on Linux with CUDA support
- Cross-Platform: Consistent performance across Windows, macOS, and Linux
- Automatic Detection: Smart hardware capability detection and optimization
Advanced Features
- Parallel Execution: Automatic parallelization via SciRS2 parallel operations
- Tensor Networks: High-performance tensor network contractions
- Circuit Optimization: Automatic quantum circuit optimization
- Backend Selection: Intelligent backend selection based on problem characteristics
Requirements
Basic Requirements
- Python 3.8 or higher
- NumPy >= 1.20.0
- Matplotlib >= 3.3.0 (for visualization)
- IPython >= 7.0.0 (for interactive features)
Optional Dependencies
- GPU Support: CUDA toolkit 11.0+ for GPU acceleration on Linux
- Machine Learning: scikit-learn >= 1.0.0, scipy >= 1.7.0 (install with
pip install quantrs2[ml]) - Development: pytest, black, flake8 (install with
pip install quantrs2[dev])
Platform Specific
- macOS: Optimized for macOS 10.15+ (both Intel and Apple Silicon)
- Linux: CUDA support requires compatible NVIDIA drivers
- Windows: Full feature support with optional GPU acceleration
Contributing
We welcome contributions! Please see our contributing guidelines for more information.
License
This project is licensed under either:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Metadata
Release files for quantrs2 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| quantrs2-0.1.2.tar.gz | 8.2 MB | With provenance | Details for quantrs2-0.1.2.tar.gz |
Built distributions (wheels)
Total release size: 18.4 MB
Release files / quantrs2-0.1.2.tar.gz
| Download URL | quantrs2-0.1.2.tar.gz |
|---|---|
| Size | 8.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b256929aea55ee71ffb3156537a6c2bd0a8dca91daa29e0d078c7e21a80028ff
|
|
BLAKE2b-256 checksum How to use checksums |
b29265878d150e0f5764b96c67cb25cc913fa48e9581032a173527405f2f157d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 23, 2026.
Transparency logRelease files / quantrs2-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | quantrs2-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.11 PyPy 3.11 7.3 |
|
SHA-256 checksum How to use checksums |
19fd0c1f4cb8b86eb385d20dc25d32f5374fa0db52fa4d3d4fadd8513bfe71ae
|
|
BLAKE2b-256 checksum How to use checksums |
257df476367a922fd6e5a8536f329fdc16ddd8c94080f5a6988a6868b12946e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 23, 2026.
Transparency logRelease files / quantrs2-0.1.2-cp38-abi3-win_amd64.whl
| Download URL | quantrs2-0.1.2-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
24ca341ea96187f2a4b9df8602ee49077b53547d181ea106c60ecc49f149e4c9
|
|
BLAKE2b-256 checksum How to use checksums |
c1dcdf9d25a1ef6578e8c23842e47744d69ecd41201b7e7c19ea3a69a13da837
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 23, 2026.
Transparency logRelease files / quantrs2-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | quantrs2-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d2aab9450c1f43909956fdf85f06d158cba3c073d26df4112f2a6802e6bc1dfa
|
|
BLAKE2b-256 checksum How to use checksums |
117d859073bcfe82aa5489093f02acd9334d05221e99816f5a9c54aef8ef61f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 23, 2026.
Transparency logRelease files / quantrs2-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | quantrs2-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
712e388a6e95f428e1d17071d829f80380f78d1e2ab14983a88fde521de5532e
|
|
BLAKE2b-256 checksum How to use checksums |
42963e5d29945fff3df8033d4617f974213744383e3ac1f64c100d2ea6a472ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 23, 2026.
Transparency logRelease files / quantrs2-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | quantrs2-0.1.2-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
bc1e2f2b7eee33ce4146cd3c9859341ab8ed100257c3b9c7553542e3f8124844
|
|
BLAKE2b-256 checksum How to use checksums |
55eaf9c2033d5e520222d4f61667b14f747edb4628b53d6ad565b0f8dec25d28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 23, 2026.
Transparency logRelease files / quantrs2-0.1.2-cp38-abi3-macosx_10_12_x86_64.whl
| Download URL | quantrs2-0.1.2-cp38-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.8 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
78da34fefff7597e7a8fad1c9f0436aa4ff51778250cf6e964a712647fb5fd9e
|
|
BLAKE2b-256 checksum How to use checksums |
ceedd0004d3bf1156b13edeb2051c9cb36eb8590188cb7740b341b8ca5d12d5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 23, 2026.
Transparency logSecurity for quantrs2 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 7 files in this release have been uploaded with provenance metadata.
Attestation for quantrs2-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.