Quil

On this page 8

Quil is a quantum instruction language that expresses a quantum program as a flat sequence of gates, measurements, classical memory operations and control-flow instructions, designed to run on a shared quantum-classical machine model. In quantum software, it sits at the level of an assembly language: higher-level tools such as the pyQuil Python library generate Quil, and the quilc compiler rewrites it into the native gate set of a specific superconducting processor.

Quil was introduced in 2016 together with a formal execution model called the Quantum Abstract Machine, and it became the program format of Rigetti quantum processors and simulators. Within quantum computing, it is best understood as an early, explicitly hybrid instruction set architecture, comparable in role to OpenQASM but with its own design choices about memory, parameters and pulse-level extensions.

How Quil models a quantum computer

Quil describes programs for the Quantum Abstract Machine (QAM), a model with three parts: a register of qubits, a classical memory, and a program counter that steps through instructions. Because the classical memory and the qubits belong to one machine, a program can measure a qubit, store the bit and branch on it without leaving the instruction stream.

A Quil program is plain text, one instruction per line. Qubits are addressed by non-negative integer indices, classical memory is declared by name and type, and gates are applied by name with optional parameters, for example RX(pi/2) 0 or CZ 0 1. The machine executes instructions in order, and the result of a run is the contents of classical memory after the final instruction.

The following table lists the main building blocks of the language and what each contributes to a program.

ConstructExamplePurpose
Gate applicationH 0, CNOT 0 1Applies a unitary operation to qubits
Memory declarationDECLARE ro BIT[2]Reserves typed classical memory
MeasurementMEASURE 0 ro[0]Collapses a qubit and stores the bit
Gate definitionDEFGATE with a matrixAdds a custom unitary by name
Control flowLABEL, JUMP-WHENBranches on classical values
ResetRESETReturns qubits to the ground state
PragmaPRAGMA INITIAL_REWIRINGPasses hints to the compiler
Core Quil constructs

Parametric programs and classical memory

One of the most practical features of Quil is parametric compilation. A program can declare a real-valued memory region, such as DECLARE theta REAL, and use it as a gate angle in RZ(theta) 0. The program is compiled once, and different angle values are written into memory before each execution.

This design targets variational algorithms such as VQE and QAOA, in which a classical optimizer adjusts dozens or hundreds of angles across many iterations. Recompiling the circuit for every new parameter set would add seconds of latency per step, so binding parameters at run time reduces the classical overhead of hybrid quantum-classical computing considerably.

Quil memory types are deliberately simple. The table below shows the standard types and their typical role.

TypeTypical useExample declaration
BITSingle measurement outcomesDECLARE ro BIT[4]
OCTETPacked byte-sized dataDECLARE buf OCTET[8]
INTEGERCounters and indicesDECLARE n INTEGER
REALGate angles for parametric programsDECLARE theta REAL[3]
Classical memory types in Quil

Arithmetic instructions such as ADD, MUL and MOVE operate on this memory, and gate modifiers such as DAGGER, CONTROLLED and FORKED derive new gates from existing ones. These modifiers keep programs compact while leaving the decomposition work to the compiler.

The Quil toolchain: pyQuil, quilc and the QVM

Quil rarely appears alone; it is the common format of a toolchain. Developers typically write Python with pyQuil, which builds a Program object and serializes it to Quil text. The quilc compiler then performs gate decomposition, qubit routing and optimization for a target processor, and the result runs either on hardware or on the QVM simulator.

quilc reads the device topology and its native gates, which on Rigetti superconducting chips have historically been `RX` at fixed angles, arbitrary `RZ` and two-qubit `CZ` or `XY` interactions. Arbitrary RZ rotations are implemented as virtual frame changes, so the compiler pushes as much work as possible into them.

ComponentRoleInput and output
pyQuilPython SDK for building programsPython objects to Quil text
quilcOptimizing quantum compilerArbitrary Quil to native Quil
QVMStatevector and density matrix simulatorQuil to simulated results
Quil-TPulse-level language extensionCalibrations, frames and waveforms
quil-rsRust parser and program modelQuil text to typed structures
Components that produce or consume Quil

Quil-T and pulse-level control

Quil-T extends the language with timing and analog control, giving access to pulse-level control of the hardware. It introduces frames (DEFFRAME), waveforms (DEFWAVEFORM), and instructions such as PULSE, CAPTURE, DELAY and FENCE.

With DEFCAL, a user can redefine how a named gate is calibrated, replacing the default microwave pulse for RX(pi/2) on a qubit with a custom shape. This matters for research on optimal control, leakage reduction and characterization experiments, but it also demands detailed knowledge of the device, because poorly designed pulses degrade fidelity quickly.

Quil compared with other quantum languages

Quil, OpenQASM and QIR solve a similar problem at different abstraction levels. The table compares their main design points, which helps explain why toolchains often convert between them.

AspectQuilOpenQASM 3QIR
FormText instruction listText with C-like syntaxLLVM-based representation
Classical controlJumps and labelsStructured loops and branchesFull LLVM control flow
ParametersRun-time memory regionsInput variablesFunction arguments
Pulse extensionQuil-TOpenPulse grammarVendor-specific
Main ecosystemRigetti and pyQuilIBM and broad industryMicrosoft and partners
Quil and related intermediate representations

In practice, OpenQASM has wider industry adoption, and many cloud services accept it as the interchange format. Quil remains relevant as the native format of Rigetti systems and as a cleanly specified example of a hybrid instruction set.

Limitations and common misconceptions

  • Quil is not a high-level language. It has no functions with return values or type inference; abstractions belong in the host language.
  • Unstructured jumps limit analysis. JUMP-WHEN is flexible, but compilers struggle to optimize arbitrary control flow, and hardware may support only restricted mid-circuit feedback.
  • Portability is partial. Native Quil for one chip encodes its topology and gate set, so it will not run unchanged on another device.
  • Simulation does not equal hardware. A program that succeeds on the QVM without a noise model can fail on a real processor because of decoherence and gate errors.

Put simply

Quil is a written list of instructions for a quantum computer. Each line says something small and exact: rotate this qubit, link these two qubits, measure that one and write the answer down.

Programmers usually do not type it by hand. They write Python, and the tools turn it into Quil, much as a word processor turns formatting into a file format. The key idea is that Quil keeps quantum steps and ordinary data in one program, so the computer can measure, remember and decide what to do next.

In practice

A research group studies a small molecule with the variational quantum eigensolver on a superconducting processor. Its pyQuil script builds a circuit with 24 tunable angles stored in a REAL memory region and asks quilc to compile it once for a chain of six qubits.

During optimization, the classical optimizer proposes new angles about 400 times. Each time, the script writes the values into memory and runs the same compiled program for 2,000 shots, so no recompilation happens between steps. Before using hardware time, the team runs the program on the QVM with a noise model to check that the energy estimate behaves sensibly.

The result is a much shorter optimization loop than recompiling at every iteration, and the native Quil output lets the group inspect exactly which gates reached the chip.