Qopy Patch
Quantum Copy-and-Patch JIT
A Python library for detecting classical algorithms that could benefit from quantum acceleration and dynamically replacing them with quantum implementations. Just does pattern detection via ASTs currently uses QisKit, but could use other libraries with effort.
Overview
Quantum Copy-and-Patch JIT analyzes your Python functions at runtime to identify common patterns that are suitable for quantum acceleration, such as matrix multiplication, Fourier transforms, search algorithms, and more. When beneficial, it can automatically replace classical implementations with quantum versions.
Key features:
- Automatic detection of quantum-accelerable patterns in your code
- Performance benchmarking to ensure quantum implementations are only used when they provide a speedup
- Circuit caching to reduce overhead for repeated function calls
- Visualization tools to understand which functions are being accelerated
Installation
pip install qopy-patch
Basic Usage
Simply add the @qjit decorator to functions you want to potentially accelerate:
import numpy as np
from quantum_jit import qjit
@qjit
def matrix_multiply(a, b):
return np.dot(a, b)
# First call benchmarks classical vs quantum
result = matrix_multiply(np.random.rand(4, 4), np.random.rand(4, 4))
# Subsequent calls may use quantum if faster
result = matrix_multiply(np.random.rand(4, 4), np.random.rand(4, 4))
Supported Patterns
The library can currently detect and accelerate these algorithm patterns:
- Matrix multiplication
- Fourier transforms
- Search algorithms (similar to Grover's algorithm)
- Binary optimization problems
- General linear algebra operations
Visualization
To visualize which functions are being quantum-accelerated:
from quantum_jit import visualize_all
# Run your quantum-accelerated functions...
# Then generate visualizations
visualize_all(output_dir="./quantum_viz")
This generates graphs showing:
- Which functions have been quantum-accelerated
- The confidence of pattern detection
- Performance comparisons between classical and quantum implementations
- Speedup trends across multiple function calls
Limitations
This library has some important limitations to be aware of:
- Experimental: This is research software and not intended for production use.
- Performance: Current quantum implementations may not actually be faster than classical ones on available hardware/simulators.
- Limited Pattern Detection: Only recognizes specific algorithm patterns.
- Quantum Simulation: Runs on quantum simulators by default, not actual quantum hardware.
- Hardware Requirements: Visualizations require additional dependencies (matplotlib, pandas, etc.).
Example
import numpy as np
from quantum_jit import qjit, visualize_all
@qjit
def search_function(items, target):
"""Search algorithm pattern."""
for i, item in enumerate(items):
if item == target:
return i
return -1
# Run the function a few times
items = list(range(10, 30))
target = 15
result = search_function(items, target)
# Generate visualizations
visualize_all()
License
MIT License
Requirements
- Python 3.13+
- NumPy
- Qiskit
- Qiskit Aer (for simulation)
For visualization:
- Matplotlib
- Pandas
- Seaborn
- NetworkX
Metadata
Release files for qopy-patch 0.1.0
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 | |
|---|---|---|---|---|
| qopy_patch-0.1.0.tar.gz | 46.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qopy_patch-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 106.9 kB
Release files / qopy_patch-0.1.0.tar.gz
| Download URL | qopy_patch-0.1.0.tar.gz |
|---|---|
| Size | 46.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a3b753351c3a6a8ee18959108170f076e735d3dd8931c2aab0f11b5eb7b7c777
|
|
BLAKE2b-256 checksum How to use checksums |
69bc1d5ea461a8a46775573b1ad03029b4774d5a8a5b12b82e72a272423f48e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / qopy_patch-0.1.0-py3-none-any.whl
| Download URL | qopy_patch-0.1.0-py3-none-any.whl |
|---|---|
| Size | 60.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfe42ebf2a59e9a2a90cb71ed9397391521ce73bc7770542f081b5c754001c70
|
|
BLAKE2b-256 checksum How to use checksums |
3f5536592edd594f6592fb18cec50aa3fdeab21f20a761314cce682755a84b71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for qopy-patch 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.