qopy-patch

qopy-patch

A Python decorator that detects classical algorithms and swaps them for quantum implementations at runtime.

from quantum_jit import qjit

@qjit
def matrix_multiply(a, b):
    return np.dot(a, b)

The decorator analyzes the AST, identifies patterns like matrix multiplication or search loops, benchmarks classical vs quantum, and uses whichever is faster.

Why

I wanted to answer a question: can you make quantum acceleration invisible to the developer?

The pitch for quantum computing is always “rewrite your algorithm.” But most developers won’t. They’ll use numpy, write a for loop, ship it. If quantum is going to matter, it needs to work like a JIT compiler — optimize what’s already there.

This was an experiment to see how far you can get with pattern detection. Parse the function, recognize common structures (Grover-like searches, Fourier transforms, matrix ops), generate equivalent quantum circuits, benchmark, swap if faster.

Does it work?

I tested it on IBM’s quantum hardware. The circuits run correctly. The problem is queue times — you submit a job and wait hours or days unless you’re paying. That makes iterative development impractical. You can’t tune a JIT compiler when each benchmark takes a day to return.

On simulators the overhead of circuit generation eats any theoretical speedup. Real hardware might change the math, but the feedback loop is too slow to find out without spending money.

What I learned

Pattern detection via AST is surprisingly effective. You can recognize a linear search, a matrix multiply, a convolution. The hard part is generating correct quantum circuits — there’s a lot of bookkeeping around qubit allocation and measurement.

The library works. It’s just waiting for hardware access that doesn’t cost a fortune or take forever.