Source-linked AI summary

Open Quantum Assembly Language

Andrew W. Cross, Lev S. Bishop, John A. Smolin, Jay M. Gambetta

arXiv:1707.03429v2quant-ph

TL;DR

OpenQASM addresses the need for an interface language for low-depth quantum experiments that coordinates quantum and classical computation. It specifies a quantum circuit intermediate representation with universal physical gates, subroutines, measurement, reset, and feedback, and demonstrates its use in circuit examples and randomized benchmarking. The execution model remains bounded because fully general classical computation cannot run in the loop while qubits retain coherence.

  • Problem

    OpenQASM provides an interface language for implementing low-depth quantum experiments while coordinating quantum and classical parts of computation.

  • Method

    The document specifies a quantum circuit intermediate representation using universal single- and two-qubit gates, gate subroutines, measurement, reset, and fast feedback.

  • Results

    OpenQASM expresses quantum teleportation, inverse-QFT measurement, randomized benchmarking, and simple quantum error-correction circuits.

  • Takeaways & Limitations

    The text language can be generated by tools or written by hand and targeted to the Quantum Experience for small-depth circuit experiments.

  • Takeaways & Limitations

    The Quantum Experience model does not allow fully general classical computations in the loop because qubits remain coherent for a limited time.

Abstract

from arXiv · show

This document describes a quantum assembly language (QASM) called OpenQASM that is used to implement experiments with low depth quantum circuits. OpenQASM represents universal physical circuits over the CNOT plus SU(2) basis with straight-line code that includes measurement, reset, fast feedback, and gate subroutines. The simple text language can be written by hand or by higher level tools and may be executed on the IBM Q Experience.

1 Background

The document introduces OpenQASM as a quantum circuit intermediate representation and interface language for executing low-depth experiments. It organizes quantum-program processing across compilation, circuit generation, execution, and post-processing while supporting physical gates, subroutines, measurement, reset, and fast feedback.

  • Execution model: Quantum-program processing is divided into offline compilation, online circuit generation, real-time execution, and post-processing of measurement results.Intermediate representations connect these phases and distinguish source programs from executable instructions.
  • Execution model: The Quantum Experience model disallows fully general classical computation inside quantum computation because qubits remain coherent only for a limited time.Users instead coordinate successive circuits through a high-level controller and may post-process results offline.
  • Quantum circuit representation: OpenQASM is a human-readable quantum circuit intermediate representation for generic, fully specified circuits with parameterized physical gates.The representation sits between source-language descriptions and target machine instructions.
  • Quantum circuit representation: Its built-in basis combines arbitrary single-qubit gates with the two-qubit entangling gate CNOT to represent universal physical circuits.Hardware-supported operations can be specified through standard header files.
  • Language design: Gate subroutines hierarchically define new unitary gates from built-in gates and previously defined subroutines, providing limited code reuse.The language deliberately omits higher-level programming primitives.
  • Language design: The language includes measurement, state reset, and elemental classical feedback, while quantum circuit basic blocks use straight-line code with fast-feedback instructions.These statements model the quantum-classical interface needed for near-term experiments.

2 Language

OpenQASM 2.0 is a case-sensitive text language for universal physical circuits, built around CNOT and parameterized single-qubit gates. It supports gate subroutines, parallel register operations, measurement, reset, and classical conditional execution.

  • Syntax: OpenQASM 2.0 programs use a version declaration, semicolon-separated statements, ignored whitespace, and C++-style comments.The language is case sensitive, and include statements continue parsing a referenced file relative to the current working directory.
  • Built-in gates: The universal built-in gate basis is CNOT plus arbitrary single-qubit U(θ, φ, λ) gates.U(θ, φ, λ) parameterizes any SU(2) element; its parameters range over [0, 4π) and support arithmetic expressions.
  • Built-in gates: CX a,b; flips target b if and only if control a is one, and register arguments apply corresponding CNOT gates elementwise.A qubit-to-register or register-to-qubit call applies the gate across the register indices; the two arguments cannot refer to the same qubit.
  • Gate subroutines: User-defined gates are unitary subroutines declared before use, with optional parameters, required qubit arguments, scoped symbols, and bodies restricted to built-in gates, earlier gates, and barriers.Their invocation uses name(params) qargs;, and an empty body denotes the identity gate.
  • Measurement and control: Measurement projects qubits onto the Z-basis, overwrites classical bits with outcomes, and leaves the qubits available for further computation.Reset prepares a qubit or register in |0⟩, while if conditionally executes a quantum operation when a classical register equals a specified integer.

3 Examples

The examples section presents Open QASM 2.0 circuits using a Quantum Experience gate basis, whose physical operations are defined through abstract U and CX gates. The standard header also supplies user-defined gates and decompositions for common controlled operations and rotations.

  • The examples use a gate basis defined for the Quantum Experience.
  • Physical hardware gates are defined in terms of abstract U and CX gates, allowing physical gates to be added or changed.
  • The one-parameter gate changes a carrier's phase without applying pulses, while the three-parameter gate uses two π/2-pulses.
  • The hardware primitives include three single-qubit gates, u3, u2, and u1, plus controlled-NOT and identity gates.
  • The standard header defines Pauli, Clifford, C3, and rotation gates through u1, u2, u3, and CX subroutines.
  • User-defined controlled gates, including cz, cy, ch, ccx, crz, cu1, and cu3, are decomposed into the standard primitives.

3.2 Quantum teleportation

The teleportation example demonstrates conditional application of later gates based on earlier measurement outcomes. It prepares a state, teleports it across a three-qubit circuit, and applies classically controlled corrections before final measurement.

  • Quantum teleportation demonstrates conditional application of future gates based on prior measurement outcomes.
  • The circuit prepares q[0] with U(0.3,0.2,0.1) and teleports its state to q[2].
  • After measuring q[0] and q[1], the circuit conditionally applies z and x corrections to q[2].
  • The corrected state is optionally post-rotated for tomography and then measured into c2[0].

3.3 Quantum Fourier transform

The four-qubit QFT example demonstrates parameter passing to gate subroutines by applying controlled phase rotations to the input state |1010⟩. The circuit then measures the result in the computational basis with reversed classical output order.

  • The circuit applies a four-qubit QFT to |1010⟩ and measures in the computational basis.
  • The measured output is read in reverse order c[3], c[2], c[1], c[0].
  • Hadamard gates and cu1 rotations with parameters π/2, π/4, and π/8 implement the QFT interactions.

3.4 Inverse QFT followed by measurement

The inverse-QFT example replaces controlled phase rotations with classically controlled single-qubit rotations after measurement, exploiting their commutation with measurement. Two equivalent Open QASM implementations illustrate compact conditions versus decomposed rotations.

  • After inverse-QFT measurements, the cu1 controls commute with measurement and can be replaced by classically controlled single-qubit rotations.
  • Version 1: The first implementation stores all four measurement results in one classical register and conditions later rotations on register values.
  • The circuit example is presented as an inverse QFT followed by measurement.
  • The rotations can instead be decomposed into fewer statements at the cost of using more quantum gates.
  • Version 2: The alternative implementation uses four one-bit classical registers and applies separate conditional rotations from earlier measurement results.

3.5 Ripple-carry adder

The ripple-carry adder example demonstrates hierarchical gate-subroutine use in OpenQASM. It defines majority and unmaj subroutines, applies them across registers, and measures the resulting sum.

  • 3.5 Ripple-carry adder: The adder exhibits hierarchical use of gate subroutines.The example is identified as the quantum ripple-carry adder from Cuccaro et al.
  • 3.5 Ripple-carry adder: OpenQASM defines majority and unmaj gate subroutines from CNOT and Toffoli operations.The majority subroutine uses cx and ccx operations, while unmaj uses cx operations.
  • 3.5 Ripple-carry adder: The circuit initializes a carry register and four-bit registers, applies majority gates forward, then unmaj gates backward.A CNOT connects the final carry to cout before the reverse unmaj sequence restores intermediate structure.
  • 3.5 Ripple-carry adder: The example measures the four result bits and the output carry into a five-bit classical register.The inputs are set with x operations before addition, with the sum stored in b.

3.6 Randomized benchmarking

Randomized benchmarking is represented as many independent quantum circuits generated from random Clifford sequences. OpenQASM supports the required gate definitions, barriers, and measurement structure for these sequences.

  • 3.6 Randomized benchmarking: A randomized benchmarking experiment becomes many quantum circuits with associated classical control and no data dependence between circuits.This makes benchmarking a particularly simple example of a high-level program passing through compilation.
  • 3.6 Randomized benchmarking: Each circuit consists of random Clifford gates composed from a basic gate set such as h, s, cz, and Pauli gates.Additional gates can be defined with the gate statement when the required set differs from the built-in set.
  • 3.6 Randomized benchmarking: Barrier instructions separate randomly chosen Clifford gates to prevent later transformations from simplifying the sequence to the identity.The example sequence places barriers between gate groups before measuring both qubits.
  • 3.6 Randomized benchmarking: An RB experiment runs many sequences, with each sequence executed for a specified number of shots.Figure 12 illustrates a two-qubit sequence over the basis ⟨H, S, CZ, X, Y, Z⟩.

3.7 Quantum process tomography

Quantum process tomography is expressed through a high-level program that generates several independent OpenQASM circuits. The circuits differ in their pre- and post-gate definitions, and measurement statistics reconstruct the process under study.

  • 3.7 Quantum process tomography: A high-level QPT program compiles into several independent quantum circuits, each expressible in OpenQASM 2.0.The example performs tomography of a Hadamard gate.
  • 3.7 Quantum process tomography: The circuits are identical except for their pre- and post-gate definitions.Empty definitions in the example serve as placeholders for identity gates.

3.8 Quantum error-correction

The three-bit repetition-code example shows that OpenQASM 2.0 can express a simple quantum error-correction circuit. It encodes syndrome measurement and measurement-dependent feedback to correct a bit-flip error.

  • 3.8 Quantum error-correction: The example uses a three-bit quantum repetition code to demonstrate simple quantum error-correction circuits in OpenQASM 2.0.The circuit includes three quantum data registers, two ancillas, and classical registers for results and syndrome values.
  • 3.8 Quantum error-correction: The circuit measures a two-bit syndrome through a dedicated syndrome gate acting on the three data qubits and two ancillas.The syndrome gate is built from four CNOT operations before the ancillas are measured.
  • 3.8 Quantum error-correction: Syndrome-dependent if statements apply different X corrections after an X error is introduced on q[0].The circuit applies corrections to q[0], q[2], or q[1] for syndrome values 1, 2, or 3, respectively.

A Open QASM Grammar

The Open QASM grammar defines program structure, declarations, gate bodies, operations, and parameter expressions in Backus-Naur form. Grammar-generated strings still require additional validity rules and operator-precedence handling.

  • Program structure: The grammar defines Open QASM programs as sequences of declarations, gate declarations, opaque gates, quantum operations, conditionals, and barriers.It also includes quantum- and classical-register declarations and gate subroutine bodies.
  • Expressions: Expressions support real numbers, nonnegative integers, pi, identifiers, arithmetic operators, exponentiation, parentheses, and unary functions.The listed unary functions are sin, cos, tan, exp, ln, and sqrt.
  • Lexical forms: Identifiers begin with a lowercase letter and may contain letters, digits, and underscores, while real and nonnegative-integer literals follow regular-expression definitions.The grammar specifies decimal forms with optional scientific notation for real values.
  • Validity constraints: The grammar is simplified, and syntactically generated programs may still violate rules for arguments, parameters, declarations, identifiers, or operator precedence.Validity therefore requires constraints beyond the productions shown in the grammar.
Loading 1707.03429v2…