What is quantum just-in-time (QJIT) compilation?

What is quantum just-in-time (QJIT) compilation?

Quantum just-in-time compilation is the compilation of hybrid quantum-classical programs during execution of a program, rather than before execution. PennyLane provides just-in-time compilation with its @qml.qjit decorator, powered by the Catalyst compiler.


Many programming languages are commonly implemented as compiled languages, meaning that, before execution, a compiler first translates the human-readable source code into low-level instructions (a binary) that are natively understood by a computer. This binary can then be executed with program input. Examples of compiled languages include C++, Fortran, and Rust.

In contrast, other programming languages are more commonly implemented as interpreted languages. Rather than being compiled ahead-of-time, an interpreter executes the program line-by-line, translating each line of high-level code to machine instructions 'on the fly'. Examples of interpreted languages include Python and JavaScript.

As a general rule of thumb, compiled languages result in better performing code, as the compiler is given time to analyze the entire program to make the best optimizations available. However, this results in less portable code, and requires the programmer to provide more information upfront (such as variable types).

On the other hand, interpreted languages need less information upfront since the program is executed on the fly, which is useful for rapid prototyping. However, execution can be slower than compiled languages.

Just-in-time (JIT) compilation blurs the line between interpreted and compiled languages. In this paradigm, portions of code in an interpreted language are compiled to machine code just before execution, when enough information is available for compilation. When this block is executed again later, the previously optimized compiled block is re-used, with potentially different input. This allows for a nice middle ground between the rapid prototyping capability of interpreted languages, and the speed of compiled languages.

Various languages and packages make use of JIT compilation for this reason. Examples include Julia, JAX, and Numba.

Quantum just-in-time (QJIT) compilation is an extension of this idea, where an entire quantum-classical program — including classical processing and control flow of quantum operations — is compiled just before execution. This enables rapid quantum algorithm prototyping, which can easily be scaled up to run on hardware accelerators (such as GPUs and QPUs).

Examples of quantum software frameworks that support QJIT include PennyLane (via the @qml.qjit decorator and Catalyst) and Nvidia's CUDA Quantum.