Importer for parsing OpenQASM 2 strings into Qiskit circuits
Project description
Importer from OpenQASM 2 to Qiskit
This repository provides the Python package qiskit_qasm2
, which provides a
fast parser of OpenQASM 2 into Qiskit's QuantumCircuit
. It is often 10x or
more faster than Qiskit's native parser. The API is simple:
qiskit_qasm2.load
takes a filename, and returnsQuantumCircuit
;qiskit_qasm2.loads
takes an OpenQASM 2 program in a string, and returnsQuantumCircuit
.
For example:
import qiskit_qasm2
program = """
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];
h q[0];
cx q[0], q[1];
measure q -> c;
"""
qiskit_qasm2.loads(program).draw()
┌───┐ ┌─┐
q_0: ┤ H ├──■──┤M├───
└───┘┌─┴─┐└╥┘┌─┐
q_1: ─────┤ X ├─╫─┤M├
└───┘ ║ └╥┘
c: 2/═══════════╩══╩═
0 1
Features
The parser supports almost all of the OpenQASM 2 specification, including:
- register definitions and usage (
qreg
andcreg
); - the
qelib1.inc
as a special builtin include, precisely as described in the paper; - general includes, with an option to specify the search path;
- custom
gate
andopaque
declarations; - gate, measurement and reset broadcasting;
- conditioned gate applications, measurements and reset;
- constant folding with the scientific calculator functions in gate parameter lists;
- mathematical expressions on parameters within custom gate bodies.
Qiskit itself adds in some non-paper gate definitions when it sees the
qelib1.inc
include, and treats a non-unitary operation called delay
magically. This parser does not make these extra-spec additions.
Installation
Install the latest release of the qiskit_qasm2
package from pip:
pip install qiskit_qasm2
Developing
If you're looking to contribute to this project, please first read our contributing guidelines.
Set up your development environment by installing the development requirements with pip:
pip install -r requirements-dev.txt tox
This installs a few more packages than the dependencies of the package at
runtime, because there are some tools we use for testing also included, such as
tox
and pytest
.
After the development requirements are installed, you can install an editable version of the package with
pip install -e .
After this, any changes you make to the library code will immediately be present when you open a new Python interpreter session.
This package was mostly an excuse for me to learn a bit more about how lexers are written at a low level. This is why the Rust crate doesn't use any lexer-generation libraries. You can read a bit more about the architecture and some of the design decisions in the developer section of the documentation.
Building documentation
After the development requirements have been installed, the command
tox -e docs
will build the HTML documentation, and place it in docs/_build/html
. The
documentation state of the main
branch of this repository is published to
https://jakelishman.github.io/qiskit-qasm2.
Code style and linting
The Python components of this repository are formatted using black
, and the
Rust components with rustfmt
. You can run these on the required files by
running
tox -e style
The full lint suite can be run with
tox -e lint
License
This project is licensed under version 2.0 of the Apache License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for qiskit_qasm2-0.3.2-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bc5f7d4f859dbb12ab7e4e98426abe9e616360f767b5fd597d5c18004e47644 |
|
MD5 | ba63348c9315d85279fc80ee3847ad55 |
|
BLAKE2b-256 | 5266c6e5590e0ab5db9188e2fbb3d6fc3f286cbd3b23dcb20323e1eb36fd8123 |
Hashes for qiskit_qasm2-0.3.2-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cc30ea5871e900d1e7719237d6eff6e9616b7ec5d9b0fb74eda501ced970ecb |
|
MD5 | 4a5c4d5abd1b06113ee52a0e3b495b3d |
|
BLAKE2b-256 | e085fcc1af7af2ec338b1713b7fce48d9d7d843e747e49eabf8ab42ce673123c |
Hashes for qiskit_qasm2-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c53618ae48b24da662661aff9fd801a4aeaeba3c5148dc3fe63fff111fbd45c3 |
|
MD5 | 92676b197e9293d2edb4b764580946a8 |
|
BLAKE2b-256 | a229edf60560133c2f726312f576e632ecc1c7f660c979b455dbb0dc86b491d0 |
Hashes for qiskit_qasm2-0.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1db5ab11013ecb8910dafe162914c9923082cd6d1f2e371899fd86d57988dca |
|
MD5 | f5242465b770a08f787298f7c424fe37 |
|
BLAKE2b-256 | a9f02493aa53258667bf6a9b45ef046bf5432af83500b5be42786379b3e09472 |
Hashes for qiskit_qasm2-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d75aded93ecefc64f10f1872b78ce6e308d96e987ee4b8995dda1870fd13ff2 |
|
MD5 | daa5cb38da0a9a0f2c9b8ea9d4d302ef |
|
BLAKE2b-256 | e111cf1697b4e7345b95d895edbc0a3d5e1c88dfebaa06414e9cdc13b83bb5f9 |
Hashes for qiskit_qasm2-0.3.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f32edfc251a87aa06d21b8d0b352e7d7bfae855217da563435f5e20d851bc1e |
|
MD5 | 3defb688f3d718eecec9538237cf5f5c |
|
BLAKE2b-256 | 43f580c49dc15ca226a1331d11e3e4a79b14cecc1cc78c60ad9a9e1821aed488 |
Hashes for qiskit_qasm2-0.3.2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8757c4c1bcf5533329e5a5e9cacf8973b52cf1088814eca9594ce5d982ee1ec |
|
MD5 | a32bb62f05d1585eea94b073f08b44c1 |
|
BLAKE2b-256 | 03e5b8f0ae28fe0cfac77f30e053ee5140f9cdd564b60264a123a849fda2c7e0 |
Hashes for qiskit_qasm2-0.3.2-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d94c5240b912ba83ed92f22e962fd5327b60947d39ef9e72486c34e4e8785fe |
|
MD5 | 04e75b815aeb86818d9cacf8bbeb98ee |
|
BLAKE2b-256 | 55ec9c071d59fee59d963b5c91e350858d70c037b8341e56d2817647b90613a8 |
Hashes for qiskit_qasm2-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b81511d2c0aef51d60189d534752f291db932d8a8876424ea35988092331cb4 |
|
MD5 | 9fb6f45779aaebbc26c19fd8bf278fad |
|
BLAKE2b-256 | f1a16c9093c5d9c63a6402ec2148071ab6f0aac7727568ff2a851f4e616abc24 |
Hashes for qiskit_qasm2-0.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abe3627df6ebcb4ae214e2ad1ad2396db9a07a7998d3868c48f5cc9e2883fb9f |
|
MD5 | 7e2fdd5cf536cfa3d8575420e8b236ca |
|
BLAKE2b-256 | e46251fc02dc0532b5ef70ed74c4fd0061b511ce86f97d42b08c21fdbc8d1a67 |
Hashes for qiskit_qasm2-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfe6d4a5f61dcc7b26a76b7b1eba4ce00bd38f213e0752b622716f1ca513b49e |
|
MD5 | d1b6e04f92b7f0f918674178f708ac43 |
|
BLAKE2b-256 | 3a0f97ab5d3f27e704af94b6f32b3758435adeb155444af06e98b7b8c7d927f2 |
Hashes for qiskit_qasm2-0.3.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c6fac9d291010fc5c32c807be1842c9219bd69c3520db69b42728166ef11ce9 |
|
MD5 | a724a40cc125978130c36a88d436901d |
|
BLAKE2b-256 | 3b9fd939d99488f5a2b357d2e568535bc9f2d0685821271848c0677b2d7d72e5 |
Hashes for qiskit_qasm2-0.3.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b4ac7db37d66bce5bdfe5a18c7a9c4599ba1177ed06c2710ab71fac05b9d069 |
|
MD5 | bbab57aa7eaf6435c3a6cd671c18aa31 |
|
BLAKE2b-256 | 8a66f080000dc59b02948631c330adfd59ef675720eabd8ca4297933b7e585eb |
Hashes for qiskit_qasm2-0.3.2-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7841ab58b52efb7d2de05fe8af5fd5f8b05fbff12397cb6f9f1e36c153e84c3 |
|
MD5 | b76004d885bd47c630d7869f993aa465 |
|
BLAKE2b-256 | cf52c6b3e1313755b30f4a7eef0c82258091ecf76cb216480f895f6d5893d170 |
Hashes for qiskit_qasm2-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f409cde6f869a1c8193b61bc7688980f2dd8579fc95eb57672bc36288f090762 |
|
MD5 | fbc0367336128c0a9f6558d9dd57cfe6 |
|
BLAKE2b-256 | e7bb70d3add8c54c4a6947821d776d19c220c48618f2b15024d36f9c93e2545d |
Hashes for qiskit_qasm2-0.3.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c94e25986199919f94f4afe15bd92608c81617ae9e57c8564d613d80ac09518 |
|
MD5 | c9e7e7a65d2301781fcb87d19e2d240a |
|
BLAKE2b-256 | 0f0b3e31fb1fa7fac5a1cf46f97c154c77ea1eddc0da1392fec0fc39155671f7 |
Hashes for qiskit_qasm2-0.3.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 692cb32d47dd8fe2a739f369330f91d1e68b8273cb2fadef92bf6515e6c91b2c |
|
MD5 | fecd9cd0adae2d352831cd79dd6f3f1d |
|
BLAKE2b-256 | 7ee211ee01222b0148c9e2a2ba084e38e7f0d3a8951f27bb9c4569e0486d618e |
Hashes for qiskit_qasm2-0.3.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7da3ace7bb70decae2b4d3041515690848878e85b1b4a5ace356ccd5f3e146fb |
|
MD5 | b459b2d35338c1b30edbe91e62f4dc2f |
|
BLAKE2b-256 | 476e62294c9c9b1ac88c108a1b00fbab041d7a9db11734267512735b0dc827e9 |
Hashes for qiskit_qasm2-0.3.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57c04c5fad83aebc1f3a78bf976bb8e5d5aa96b3421cc17e51807a2fff224cfa |
|
MD5 | 3461fc849871d43dbfda016fca779641 |
|
BLAKE2b-256 | ce8bb41a295815d21417195fb78bb6e0c6c69de8da9e31599b5e8b4b6a405ca4 |
Hashes for qiskit_qasm2-0.3.2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d001404038ab18bbbd63e328abab9e98f323189ee6dc929491b46a25bbca1001 |
|
MD5 | 15a6fc986967aca4b895f5dc9c97383d |
|
BLAKE2b-256 | b6e95d4b40840a4b0bcb679b5832b133d44a6c68457e98a38bf38a4d0416cdef |
Hashes for qiskit_qasm2-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3294515bc090e80e27d6beb39bdad8af2f792c727a96233adf9984489b4a5c2 |
|
MD5 | 72651c1bf22a369e0e48c5910887b267 |
|
BLAKE2b-256 | ca82f615ce0b198daee69485edee15b0b990e70e49f36a1437c9bdca89618099 |
Hashes for qiskit_qasm2-0.3.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e20a5ae0e1c68a665f5cb5ce2a30385932aaeb9a8c0be486611543a72171c4b |
|
MD5 | 5332c314aa5f448325e45c0491b99585 |
|
BLAKE2b-256 | e0e81f51cccdf7fa4382e9f9e6317b83dc15dd0b30750a80a052627350109cbc |
Hashes for qiskit_qasm2-0.3.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cd4cbeb8bee0bb5602bb12d2b07b8f7bf159003c14870ad1f76e0780800e7c0 |
|
MD5 | d303de0c243cb78c919a531d01d9711c |
|
BLAKE2b-256 | 2f94dd58739e4e9ce76be892c46f53e5b456af8a6dfc2579b44a3462fd95d051 |
Hashes for qiskit_qasm2-0.3.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 638747c72abb047148b53ab5c27873356b59d236e490ce9ca3271193b069e47b |
|
MD5 | 17ea19bea9a7df60f2afc2ba9f8030a3 |
|
BLAKE2b-256 | 9fb4b5a3534b7264a5020944bb35cd744bb87644780a59841273e48d71beaa97 |