Git Product home page Git Product logo

openpulse-python's Introduction

OpenQASM

OpenQASM is an imperative programming language for describing quantum circuits. It is capable of describing universal quantum computing using the circuit model, measurement-based model, and near-term quantum computing experiments.

This repo contains the OpenQASM specification, examples, and tools for the OpenQASM intermediate representation.

OpenQASM is a Qiskit project.

Current version: 3.0

About this project

In this repository, you'll find all the documentation related to OpenQASM, some useful OpenQASM examples, and plugins for some text editors.

Language specs

The live language documentation specification.

Examples

An example of OpenQASM 3.0 source code is given below. Several more examples may be found in the examples folder.

/*
 * 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.
 */
def segment qubit[2] anc, qubit psi -> bit[2] {
  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;
}

qubit input;
qubit[2] ancilla;
bit[2] flags = "11";
bit output;

reset input;
h input;

// 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

Citation format

For research papers, we encourage authors to reference.

  • [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].
  • [Previous Version: 2.0] Andrew W. Cross, Lev S. Bishop, John A. Smolin, Jay M. Gambetta "Open Quantum Assembly Language" [arXiv:1707.03429].

Governance

The OpenQASM project has a process for accepting changes to the language and making decisions codified in its governance model.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Contributing

If you'd like to help please take a look to our contribution guidelines. This project adheres to a Code of Conduct. By participating, you are expected to uphold this code.

Release Notes

See the section on Release Notes contribution guidelines.

openpulse-python's People

Contributors

aspcompiler avatar braised-babbage avatar jakelishman avatar psivaraj avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openpulse-python's Issues

Consider adding a global `delay`, or otherwise clarifying the spec

The spec makes explicit provisions for global barrier statements, but there is no mention of any equivalent for delay. This could be convenient to add. Strictly speaking, if we supported this in the OpenPulse spec, this would apply to delay instructions within cal blocks, and would not apply to delay instructions outside of cal blocks (which retain the existing OpenQASM semantics). We should poll the TSC to see whether this would be reasonable to support at the OpenQASM level.

Parser fails in the presence of brace in comment

The following OpenPulse program fails to parse

cal {
  // while(true) {
  int x;
}

The error I see is

In [10]: parse("""cal {
    ...: // while(true) {
    ...: int x;
    ...: }
    ...: """)
---------------------------------------------------------------------------
ParseCancellationException                Traceback (most recent call last)
File ~/source/interpres/.venv/lib/python3.10/site-packages/openqasm3/parser.py:87, in parse(input_, permissive)
     86 try:
---> 87     tree = parser.program()
     88 except (RecognitionException, ParseCancellationException) as exc:

File ~/source/interpres/.venv/lib/python3.10/site-packages/openqasm3/_antlr/_4_11/qasm3Parser.py:640, in qasm3Parser.program(self)
    639 self.state = 131
--> 640 self.statement()
    641 self.state = 136

File ~/source/interpres/.venv/lib/python3.10/site-packages/openqasm3/_antlr/_4_11/qasm3Parser.py:919, in qasm3Parser.statement(self)
    918 self.state = 155
--> 919 self.calStatement()
    920 pass

File ~/source/interpres/.venv/lib/python3.10/site-packages/openqasm3/_antlr/_4_11/qasm3Parser.py:3352, in qasm3Parser.calStatement(self)
   3351     self.state = 423
-> 3352     self.match(qasm3Parser.RBRACE)
   3353 except RecognitionException as re:

File ~/source/interpres/.venv/lib/python3.10/site-packages/antlr4/Parser.py:126, in Parser.match(self, ttype)
    125 else:
--> 126     t = self._errHandler.recoverInline(self)
    127     if self.buildParseTrees and t.tokenIndex==-1:
    128         # we must have conjured up a new token during single token insertion
    129         # if it's not the current symbol

File ~/source/interpres/.venv/lib/python3.10/site-packages/antlr4/error/ErrorStrategy.py:703, in BailErrorStrategy.recoverInline(self, recognizer)
    702 def recoverInline(self, recognizer:Parser):
--> 703     self.recover(recognizer, InputMismatchException(recognizer))

File ~/source/interpres/.venv/lib/python3.10/site-packages/antlr4/error/ErrorStrategy.py:697, in BailErrorStrategy.recover(self, recognizer, e)
    696     context = context.parentCtx
--> 697 raise ParseCancellationException(e)

ParseCancellationException: None

Note that the OpenQASM parser doesn't have a problem with the following

while (true) {
  // while(true) {
  int x;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.