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
.
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-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a32cbb9acd62ea4760c1a862ddf9f8c4d33d6bf681718f08eaee1846b415077 |
|
MD5 | e0eafb8693c464086ae800212495192e |
|
BLAKE2b-256 | 723eba6d4af0385fc132ea2d90f9b6bc14075b5a218fe2835959b217c5d1719f |
Hashes for qiskit_qasm2-0.5.3-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc1aaf9d20629506a30796c4f20507a2c91f8be11ed8edbb0030e2a54aea6cc1 |
|
MD5 | 4cb4b11a972d69e2d09b5cb538a4afaa |
|
BLAKE2b-256 | 2b08e20b6ee244f40ae96a80a8cdc81711f41666df4a9364cdfc233f9dfb7555 |
Hashes for qiskit_qasm2-0.5.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 655db2ebfa9e4f454a042a2f0a85e035133f80f64bc6ad5566fddb7f172e7c06 |
|
MD5 | 8968379da51b7e055550ef36b20eae77 |
|
BLAKE2b-256 | 0144c269034b85850319e089903aa5b6c34ab268066cf20520b4590a8f6fed81 |
Hashes for qiskit_qasm2-0.5.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a6e11ea04c4452735f5f35390526e7706ce06a441cf26741ed5257b4689df54 |
|
MD5 | 7016a2f5ff22eeecd707db5e313827bf |
|
BLAKE2b-256 | c66ab5a37db8c909671feae5e1c01110c90228c0bb0600854f5f6fa36e94ce4a |
Hashes for qiskit_qasm2-0.5.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0772e969490fc75dc01d1aab26fd628a58e4fea2793d52259dc03aa81dbb7470 |
|
MD5 | 794c2a8d513407b7247c43d2e25e688d |
|
BLAKE2b-256 | c65d3371d7c7b44b5fa3898a941bc20d5068b629b83b259c8120cfafa605121d |
Hashes for qiskit_qasm2-0.5.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8bf5764382528a206942a6f7c5fe3536872bf60706d1cae9c8f17611fd9345e |
|
MD5 | e0c9a30d8abd64c329a8d108e14c0315 |
|
BLAKE2b-256 | e0fa295c6c60787729ecfeba054e84de58abc8fd943475994eb53ed298a5309e |
Hashes for qiskit_qasm2-0.5.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6598cee8b16225f91e24c46b952b41bb7bb307dc6df5eefd53e770f13b97ad8e |
|
MD5 | 6f6ce72b43835cd433a3c9016ca8c425 |
|
BLAKE2b-256 | 81913718e4ae352a5b906a29da8c64f265c705d2c6dd81d07746fc92c667dc7b |
Hashes for qiskit_qasm2-0.5.3-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99d9f7e0f4e909676388344c30bfae3abbc25dd255f4a4bb19b16394cd35e287 |
|
MD5 | 9a92140601ea83d731c16c9dd70b756e |
|
BLAKE2b-256 | d302cac5660327635d582807fcf762c64b313d46295afa438eb9d2f440abccf9 |
Hashes for qiskit_qasm2-0.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 089b46bdf2467631ee0a43033447fe0ff247fbc72562ee94e4065b21715b0d6b |
|
MD5 | 5850c648feed69d8e8c26f429c4f8734 |
|
BLAKE2b-256 | 22dfea99b9ea0d3eca9fa948440003ddce24b42546a077d594c2c7f1231ad94a |
Hashes for qiskit_qasm2-0.5.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d7de13c0341bc2c0bff5e8dc138c1d8d278daeb48dff119557af3aeb7f89893 |
|
MD5 | 0ee2ce30467a3f822550c0ab0d7479cd |
|
BLAKE2b-256 | 4ed8445a4c85e8d73f93ff7d7a28c7d21e9393fc3eaf5946e4a629a73f1f3356 |
Hashes for qiskit_qasm2-0.5.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 450a5ad57de46b1c236e9b5278bec4856c18a69106e5ff5a82c76fbe369de4bc |
|
MD5 | ba55b901ec2ca0a6794e72de00c737bc |
|
BLAKE2b-256 | 7c4806d0e0fd82bea0bcae9505c804192c35d7074ae7d01cec735b917d50a4f2 |
Hashes for qiskit_qasm2-0.5.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3a7b3912b67e756da16dd84508d9acf9c53f42ad1c0dca42b83744f5c9accd3 |
|
MD5 | d10228d9f872513e71e16c5dcebcd8fd |
|
BLAKE2b-256 | 949e6dfea4a851e14e07bde009caca987f2e665aa00a9799d11cfc0c4db44f13 |
Hashes for qiskit_qasm2-0.5.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e47ad37ed47ed0df926fffb1ea49fbe2efa500a655533f1214af354514de7489 |
|
MD5 | eba5db6aa62c1ca6a60c083c8949da01 |
|
BLAKE2b-256 | 6a73a25fc28ecb43d57532778dabec947f7e101e7a6c9c6f0b742f7d255bd217 |
Hashes for qiskit_qasm2-0.5.3-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f45890928a9f0057ad4c1e057df6b781629f2dd1f252519ba1f31c91549eb5da |
|
MD5 | fa328fc06d3f6d54c0e0669ae4f0115a |
|
BLAKE2b-256 | f4069c8674f56e674470f9fe5a2f652d6559f9c5204d582099a38cb61c0f5a3b |
Hashes for qiskit_qasm2-0.5.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62056f432c4dec7674d3343036169eee28eca1845bbbd28c38ff42ff62d7d15e |
|
MD5 | 80a9d696f01c413c52936bab0ff53e49 |
|
BLAKE2b-256 | b462b6ca6a1b3570cbc816558d2a2bcbec2866564009b09a82a25b89a64d6674 |
Hashes for qiskit_qasm2-0.5.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a0034a56208433c4b088b1b3dd4fbadd90f18f704c55e8b754e10be606b6cd6 |
|
MD5 | db2d86fc8ce335f9d25b3ce2b9e7146c |
|
BLAKE2b-256 | d0f94e5cd4a08272fd262e99d705f609922dec0bb4899f3bcaf16ff415df98f1 |
Hashes for qiskit_qasm2-0.5.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edefddc83217565ee1550f946202bb5a08172f02c438a1e0cbe316281fc2c9ff |
|
MD5 | 8874b81df4a68004f3bc46d55a7987a5 |
|
BLAKE2b-256 | 4658d7fd48e4ce86ef2722a37bbf57c9eac545b3ec544ccb65fd23ae8a2afe37 |
Hashes for qiskit_qasm2-0.5.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcee7d39dda932410473025fa26750af64f039211bb8c93933d86caff372e639 |
|
MD5 | 7cab8d73977b5b661a19c91cafd42653 |
|
BLAKE2b-256 | 7a8acffb1ee8c0caed25de32323c1cfc1a3e3630a3b9feb36dec3d4ea5344d8c |
Hashes for qiskit_qasm2-0.5.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b900d0488e2dbeb6ebc174ee65c54055c01a1ea2053b35b99251b7aeb2d1a02f |
|
MD5 | f24f0f34f478ee49c9df85747cce982e |
|
BLAKE2b-256 | 3fe975e0ac3bb8e086ea6d3877ba6382b5342a0a491a52853a5c5ea67ac482a5 |
Hashes for qiskit_qasm2-0.5.3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f019711111382b1a864684342b4c4907320855d0fccf2cbfd8026236dd13910 |
|
MD5 | cdfbd06a24a70535054e123c47736d2c |
|
BLAKE2b-256 | 4f8889ab61c1c38f0d62300bb5195c26671d072b3e7ccbe668d6e44de06f7afd |
Hashes for qiskit_qasm2-0.5.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b0d842c161e0c27b6759faac1c083dba2121025c0863bd5c70a2c3b79015922 |
|
MD5 | 9294f436cc4d6a73f9fd4a89e8fd0978 |
|
BLAKE2b-256 | e6e9d65a2ebb3bcf672175d92bb6a807870e3dddb613fbd58b9dbc4765af27eb |
Hashes for qiskit_qasm2-0.5.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5bebf225f006031512bce7c4499bec1c0b040fdc6c0c2f99af39b309d6c5cfd |
|
MD5 | 9077cba3111b653321a0c6e44d22fb7d |
|
BLAKE2b-256 | 2c48b0584ffa033ab5edd3a32d34a02cebc991b51bcb9667d5c750ffc3764e33 |
Hashes for qiskit_qasm2-0.5.3-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b785ef152d924a4f855b6e74755ef576b9f4b55277ea4cc1ae179fc2bcfbb87d |
|
MD5 | 8638dca77eb64ff3f3da5ce9e4075507 |
|
BLAKE2b-256 | c40133a8135c575fa127bbaa1ea426c9791385e874010859882966e030f33220 |
Hashes for qiskit_qasm2-0.5.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0fa77310ef2213883d0b977682e9ec940723f645fefd48bd4bd036d55b49505 |
|
MD5 | 044579c72057dadd72884e7cf4ca89f8 |
|
BLAKE2b-256 | 194c73b8dda9e93240165007f0222134e5796b5be6dca381bd88d2216b1742ea |
Hashes for qiskit_qasm2-0.5.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56610b8340fd38ebfab16709f64f733270545b0c7dd99ffa701253b6312de0be |
|
MD5 | 12a50f621c0469a0598123f193480a5f |
|
BLAKE2b-256 | c74851ad698c1ea09bdacb892edfab6f65ff4db9dc111baa0a03e83ab0535ca1 |
Hashes for qiskit_qasm2-0.5.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86816fb02d4b10bfd1ba46fe45e286add42a1b05560513a48ce9b5ea7ff101ce |
|
MD5 | 636b3db6ce8a9fe43daccdb474511007 |
|
BLAKE2b-256 | 18fca6391a2503cde63aa7e2ad9330730ea89457c24c5bdc28d27c1ccaba2688 |
Hashes for qiskit_qasm2-0.5.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35c364fc76105f0f17f7c607d506556b6a5bfccded9b2a20bd9a3332d241b293 |
|
MD5 | 1a6cb925a8f5477f10aee195cd931655 |
|
BLAKE2b-256 | edd26a5fd8513e88cd252272e9921500dc81cc68606c98b2d7a3f6aa345ea1fc |
Hashes for qiskit_qasm2-0.5.3-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ad08a19d49fecf43e8f1b7cf99399fd23a991afd154aedd73c2a4106598619f |
|
MD5 | e5ba9c327a1c2e06aa0e1acc54d1e750 |
|
BLAKE2b-256 | b1c254c8818793e25f540fc34bdcc9a7978668f068975957ace6e5b3ced57723 |
Hashes for qiskit_qasm2-0.5.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5649e302a4315d3f1a478b51f41c8ef8f5795ef90480e31ae8ca065b33a6950b |
|
MD5 | b737f31e9d548aa100c574621102f784 |
|
BLAKE2b-256 | 1913f82d4bbb7dbdab091ca6496417f9cce9a23681bd91ae8714624c6ca9439c |