Importer for parsing OpenQASM 2 strings into Qiskit circuits
Project description
Importer from OpenQASM 2 to Qiskit
[!IMPORTANT]
This package is obsolete. It was vendored into Qiskit itself as of
qiskit==0.43.0
(viaqiskit-terra==0.24.0
at the time), at version0.5.3
of this package. There is no longer any need to install this package; simply useqiskit.qasm2.load
orqiskit.qasm2.loads
. The Qiskit version is actively developed, and this package is not being updated any more.All references to Qiskit in the README and in the package itself mean Qiskit versions
<0.43
, before this package was vendored into 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
.
The full documentation is published to https://jakelishman.github.io/qiskit-qasm2.
A simple parsing 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 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.
In addition, the parser also includes options to:
- modify the search path for
include
statements in OpenQASM 2; - define overrides for how some named OpenQASM 2 gate applications should be converted into Qiskit form;
- define new builtin quantum instructions for OpenQASM 2;
- define new builtin classical scientific-calculator functions.
Qiskit's builtin parser makes some extra-spec additions by default, with no
option to disable them. This mostly takes the form of custom gate overrides,
and various additional gates in Terra's vendored version of qelib1.inc
compared to the description in the paper. This parser is more type-safe than
Qiskit's, but does include a compatibility mode
to ease the transition from using Qiskit's parser.
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
.
You will also need a working Rust toolchain. The easiest way to install one is by using rustup on Linux, macOS or Windows.
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.5.3.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28a7a686369f8837b881931ce345a51d86d658c4e4e3bda03d608f4b206be4e4 |
|
MD5 | d7b765a1588ac235e0180e7a84508239 |
|
BLAKE2b-256 | 8c2dc1ee33b06fee7588abeafce06acdac26dfd55681a5eebfff4f3685d2ab0a |
Hashes for qiskit_qasm2-0.5.3.1-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82a586da95e507bf94a045a9f4d5227c55be17a441d3ea43a9871804fea1e6d2 |
|
MD5 | 462d8dbc9dc4631a26ebc971251e9111 |
|
BLAKE2b-256 | 7b9eefc0daca9fc91d5cfa11058d62d499418937d92ca0cfe0bfc099ff158af4 |
Hashes for qiskit_qasm2-0.5.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 354c5352bd760aeaa9b0caf1f930cc1865db6aa4c3348f9571e66701e0f111af |
|
MD5 | 208039409e3889880428046208db4035 |
|
BLAKE2b-256 | faa3017d301050645d204f369a97b356887ab6f2d053da5dc1bc0203debf8b1a |
Hashes for qiskit_qasm2-0.5.3.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84643a30da1e3ff80013dc7383fbdaaaaee9cf793a91372ad1f2bacbf5a4592b |
|
MD5 | 03e83a4424b9bbaf4baa2ef16968ccf0 |
|
BLAKE2b-256 | 334c787c12ea5761045bf60b0167f2d25fffe9f612aeaf0e50017e142f498dca |
Hashes for qiskit_qasm2-0.5.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 608b40d083882b7e67729e1eb835a5a17ee04805794572cc64f56f6a5f6f9f6c |
|
MD5 | 7f8d05e39316323468d4125c51df84d3 |
|
BLAKE2b-256 | 82e63b2141c7c7c1726e21121b546f718b0a17ae9cd20210b6cb577d1950fc63 |
Hashes for qiskit_qasm2-0.5.3.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f80b1e8e407c28a700b5808f45311e73aafe941e2e93d1ed7c7b36f2b736d459 |
|
MD5 | b85080b3c13f66aaffa428b6ac2b1c19 |
|
BLAKE2b-256 | a6fb1dc4b465e7c39d159664b7ceb1f074df016e6571abeed8bcab9ef7d3717a |
Hashes for qiskit_qasm2-0.5.3.1-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 461b0800500fe8d3ce5a8535165620b0923b747038e80c5f197d19917d7943e8 |
|
MD5 | 0e6d503c102a45ceda4616382d411e4f |
|
BLAKE2b-256 | 09f6393ef37bdcaeeafb2367968bc98b7855f770ef109f32fb464e75f65dd274 |
Hashes for qiskit_qasm2-0.5.3.1-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b5023cab423ed94d4c89a3b7c29bbbd76a2810c061b519a37333ac23fdaf9b6 |
|
MD5 | 09b25d754a3735e9c36a5d23101825c6 |
|
BLAKE2b-256 | 92a0e1f63c58cbe1784483c4034a0ed074cf7f4ed74b0e4564c011a79be6a7be |
Hashes for qiskit_qasm2-0.5.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a74468bdc0b55692ff124bae8513b752cc40f10710b208ea19e7b358b7e272da |
|
MD5 | 9fe56e8d9e1cc8f1f91cbca2381e6034 |
|
BLAKE2b-256 | 0185a31ad39ccdbc6e4957db70db0e31bb668bc7dfee66cd284465137b87cb17 |
Hashes for qiskit_qasm2-0.5.3.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 346f1e5a17344aa3c2c8a3f28b3a0bc6594d4f8e9e9f93fba4b07b041055f16f |
|
MD5 | 13f32cf0861fc19236968b30f886da02 |
|
BLAKE2b-256 | 64f8b827c8be8581fe94dce1e7b937fb11e669e9514fce27488bf99b1bf10a4e |
Hashes for qiskit_qasm2-0.5.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6463c133799a871ee45f28b6176f5b3f0a74b7da039d73ddc806fb626a035195 |
|
MD5 | d1cbbd10954214e2e21a450b671d2eb2 |
|
BLAKE2b-256 | 8583308e9c74b461d6a41ac0848db02d5ab9de264c8610fd5b91c385fc44e318 |
Hashes for qiskit_qasm2-0.5.3.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca93a137c0e116917858c7689dcc53e2bc7ad060c416f270221bda6133cef973 |
|
MD5 | 7506354ab3767411523065bfc2df7d93 |
|
BLAKE2b-256 | bf51b4ccac76437345765964a117ab5209fabaf3cdc1b7525d9798feff62ca4b |
Hashes for qiskit_qasm2-0.5.3.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8ff62b1e116dc988fb2e85ff4d56c208e4d6b98c5159598a32f0c39f1e252fd |
|
MD5 | 709b7937f176f251a16adc6d0ddf3c65 |
|
BLAKE2b-256 | a7846889dccf06727aa334e452e5cac7e3b782c7b2ee29c5c04fc06aca7ba156 |
Hashes for qiskit_qasm2-0.5.3.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e950aeeccd0216878f91515ab8ae33f787d1bdd8f012db7cd1a7f1edcd81bb8a |
|
MD5 | 9437e823ef296ae3de901c5965284e48 |
|
BLAKE2b-256 | 611483b8db82426abf67ca5dd1cb3f8121f0cc6071d9fc0b466e54a8d56ac958 |
Hashes for qiskit_qasm2-0.5.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0d72ff8feb176a6094db96293424c50e39fae0902c3682bad70f52ef373b8d1 |
|
MD5 | 844dce026d427c8a452db3d6137e8a2d |
|
BLAKE2b-256 | d51360691d1de5c1e1c839e0a3bb8b961a6522069a2553ff52ae86f188026b9b |
Hashes for qiskit_qasm2-0.5.3.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89285a31a21d7c926c1f94bba97e9ab68b37a764862258ed94a05b8314dc0967 |
|
MD5 | 2a28ae2d0f2ec9968d0505ce172d23de |
|
BLAKE2b-256 | 474199534316c5b876d04ac954cd120676d4f13ada6b0e5ea59142a1dec73143 |
Hashes for qiskit_qasm2-0.5.3.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea5d6043834db660d0563cc9b6f0fc8328ef12f8514215d578ab0bfafcb0f2d1 |
|
MD5 | 8b9abdf0c9ed1bb5c7d8a49d961cfdbb |
|
BLAKE2b-256 | 9ae9bb6784589d7d7a6269a2e3dcd7a0cdab0258764ac0367640e6d5728af95b |
Hashes for qiskit_qasm2-0.5.3.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a94f194db5db83ad101d359773e31e93d986dfe761a72618e91aedb368a63f35 |
|
MD5 | b80952173c29849294c129d9400a9bd3 |
|
BLAKE2b-256 | 3369154acd30c435422be130e4d7a26e1f6bd9a479970f7d7bf29161e5ef0146 |
Hashes for qiskit_qasm2-0.5.3.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d0ca8f20cbe152481946d1c67bee8b2fa399f0b04ca4ab99b8f94d64149c900 |
|
MD5 | 2a37503b3721c9c4945aa2950a9ea93a |
|
BLAKE2b-256 | 571ce9d3c6da880faa27306dc38add22d9477577796d93fb1ba661882eeeb56b |
Hashes for qiskit_qasm2-0.5.3.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da6ffa3fb9d38f38061aa7dc11fc340db985888371be0d87e64a2111041ec02e |
|
MD5 | 90d5e6039a525c0b74aa9abb070d1e4c |
|
BLAKE2b-256 | a4b023a59d582b87e5a9275af07d51e13bf6f7d0311e42aba58291577dcd0a1a |
Hashes for qiskit_qasm2-0.5.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28e96915a555c4d712db5b97118a87c99e50d86f5721ef03a8ff57f116890fa4 |
|
MD5 | 1f76ece215f3cdccfdf86957b3360cce |
|
BLAKE2b-256 | 167c6b3aad86cfb1e75eb0522d425b3ddc4567561803cd038a2a6986f4116572 |
Hashes for qiskit_qasm2-0.5.3.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e8b3edf123b8f0b80a4e2a92814ed42cde2ee31cd8dc58a530952ef84fec979 |
|
MD5 | c304596f22379a31a3ad4afb8436a02a |
|
BLAKE2b-256 | 9fd32c6e936756e06a6f97475c28bca3ca026795ac50deacc59c53b741d17665 |
Hashes for qiskit_qasm2-0.5.3.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81b50cdc54ecf8963aeb934ab08716810d3aa9897eb92e9a757b4265d0c1e67d |
|
MD5 | b174c65e6178a60d44e9b344017ef58a |
|
BLAKE2b-256 | 20ef258ff2bcadf536b7dddd29da74fd67e23f6d123fd19d4b284f8ed38a0d9f |
Hashes for qiskit_qasm2-0.5.3.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b838fcf21c6775f1286485cc8c0574dbe7f2da6776faac6437864f2664db58be |
|
MD5 | 5c22848936d3e03a6f49e5c97fea7f06 |
|
BLAKE2b-256 | f2932a61912c56522b380d68cb7380d0798e21afee4a9ac8b457d5d20bbacd7e |
Hashes for qiskit_qasm2-0.5.3.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbc3da7d1fa364dac6c83d905b629141900139f3d3b8491ee62b51520e71d912 |
|
MD5 | d9749ce91c952f688443b4d837bc2448 |
|
BLAKE2b-256 | 6c54fbfeb1e2d782c6c511944b3025cc242fa6c5bdaf36373947fef29502a704 |
Hashes for qiskit_qasm2-0.5.3.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb7ac98c7289040700810642dd601a890da0fb1a21b59bfdc3ada671ccf46eb5 |
|
MD5 | d7ef3e3e28776c1f5a456a6046727c59 |
|
BLAKE2b-256 | a5b3885c96df4ed5ce5cc1aaa460522502c21ff065b31a6c31a0a9f7aa29d7e1 |
Hashes for qiskit_qasm2-0.5.3.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766ceaf4f6a14861ae08839b7206c0a0e140ecfb866fa48d32548ad6128a0949 |
|
MD5 | 9d35e4d63e7d4d9a5895032182f98109 |
|
BLAKE2b-256 | 8edc9a8b480d2b892bf11b4fcac14583c1e61681d4a1c11d4d2438d1b7e83449 |
Hashes for qiskit_qasm2-0.5.3.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e99e77789c1e607dbb2bbddc66fa50c6916aae912120b6ca8fd9a8c95ecca28b |
|
MD5 | 02ab4b4b598c62c05ac88d29ce7c0b71 |
|
BLAKE2b-256 | a6335c875e103e4dd9d349f29c615431de3360f7b34c2fb274b053b42e39fa5b |
Hashes for qiskit_qasm2-0.5.3.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c6c4089998714f7309d793aa03d3b5507ac70f1224bcceee152b04426149121 |
|
MD5 | af0e120c90a5cf061569b9348dd07df7 |
|
BLAKE2b-256 | f2e4323bfb25ab3c8491710b791bd9da30dda4a0c962dd8a8912f7cefb1e45cf |