Skip to main content

An example library for quantum copy and patch jit

Project description

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

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

qopy_patch-0.1.0.tar.gz (46.3 kB view details)

Uploaded Source

Built Distribution

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

qopy_patch-0.1.0-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

Details for the file qopy_patch-0.1.0.tar.gz.

File metadata

  • Download URL: qopy_patch-0.1.0.tar.gz
  • Upload date:
  • Size: 46.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for qopy_patch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a3b753351c3a6a8ee18959108170f076e735d3dd8931c2aab0f11b5eb7b7c777
MD5 627df02ebb7a282327adbaf1dbf15902
BLAKE2b-256 69bc1d5ea461a8a46775573b1ad03029b4774d5a8a5b12b82e72a272423f48e7

See more details on using hashes here.

File details

Details for the file qopy_patch-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: qopy_patch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 60.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for qopy_patch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfe42ebf2a59e9a2a90cb71ed9397391521ce73bc7770542f081b5c754001c70
MD5 32456d72fb15ba652e67483a89f56f10
BLAKE2b-256 3f5536592edd594f6592fb18cec50aa3fdeab21f20a761314cce682755a84b71

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