Code
qcr:2604.08928.1

Constant-time hybrid compilation of Shor's algorithm with quantum just-in-time compilation

Continuous improvements in quantum computing hardware are exposing the need for simultaneous advances in software. Large-scale implementation of quantum algorithms requires rapid and automated compilation routines such as circuit synthesis and optimization. As systems move towards fault-tolerance, programming frameworks and compilers must also be capable of compiling and optimizing programs comprising both classical and quantum code. This work takes a step in that direction by providing an implementation of Shor's factoring algorithm, compiled to elementary quantum gates using PennyLane and Catalyst, a library for quantum just-in-time (QJIT) compilation of hybrid workflows. We demonstrate that with QJIT compilation, the algorithm is compiled once per bit width of , the integer being factored, even when -specific optimizations are applied to circuit generation based on values determined at runtime. The implementation is benchmarked up to 32-bit , and both the size of the compiled program and the pure compilation time are found to be constant (under 3 seconds on a laptop computer), meaning code generation becomes tractable even for realistic problem sizes.
Compilation
Qubit
Circuit-based
Superconducting qubits
Uploaded 2 months ago
84
Views
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

QSAR-UBC/shortalyst
30
README.md

Shortalyst

Code and benchmark scripts for the paper, "Constant-time hybrid compilation of Shor’s algorithm with quantum just-in-time compilation", by David Ittah (@dime10), Jackson Fraser (@JacksonnF), Josh Izaac (@josh146), and Olivia Di Matteo (@glassnotes).

Usage

General usage

To run the quantum just-in-time-compiled version of Shor's algorithm out-of-the-box, you can pass it a number to factor, N, and a random integer a between 2 and N-2 (inclusive).

import jax.numpy as jnp

from shortalyst.shors_algorithm import shors_algorithm

N = 35
a = 2
n_bits = int(jnp.floor(jnp.log2(N))) + 1
n_trials = 100

p, q, success_prob, _, _ = shors_algorithm(N, a, n_bits, n_trials)

print(f"p = {p}, q = {q}, success_prob = {success_prob:.4f}")

A random a can also be generated by passing a JAX PRNGKey as a keyword argument (see docstring for details).

Installation

Dependencies are listed in the pyproject.toml file and can be installed via

$ pip install -e .

or a tool such as Poetry. pytest is required for the suite of unit tests in tests/.

Replication

Code for generating the set of plots shown in the paper can be found in the compilation-benchmarking.ipynb notebook.

To obtain the gate counts, a custom version of Catalyst is currently required. Please clone and checkout the shortalyst tag from the official Catalyst repository, and follow the build from the source instructions available in the documentation.

Alternatively, the data files used for the paper can be found in data/.

Acknowledgments

If you use our code in your own work, please cite our preprint:

@misc{ittah2025constanttimehybridcompilationshors,
      title={Constant-time hybrid compilation of Shor's algorithm with quantum just-in-time compilation}, 
      author={David Ittah and Jackson Fraser and Josh Izaac and Olivia {Di Matteo}},
      year={2025},
      eprint={2504.12449},
      archivePrefix={arXiv},
      primaryClass={quant-ph},
      url={https://arxiv.org/abs/2504.12449}, 
}

This work is a collaboration between the UBC Quantum Software and Algorithms Research Lab, and members of the PennyLane and Catalyst teams at Xanadu.

It is based in part on the PennyLane demo, Quantum just-in-time compiling Shor’s algorithm with PennyLane and Catalyst.

The QSAR Lab acknowledges funding from an NSERC Alliance Quantum grant, the Canada Research Chairs program, and the Electrical and Computer Engineering Department at UBC.

Join the Discussion

Comments (0)

No comments yet. Be the first to share your thoughts!

Indexed by QCR Librarian

This entry was created automatically from publicly available records. QCR links to public sources and only stores repository content where the license permits redistribution.

Versions

v1 Latest
Apr 15, 2026
qcr:2604.08928.1

Cite all versions? Use the base QCR ID to always reference the latest version of this entry.

Tools used

PennyLane

Keywords

short
qijt

You may also like5