openQASM

{{Short description|Intermediate representation for quantum instructions}}

{{primary sources|date=September 2018}}

{{Infobox programming language

| logo =

| logo caption =

| collapsible =

| screenshot =

| screenshot caption =

| sampleCode =

| paradigm =

| family =

| designer =

| developer =

| released =

| latest release version = 3.1.0

| latest release date = {{Start date and age|2024|05|15}}

| latest preview version =

| latest preview date =

| typing =

| scope =

| programming language = Python

| discontinued =

| platform =

| operating system =

| license = Apache License 2.0

| file ext = {{Mono|.qasm}}

| website = {{URL|https://openqasm.com/}}

| implementations =

| dialects =

| influenced by =

| influenced =

}}

Open Quantum Assembly Language (OpenQASM; pronounced open kazm){{cite arXiv|title=Open Quantum Assembly Language|first1=Andrew W.|last1=Cross|first2=Lev S.|last2=Bishop|first3=John A.|last3=Smolin|first4=Jay M.|last4=Gambetta|year=2017|class=quant-ph|eprint=1707.03429}} is a programming language designed for describing quantum circuits and algorithms for execution on quantum computers.

Language

It is designed to be an intermediate representation that can be used by higher-level compilers to communicate with quantum hardware, and allows for the description of a wide range of quantum operations, as well as classical feed-forward flow control based on measurement outcomes.

The language includes a mechanism for describing explicit timing of instructions, and allows for the attachment of low-level definitions to gates for tasks such as calibration. OpenQASM is not intended for general-purpose classical computation, and hardware implementations of the language may not support the full range of data manipulation described in the specification. Compilers for OpenQASM are expected to support a wide range of classical operations for compile-time constants, but the support for these operations on runtime values may vary between implementations.{{cite web|url=https://openqasm.com/intro.html|title=OpenQASM Live Specification|access-date=26 December 2022}}

The language was first described in a paper published in July 2017, and a reference source code implementation was released as part of IBM's Quantum Information Software Kit (Qiskit) for use with their IBM Quantum Experience cloud quantum computing platform.{{Citation|title=qiskit-openqasm: OpenQASM specification|date=2017-07-04|url=https://qiskit.github.io/openqasm/|publisher=International Business Machines|access-date=2017-07-06}} The language has similar qualities to traditional hardware description languages such as Verilog.

OpenQASM defines its version at the head of a source file as a number, as in the declaration: OPENQASM 3;

The level of OpenQASM's original published implementations is OpenQASM 2.0. Version 3.0 of the specification is the current one and can be viewed at the OpenQASM repository on GitHub.https://github.com/openqasm/openqasm OpenQASM

Examples

The following is an example of OpenQASM source code from the official library. The program adds two four-bit numbers.{{cite web|url=https://github.com/openqasm/openqasm/blob/main/examples/adder.qasm|title=openqasm/adder.qasm at master · openqasm/openqasm · GitHub|website=GitHub|date=29 January 2022}}

/*

* quantum ripple-carry adder

* Cuccaro et al, quant-ph/0410184

*/

OPENQASM 3;

include "stdgates.inc";

gate majority a, b, c {

cx c, b;

cx c, a;

ccx a, b, c;

}

gate unmaj a, b, c {

ccx a, b, c;

cx c, a;

cx a, b;

}

qubit[1] cin;

qubit[4] a;

qubit[4] b;

qubit[1] cout;

bit[5] ans;

uint[4] a_in = 1; // a = 0001

uint[4] b_in = 15; // b = 1111

// initialize qubits

reset cin;

reset a;

reset b;

reset cout;

// set input states

for i in [0: 3] {

if(bool(a_in[i])) x a[i];

if(bool(b_in[i])) x b[i];

}

// add a to b, storing result in b

majority cin[0], b[0], a[0];

for i in [0: 2] { majority a[i], b[i + 1], a[i + 1]; }

cx a[3], cout[0];

for i in [2: -1: 0] { unmaj a[i],b[i+1],a[i+1]; }

unmaj cin[0], b[0], a[0];

measure b[0:3] -> ans[0:3];

measure cout[0] -> ans[4];

See also

References

{{reflist}}