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.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d6fab817b3f115fe27871d4dadffa4aa3cbb98752ef41a741263f12032446bd |
|
MD5 | 5d80134556d553eb90bc6440bd771df7 |
|
BLAKE2b-256 | daadbb22b15e5531c7b00fde29ccc4e238a26156882527980941ae8310e94a8e |
Hashes for qiskit_qasm2-0.3.1-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1f22c59fb7cde668f74be2d40108ba86eaad0348d7974c4c176ab5c82f61f98 |
|
MD5 | d787bd04d59b5482459a8e7b07433646 |
|
BLAKE2b-256 | 4a12caaea972ff2f44efeb3f6fde2d0de755da8b949d720ecf4660f101b5254f |
Hashes for qiskit_qasm2-0.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 456e39879730a1c7d0c260fc82c8f2f44cb745abe0bdff31b07030c5fb82ee61 |
|
MD5 | 8c01df1cbb1a7dbfef0aecad524a3f50 |
|
BLAKE2b-256 | 67a2e551b9138c57666838c5488577eff2055981200755e245d54baa79bb6864 |
Hashes for qiskit_qasm2-0.3.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63f3243179edc0d52fc07ca432a15128a939b81262bce8f7ddd03907bb8e6b35 |
|
MD5 | 309367587fcd67a5246ed30703de90cd |
|
BLAKE2b-256 | 18345da93b44078abb5af0066606193153f10a6a0cdb523b8cc25dbaab59380e |
Hashes for qiskit_qasm2-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d47a387dfd8aebe91f781f1b08c4373d24db0ddf88fdf35e421b27c3ee044ff |
|
MD5 | 18f6cd083ef3e7980c4b8ccc52b1caac |
|
BLAKE2b-256 | 53aa4da6e5c3d12a2776f3e528702f11d18a2c88c2ca3d08860905506653c2d6 |
Hashes for qiskit_qasm2-0.3.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cc7d1ac3838c20931288944cdecd77c79a0e1fe3af4b226515fe43cdef44fc1 |
|
MD5 | db50fd23ce446ca363d00092fd762c25 |
|
BLAKE2b-256 | e9e9bc3832e3938ccff059278c06a88688524ffca24c78d601ba9025a6069c1a |
Hashes for qiskit_qasm2-0.3.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7fbe05870044fe65a796815185d3c512079ea6aa17232e508344c1f2eaa2002 |
|
MD5 | 7f968c0bee4fc5af5f8843b030c663e9 |
|
BLAKE2b-256 | b9cf24ee42fe5df5a24bc36af2a8112e5267877aaaeeda911c124a483b2116e7 |
Hashes for qiskit_qasm2-0.3.1-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bdcabc9dde1042511dd485ef525ffaada6ef88db31337be649cc5f845613645 |
|
MD5 | 9c9d94244906b7039a2837fb8e1ec9c7 |
|
BLAKE2b-256 | cefaad8a1527105c6242a977206507ca04ef39387713a1ae21051dffcb3ca32f |
Hashes for qiskit_qasm2-0.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8200f6edfe990cd6b24cedf9eb109aee23c7e513bb83ba9cd920c4d177fe24c |
|
MD5 | dc226bc6989a7639386314e9870daf49 |
|
BLAKE2b-256 | 7f995b65a3eb24ee564472cef794d23299669eef98ec61f31cede6de090a2ee0 |
Hashes for qiskit_qasm2-0.3.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef48c664889aeb685276d6d6758f4c7a4ba8bf5773033c64b01b93dfe79aaa2b |
|
MD5 | 8243458f73586fb0ac2aeaf9184f6e13 |
|
BLAKE2b-256 | 9d027a619fc040f5ebd5455e6eb69c98301afef03fe68cc1965dcd8c0d34dec1 |
Hashes for qiskit_qasm2-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2854034c14b9f0a5b8b3a8b20c4d54caffe840f04f43b9d9999f97cab71d9408 |
|
MD5 | 1d0c843e24fe469f10ee99921351b842 |
|
BLAKE2b-256 | 04533cfacd355ac8617e8bf0d60134b7b4ae578711114c924582b29f1037db17 |
Hashes for qiskit_qasm2-0.3.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41574981d5f600b7a97c4da8d13463019fc582f26ba17263f536d70e2ba58852 |
|
MD5 | 4b2115780359c4305dfb6c01b1e907f5 |
|
BLAKE2b-256 | 297a1e151dfb2dffb6eaee95f999d848ca332a75af9b28d133d991d778038bc1 |
Hashes for qiskit_qasm2-0.3.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8be3a6bc83d986e6f7714c41e9361ed76e070914e0d8918debcb6b081190b01d |
|
MD5 | 50113ca7e324555eae419c962af459ae |
|
BLAKE2b-256 | de4b3814f107f5f56726c67678afa55cce482c1ba2f37ee99002bda28fb6ca68 |
Hashes for qiskit_qasm2-0.3.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 446dc08d5857013946c9efd64b20cc66f867a5745e3d894983fb272a18024bd1 |
|
MD5 | 6ee5b916f69bb8978ab97f6e0010da1d |
|
BLAKE2b-256 | 8372c4d1ef3c2529705a12217c853c8c188d59483c56a6c77a25fbdeb569bbb7 |
Hashes for qiskit_qasm2-0.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b3fbacd0ab570fab735c1cf5a79f94b48aac3bd9eef97ff26bfa3b5d1334ad8 |
|
MD5 | cb1264c1adfe43921fc7e9a79e1d6378 |
|
BLAKE2b-256 | b375fe00172f1b231c707d23605a417521e079cf6ad3a6ae69e6179b621a8b99 |
Hashes for qiskit_qasm2-0.3.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30254f4d5a8933905525eeea67c8e72404a86b189c8cc4fedc6663c8754ab794 |
|
MD5 | 9c5200be930ed0bd273aeff25d8295f8 |
|
BLAKE2b-256 | b45060b2e1739abd44257a7dec6f0b3c6a2ddd3928027cd5bf4760efb2463613 |
Hashes for qiskit_qasm2-0.3.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2f694a957eb5907dcff5c45aa964fba3ae82faea522b4242d90a8f868e462c |
|
MD5 | ba0f3ea401dfbd4ef5a0ff62d73987e7 |
|
BLAKE2b-256 | 38b363fc8b231e286723dfd9d5b38ee7d9e7e24bd70b778459f581a5d79981d4 |
Hashes for qiskit_qasm2-0.3.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b408c97c50f9c60b1e166239ce836acbb9a72c099340ccfce8bce6e954149c9 |
|
MD5 | 06f6a5946fb8f05ef15671d7801835a3 |
|
BLAKE2b-256 | b4e5a27006a7a8f9e3db3a83d47c82ed5dfa3cff059404d16eee043e509e7804 |
Hashes for qiskit_qasm2-0.3.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17874fbfb790d725de4013a5b73c753bca454db059ba6946949adc25e5cbcdb0 |
|
MD5 | ae4e42add5000ccd0e99aaf0ba409555 |
|
BLAKE2b-256 | 728ab28d24eec94fc300bd441b569486c7372bbbc27550e6bd4678df245856b3 |
Hashes for qiskit_qasm2-0.3.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77612cc29a328fa576a05691ebcf037d3d097450a72f2aacddb1a95ef12d5f13 |
|
MD5 | a1c71025fdd0bbb6a2a8863ed94e9cf7 |
|
BLAKE2b-256 | 4623cb74f090ee13a839efd6169d78dfc6746298db0be39c2eabd5e13c5b228d |
Hashes for qiskit_qasm2-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bfaeecbff74266f8362da36f1af2c93cc67ae1b89d1e887d2dbfd4a86a867be |
|
MD5 | 1067abe39549c62de20df9188f0c8ef4 |
|
BLAKE2b-256 | d42a524f19047cfafc6924f3b02860faafe83495325d8d3e8d5e6f103f29fdff |
Hashes for qiskit_qasm2-0.3.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cd7e2c685b087af3c56159dc1fd3d578ddeaa9d97bbbab776e202253ebe1322 |
|
MD5 | 00d3e0a67de67765bd037da4feb600e3 |
|
BLAKE2b-256 | 953eba115628e89df39837fbbf5d2c5f59fa398d299a751937a666a6af42d27a |
Hashes for qiskit_qasm2-0.3.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 659814a9df906636fd34d2bb0d4238f03eb2bc7a5d83c2d1ea404d279bf7a06f |
|
MD5 | 7d964685023fbdf3df99113f5b1b430e |
|
BLAKE2b-256 | 502e1d276b52fdf1a1f47e00af7ddf88ccc30f9e89ebbb18b0933a32dd925f13 |
Hashes for qiskit_qasm2-0.3.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 139fa31fb03239c2eb578771541dac846ecb3e4f37e22765f0ce51bbc46e97d3 |
|
MD5 | 21cf715e7f1c00739bf315e8c3d60035 |
|
BLAKE2b-256 | f75066b6f335dd4c66c019ec99b4853de271803ce72983a792d8c99b59f7d909 |