Jump to content

OpenQASM: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Monkbot (talk | contribs)
m Task 18 (cosmetic): eval 3 templates: hyphenate params (1×);
Copyedit. Date formats.
 
(17 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Short description|Intermediate representation for quantum instructions}}
{{primary sources|date=September 2018}}
{{primary sources|date=September 2018}}
{{Infobox programming language
'''Open Quantum Assembly Language''' ('''OpenQASM'''; pronounced ''open kazm''<ref name=Cross>{{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|arxiv=1707.03429}}</ref>) is an [[intermediate representation]] for quantum instructions. The language was first described in a paper published in July 2017,<ref name=Cross/> and a reference source code implementation was released as part of [[IBM]]'s Quantum Information Software Kit ([[Qiskit]]) for use with their [[IBM Q Experience]] cloud quantum computing platform.<ref>{{Citation|title=qiskit-openqasm: OpenQASM specification|date=2017-07-04|url=https://github.com/IBM/qiskit-openqasm|publisher=International Business Machines|access-date=2017-07-06}}</ref> The language has similar qualities to traditional [[hardware description language]]s such as [[Verilog]].
| logo = <!-- (filename) -->
| logo caption =
| collapsible = <!-- to make screenshot collapsible -->
| screenshot = <!-- (filename) -->
| screenshot caption =
| sampleCode =
| paradigm = <!-- or: | paradigms = -->
| family =
| designer = <!-- or: | designers = -->
| developer = <!-- or: | developers = -->
| released = <!-- or: | year = --> <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} -->
| latest release version =
| latest release date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} -->
| latest preview version =
| latest preview date = <!-- {{Start date and age|YYYY|MM|DD|df=yes/no}} -->
| typing =
| scope =
| programming language =
| discontinued =
| platform =
| operating system =
| license = [[Apache License]] 2.0
| file ext = <code>.qasm</code>
| website = {{URL|https://openqasm.com/}}
| implementations =
| dialects =
| influenced by =
| influenced =
}}
'''Open Quantum Assembly Language''' ('''OpenQASM'''; pronounced ''open kazm''<ref name=Cross>{{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}}</ref>) is a programming language designed for describing quantum circuits and algorithms for execution on quantum computers. 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.<ref name=Cross/> 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.<ref>{{cite web|url=https://openqasm.com/intro.html|title=OpenQASM Live Specification|access-date=26 December 2022}}</ref>
OpenQASM defines its version at the head of a source file as a real number, as in the declaration: <syntaxhighlight lang="verilog">OPENQASM 2.0;</syntaxhighlight>


The language was first described in a paper published in July 2017,<ref name=Cross/> 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-based quantum computing|cloud quantum computing]] platform.<ref>{{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}}</ref> The language has similar qualities to traditional [[hardware description language]]s such as [[Verilog]].
The level of OpenQASM's original published implementations (e.g., Qiskit, ''infra'') is OpenQASM 2.0. The 3.0 level of the specification is currently work in progress and can be viewed at the [https://github.com/qiskit/openqasm OpenQASM] repository on ''GitHub''.

OpenQASM defines its version at the head of a source file as a number, as in the declaration: <syntaxhighlight lang="verilog">OPENQASM 3;</syntaxhighlight>

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 [https://github.com/openqasm/openqasm OpenQASM] repository on ''GitHub''.


== Examples ==
== Examples ==
The following is an example of OpenQASM source code from the official library. The program adds two four-bit numbers.<ref>{{cite web|url=https://github.com/QISKit/openqasm/blob/master/examples/generic/adder.qasm|title=openqasm/adder.qasm at master · QISKit/openqasm · GitHub}}</ref>
The following is an example of OpenQASM source code from the official library. The program adds two four-bit numbers.<ref>{{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}}</ref>


<syntaxhighlight lang="verilog">
<syntaxhighlight lang="systemverilog">
/*
// quantum ripple-carry adder from Cuccaro et al, quant-ph/0410184
* quantum ripple-carry adder
OPENQASM 2.0;
* Cuccaro et al, quant-ph/0410184
include "qelib1.inc";
*/
gate majority a,b,c
OPENQASM 3;
{
include "stdgates.inc";
cx c,b;

cx c,a;
ccx a,b,c;
gate majority a, b, c {
cx c, b;
cx c, a;
ccx a, b, c;
}
}

gate unmaj a,b,c
gate unmaj a, b, c {
{
ccx a,b,c;
ccx a, b, c;
cx c,a;
cx c, a;
cx a,b;
cx a, b;
}
}

qreg cin[1];
qreg a[4];
qubit[1] cin;
qreg b[4];
qubit[4] a;
qubit[4] b;
qreg cout[1];
qubit[1] cout;
creg ans[5];
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
// set input states
for i in [0: 3] {
x a[0]; // a = 0001
if(bool(a_in[i])) x a[i];
x b; // b = 1111
if(bool(b_in[i])) x b[i];
}
// add a to b, storing result in b
// add a to b, storing result in b
majority cin[0],b[0],a[0];
majority cin[0], b[0], a[0];
majority a[0],b[1],a[1];
for i in [0: 2] { majority a[i], b[i + 1], a[i + 1]; }
majority a[1],b[2],a[2];
cx a[3], cout[0];
majority a[2],b[3],a[3];
for i in [2: -1: 0] { unmaj a[i],b[i+1],a[i+1]; }
cx a[3],cout[0];
unmaj cin[0], b[0], a[0];
unmaj a[2],b[3],a[3];
measure b[0:3] -> ans[0:3];
unmaj a[1],b[2],a[2];
unmaj a[0],b[1],a[1];
unmaj cin[0],b[0],a[0];
measure b[0] -> ans[0];
measure b[1] -> ans[1];
measure b[2] -> ans[2];
measure b[3] -> ans[3];
measure cout[0] -> ans[4];
measure cout[0] -> ans[4];
</syntaxhighlight>
</syntaxhighlight>
Line 54: Line 96:


== External links ==
== External links ==
* {{Official website|https://openqasm.com/}}
* [https://github.com/qiskit/openqasm OpenQASM] on ''GitHub''
* {{GitHub|openqasm/openqasm}}


{{quantum computing}}
{{quantum computing}}
{{IBM}}
{{Use dmy dates|date=June 2024}}



[[Category:Programming languages]]
[[Category:Programming languages]]
[[Category:Quantum information science]]
[[Category:Quantum computing]]
[[Category:Quantum computing]]
[[Category:Quantum programming]]
[[Category:Quantum programming]]

Latest revision as of 20:00, 1 June 2024

OpenQASM
LicenseApache License 2.0
Filename extensions.qasm
Websiteopenqasm.com

Open Quantum Assembly Language (OpenQASM; pronounced open kazm[1]) is a programming language designed for describing quantum circuits and algorithms for execution on quantum computers. 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.[1] 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.[2]

The language was first described in a paper published in July 2017,[1] 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.[3] 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.

Examples

[edit]

The following is an example of OpenQASM source code from the official library. The program adds two four-bit numbers.[4]

/*
 * 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];

References

[edit]
  1. ^ a b c Cross, Andrew W.; Bishop, Lev S.; Smolin, John A.; Gambetta, Jay M. (2017). "Open Quantum Assembly Language". arXiv:1707.03429 [quant-ph].
  2. ^ "OpenQASM Live Specification". Retrieved 26 December 2022.
  3. ^ qiskit-openqasm: OpenQASM specification, International Business Machines, 4 July 2017, retrieved 6 July 2017
  4. ^ "openqasm/adder.qasm at master · openqasm/openqasm · GitHub". GitHub. 29 January 2022.
[edit]