2017-05-17 12:37:53 +08:00
# OpenQASM
2017-09-20 10:24:15 +08:00
2020-11-14 03:21:36 +08:00
2020-11-04 07:10:43 +08:00
OpenQASM is an imperative programming language for describing quantum circuits. It is capable to
2021-05-11 05:23:10 +08:00
describe universal quantum computing using the circuit model, measurement-based model,
2020-11-04 07:10:43 +08:00
and near-term quantum computing experiments.
2017-01-12 02:00:25 +08:00
2020-11-11 23:11:00 +08:00
Specs, examples and tools for the OpenQASM intermediate representation.
## Current version: **3.0**
2020-12-07 09:39:34 +08:00
Live doc: [**version 3.0** ](https://qiskit.github.io/openqasm )
2020-11-11 23:11:00 +08:00
2020-11-11 23:12:21 +08:00
For previous version see: [2.0 ](https://github.com/Qiskit/openqasm/tree/OpenQASM2.x )
2020-11-11 23:11:00 +08:00
2017-01-12 02:00:25 +08:00
## About this project
2017-09-20 10:24:15 +08:00
2021-07-19 21:35:53 +08:00
On this repository, you'll find all the documentation related to OpenQASM, some useful OpenQASM examples, and [plugins for some text editors ](#plugins ).
2017-01-12 02:00:25 +08:00
### Language specs
2020-11-04 07:11:52 +08:00
The live [language documentation ](https://qiskit.github.io/openqasm ) specification.
2017-01-12 02:00:25 +08:00
### Examples
2017-11-09 08:43:38 +08:00
The examples can be found under the [examples ](examples ) folder.
2017-01-12 02:00:25 +08:00
2017-05-17 12:37:53 +08:00
They are OpenQASM files, i.e.:
2017-09-20 10:24:15 +08:00
```text
2020-11-04 04:58:34 +08:00
/*
* Repeat-until-success circuit for Rz(theta),
* cos(theta-pi)=3/5, from Nielsen and Chuang, Chapter 4.
*/
OPENQASM 3;
include "stdgates.inc";
/*
* Applies identity if out is 01, 10, or 11 and a Z-rotation by
* theta + pi where cos(theta)=3/5 if out is 00.
* The 00 outcome occurs with probability 5/8.
*/
2021-05-11 05:23:10 +08:00
def segment qubit[2] anc, qubit psi -> bit[2] {
2020-11-04 04:58:34 +08:00
bit[2] b;
reset anc;
h anc;
ccx anc[0], anc[1], psi;
s psi;
ccx anc[0], anc[1], psi;
z psi;
h anc;
measure anc -> b;
return b;
2017-01-12 02:00:25 +08:00
}
2020-11-04 04:58:34 +08:00
qubit input;
2021-05-11 05:23:10 +08:00
qubit[2] ancilla;
bit[2] flags = "11";
2020-11-04 04:58:34 +08:00
bit output;
reset input;
h input;
2017-09-20 10:24:15 +08:00
2020-11-04 04:58:34 +08:00
// braces are optional in this case
while(int(flags) != 0) {
flags = segment ancilla, input;
}
rz(pi - arccos(3 / 5)) input;
h input;
output = measure input; // should get zero
```
2017-09-20 10:24:15 +08:00
2021-07-19 21:35:53 +08:00
## Plugins
This repository also contains a plugin for working with OpenQASM 2.0 and 3.0 files in vim.
You can find its full documentation in the [plugins/vim ](plugins/vim ) directory.
2017-07-20 08:46:31 +08:00
## Citation format
2017-09-20 10:24:15 +08:00
For research papers, we encourage authors to reference.
2017-07-20 08:46:31 +08:00
2021-05-26 10:48:22 +08:00
- [Version 3.0] Andrew W. Cross, Ali Javadi-Abhari, Thomas Alexander, Niel de Beaudrap, Lev S. Bishop, Steven Heidel, Colm A. Ryan, John Smolin, Jay M. Gambetta, Blake R. Johnson "OpenQASM 3: A broader and deeper quantum assembly language" [[arxiv:2104.14722]](https://arxiv.org/abs/2104.14722).
2021-05-26 10:49:35 +08:00
- [Previous Version: 2.0] Andrew W. Cross, Lev S. Bishop, John A. Smolin, Jay M. Gambetta "Open Quantum Assembly Language" [[arXiv:1707.03429]](https://arxiv.org/abs/1707.03429).
2017-07-20 08:46:31 +08:00
2021-06-17 03:51:42 +08:00
## Governance
The OpenQASM project has a process for accepting changes to the language and making decisions codified in its [governance model ](governance.md ).
2017-01-12 02:00:25 +08:00
## License
2017-09-20 10:24:15 +08:00
This project is licensed under the Apache License 2.0 - see the [LICENSE] file for details.
2017-01-12 02:00:25 +08:00
2017-09-20 10:24:15 +08:00
## Contributing
2017-01-12 02:00:25 +08:00
2017-09-20 10:24:15 +08:00
If you'd like to help please take a look to our [contribution guidelines ](contributing.md ).