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.2.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1e6c2e5eaf6f9c159303eb7ed85c9cbd71cf7d9cadcebef445daab1b0801d81 |
|
MD5 | 007bcc63ee5eb590ecb7c328b69da013 |
|
BLAKE2b-256 | 55f250f3bb8bb0d26b149f3cbff6f0290bd7ff8dd0f07d7afedcfa110bbcd257 |
Hashes for qiskit_qasm2-0.2.0-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9a5f1051755fb097719f267238d91dce4c5d2ee539d68aec29895d5d48e840d |
|
MD5 | 4ab76cefcd70c14762d3c812d365568f |
|
BLAKE2b-256 | a4b600a3845cfceccc66b83aca39875ed6ef9cd44785acbba3199f4ddead3f2b |
Hashes for qiskit_qasm2-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f1a0da0253875b98571d4dd3af18216879f253c3d6871ecde6da127abd98f13 |
|
MD5 | a674b6b24cf699fe02b67346fc69e415 |
|
BLAKE2b-256 | 4b405e39dd81d7965e9ec42729babd68d39af44f593b6aba127239682f18c978 |
Hashes for qiskit_qasm2-0.2.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a88b0ba865778083b0579734cd76f0b8962a80085605d207f0b02464f3823ed |
|
MD5 | d51af7e6b5ef1054008cfcfd40167887 |
|
BLAKE2b-256 | 523d04a4348538ba2df8f6760f7addc43d482b454d64eeaa396296c25140f3ec |
Hashes for qiskit_qasm2-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b0e052e61b9e14d0d74ce48ed547a81e094796a4ba6b0770c4eb685d127adce |
|
MD5 | ce574b1f41b0cd7f15522d2cc624fa8f |
|
BLAKE2b-256 | 1abbeeaedd3ef3d33e8a67180382bd5f6a48cdf0c180d407a70cea7ca1cc1a6b |
Hashes for qiskit_qasm2-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45317945c0ae3d99f07493bf632e24745bfc30e9e4dc337d4c6a2f43be1b3e02 |
|
MD5 | 86392075f481b20f467d40605a27f63c |
|
BLAKE2b-256 | 4ab054df3e610aa9cea56b504736136ccf0ad53b9a5933982d3d712d30660b18 |
Hashes for qiskit_qasm2-0.2.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 334a87a741dc5db027a2a6317f135af77cd41cbfca3b22fb72f21d6406b0a1ef |
|
MD5 | e2fe0aaea52233984f03e7412f82e3f8 |
|
BLAKE2b-256 | f995c1da744f898ef188014b1c630024f49441e13885ee9611a69dc44657a8c6 |
Hashes for qiskit_qasm2-0.2.0-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8ba41dd3deac2c019306a895c37082fa9f4e58fa5fa41487452d3c82f3ff290 |
|
MD5 | 3db1f04ded04610b0f498ec29b6373f3 |
|
BLAKE2b-256 | cbdc8f71b3c0157974a17f8e299702af35152f3e71f749788c055d15ecfe6be4 |
Hashes for qiskit_qasm2-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f722163a373e644b2716fd12256a13de9765e265bf7ca94ec42039d065193d0f |
|
MD5 | a2f589311693bfacf49521c3616af58c |
|
BLAKE2b-256 | 7df0f8d78bfadddf9e1cf175fe9e727286a541e7fbea471ba7d65665452f1131 |
Hashes for qiskit_qasm2-0.2.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9bd4e0b526dc5537232af3f6c69f41c83cc93b55b7b95cd519514bc41641ec3 |
|
MD5 | 39fbe5165a2d007e0b2094cce0fb16f8 |
|
BLAKE2b-256 | 1c56563547cb9028feb0558d1ac33f7a69dde0f6d5c897eb57be7019d37f7bcc |
Hashes for qiskit_qasm2-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 015568c7ad537b72167b604e588376e8f4e1c48aefd3f18d02e56efbb6e43c48 |
|
MD5 | 1233736ef6f96130dacf0bbb94f974e9 |
|
BLAKE2b-256 | 96e736b4ff64ab10d13bdd3d85deecd127552ef390d694e4c7f69dbced47c63a |
Hashes for qiskit_qasm2-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2764c5b747fe755dc7a561f7dca15635fd19e2e880fed74888e405bc68a8be8a |
|
MD5 | 9b70c03a96fec0ab186cbfa595cade6f |
|
BLAKE2b-256 | 85fcbc75e59fffab7761bc11c1b9a8eb4268b0cf62e128be2d947343daf82566 |
Hashes for qiskit_qasm2-0.2.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08065f60ca4875969bd714490912d523d27e35a5ef33655e55f5a8d86791950b |
|
MD5 | 47f2fb9465489e9937715c2fc6552b7f |
|
BLAKE2b-256 | 939fa9a6c1a4c5aaebea2c62e316247b7d79a325234f42798109a716350af0e7 |
Hashes for qiskit_qasm2-0.2.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e70f86753225ab3329b3b45e7da69117f9c8dc6fc98e1cf4c1f32e7e6dc8c03 |
|
MD5 | 5b8b5d7741e6cdde26a1fa53f2e369b3 |
|
BLAKE2b-256 | 6a584a3f7b6178c663608c832673339404f3278858a971cd85f673da075eb806 |
Hashes for qiskit_qasm2-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53b3d077a7ed117357bef4399e17549748f5ad9c7e76a20b89c37f721ff276c5 |
|
MD5 | 4f48df0936538516d14e8653783a586a |
|
BLAKE2b-256 | 9b13cd5b0cb34e9583d45d118c459b86679b56d428a00a3ff3538c153e0c662a |
Hashes for qiskit_qasm2-0.2.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c898a7794948c345eaee7fa55f245affe4685297000b6002694b6fcb65671f01 |
|
MD5 | f1e43928fed59a48bfba0994f676d9dc |
|
BLAKE2b-256 | 3905e9dc2e965a65c5848b383bc978b30cccc54fd4bb83960d9dbf68e4ca3371 |
Hashes for qiskit_qasm2-0.2.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2141bcd008abb172aa8433a2f3576a8e33662df1c232a45a2e9caf9bf66d112a |
|
MD5 | 0bcf92395a0baeb24f182442fa71411e |
|
BLAKE2b-256 | e56638b18378e324ce047f59d180476ec611762fa8bc67e7a9f4651fa5125009 |
Hashes for qiskit_qasm2-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b534036f1261170b47837e2be85ccdf42c3b1bd192304deef88f461f0ff76e |
|
MD5 | 2912ba5d6b12e4c225975fe7457da23b |
|
BLAKE2b-256 | b9fb2263644d7f71bc32d7bc45190f0eed9bdbc696b00f44bfcd525412dd8ead |
Hashes for qiskit_qasm2-0.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47695a588471ec531f083ee967998bb0ee58660f5e014f3a0a7d14b0f8c244e5 |
|
MD5 | 515f6a95c63a9a02f57ff79ecb96f1f0 |
|
BLAKE2b-256 | 6b2b8d601763422610b4bd32c4dbb264d33fa1bd48b1244bfaafec6a2b7e96f9 |
Hashes for qiskit_qasm2-0.2.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d1ef3190e91341cb221ab83ea606ad838bf00472905d834dfe65e55081bb297 |
|
MD5 | dc0566ee77b514e11678c53d823264ab |
|
BLAKE2b-256 | 79c724cb72c3470130cfef88ac97bbfad59a0159532cb3fcfedcede9ba10af9c |
Hashes for qiskit_qasm2-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fff9a4827a45b3b64f7bfc1c23197b6167cf1641c34c2c90f1af3e3d990b0b2 |
|
MD5 | 74d53747f6e9d5e0eff73b1ce84a19f1 |
|
BLAKE2b-256 | 9a6dae49f39e2df7582ad558cc7237eae8abbd2ce15d7bc347ea4a27cc2862f5 |
Hashes for qiskit_qasm2-0.2.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e1040d71787603173bb3d902703bf115f7526caa84b99947263c49e8b5c1f18 |
|
MD5 | 9bc7544f1a4e4cb24f8fb9e011b69b1e |
|
BLAKE2b-256 | cc513cd937cf41788a390480cc3d979e63b1fabaf5b34793db0f8a29411978ad |
Hashes for qiskit_qasm2-0.2.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19fbcea5474f5d6fa7a80ab0cd53932bb2ef02198c3741e236e0081c403f647a |
|
MD5 | 7d5c76069889978198bd383ae07bc71a |
|
BLAKE2b-256 | 351b9468ba2583119b2ab7db972d6a91db8382fa2261e063c5a4d0d912e81764 |
Hashes for qiskit_qasm2-0.2.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed8532d7a5436ca1826599d88757968a3a818d3f380056cf6f18fe465d8fc246 |
|
MD5 | 1f6a47617350e5e3a716c77fcf73d1d5 |
|
BLAKE2b-256 | 2fd2aecb092bf583cd932cdf1c73a48ac12b45b80ab9102c61cf28e839f0da1c |