- Fundamentals
- Also: Quantum Instruction Language
Quil
Rigetti's quantum instruction language, a human-readable assembly language for specifying quantum circuits with support for classical control flow and custom gate definitions.
Quil (Quantum Instruction Language) is a quantum assembly language developed by Rigetti Computing for describing quantum programs at a low level. It serves as the instruction set for Rigetti’s Quil-T execution environment and is the underlying representation used by PyQuil, Rigetti’s Python SDK. Quil occupies a similar role to OpenQASM (IBM’s quantum assembly language) but with different design choices, particularly around classical control flow and parametric gate definitions.
Quil syntax
A Quil program is a sequence of instructions that operate on qubits (indexed by non-negative integers) and classical memory (declared via DECLARE). Here is a simple example that creates a Bell state and measures it:
DECLARE ro BIT[2] # Declare 2 classical bits for readout
H 0 # Hadamard on qubit 0
CNOT 0 1 # CNOT with control=0, target=1
MEASURE 0 ro[0] # Measure qubit 0 into ro[0]
MEASURE 1 ro[1] # Measure qubit 1 into ro[1]
Key syntactic elements include:
- Gate application:
GATE qubit [qubit ...]for built-in gates (H, CNOT, RZ, etc.) - Parameterized gates:
RZ(0.5) 0applies an Rz rotation of radians to qubit 0 - Classical memory:
DECLARE name TYPE[size]allocates classical registers - Measurement:
MEASURE qubit addrmeasures a qubit and stores the result - Classical control:
JUMP,JUMP-WHEN,JUMP-UNLESSenable conditional branching based on classical bits
Custom gate definitions
Quil allows users to define custom gates using the DEFGATE directive, specifying the gate’s unitary matrix directly:
DEFGATE MYGATE:
1/sqrt(2), 1/sqrt(2)
1/sqrt(2), -1/sqrt(2)
MYGATE 0
This defines a gate with the Hadamard matrix and applies it to qubit 0. Parametric custom gates are also supported:
DEFGATE PHASE(%theta):
1, 0
0, cis(%theta)
PHASE(pi/4) 0
The cis function represents , and %theta is a parameter that can be set at runtime.
Classical control flow
One area where Quil differs significantly from early versions of OpenQASM is classical control flow. Quil supports conditional jumps based on measurement outcomes:
DECLARE ro BIT[1]
DECLARE flag BIT[1]
H 0
MEASURE 0 ro[0]
MOVE flag[0] ro[0]
JUMP-WHEN @DONE flag[0]
X 0 # Apply X if measurement was 0
LABEL @DONE
MEASURE 0 ro[0]
This enables mid-circuit measurement and feed-forward, where subsequent gates depend on earlier measurement outcomes. This capability is essential for quantum error correction, teleportation-based gates, and certain adaptive algorithms.
Quil-T: pulse-level control
Quil-T extends Quil with pulse-level instructions, giving users direct control over the microwave pulses that implement gates on Rigetti’s superconducting hardware:
DEFFRAME 0 "rf":
SAMPLE-RATE: 1e9
CENTER-FREQUENCY: 5.2e9
PULSE 0 "rf" gaussian(duration: 50e-9, fwhm: 20e-9, t0: 25e-9)
This level of control is useful for calibration experiments, custom gate design, and noise characterization, but most users interact with Quil at the gate level through PyQuil.
Comparison with OpenQASM
| Feature | Quil | OpenQASM 3.0 |
|---|---|---|
| Gate syntax | GATE qubit | gate qubit; |
| Classical control | JUMP-WHEN labels | if statements, loops |
| Custom gates | DEFGATE with matrix | gate with decomposition |
| Pulse control | Quil-T extension | OpenPulse extension |
| Primary platform | Rigetti | IBM |
| Classical types | BIT, REAL, INTEGER, OCTET | Full classical type system |
OpenQASM 3.0 has a more expressive classical type system and control flow, while Quil’s design is closer to a traditional assembly language with explicit jumps and labels.
Why it matters for learners
Quil provides insight into how quantum programs are represented at a level close to hardware execution. Understanding Quil (even if you primarily use Qiskit or Cirq) builds intuition for what the compiler and transpiler do behind the scenes: every high-level quantum program is ultimately lowered to a sequence of gate instructions, measurements, and classical control operations similar to Quil or OpenQASM. Familiarity with multiple quantum assembly languages also helps when comparing results across different hardware platforms.