Skip to main content

Importer for parsing OpenQASM 2 strings into Qiskit circuits

Project description

Importer from OpenQASM 2 to Qiskit

License Release Downloads Coverage Status

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 returns QuantumCircuit;
  • qiskit_qasm2.loads takes an OpenQASM 2 program in a string, and returns QuantumCircuit.

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 and creg);
  • 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 and opaque 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qiskit_qasm2-0.3.0.tar.gz (45.1 kB view details)

Uploaded Source

Built Distributions

qiskit_qasm2-0.3.0-cp311-cp311-win_amd64.whl (251.5 kB view details)

Uploaded CPython 3.11 Windows x86-64

qiskit_qasm2-0.3.0-cp311-cp311-win32.whl (245.2 kB view details)

Uploaded CPython 3.11 Windows x86

qiskit_qasm2-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (698.0 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

qiskit_qasm2-0.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (724.4 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

qiskit_qasm2-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (351.1 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

qiskit_qasm2-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl (356.6 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

qiskit_qasm2-0.3.0-cp310-cp310-win_amd64.whl (251.5 kB view details)

Uploaded CPython 3.10 Windows x86-64

qiskit_qasm2-0.3.0-cp310-cp310-win32.whl (245.2 kB view details)

Uploaded CPython 3.10 Windows x86

qiskit_qasm2-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (698.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

qiskit_qasm2-0.3.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (724.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

qiskit_qasm2-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (351.1 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

qiskit_qasm2-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl (356.6 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

qiskit_qasm2-0.3.0-cp39-cp39-win_amd64.whl (251.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

qiskit_qasm2-0.3.0-cp39-cp39-win32.whl (245.4 kB view details)

Uploaded CPython 3.9 Windows x86

qiskit_qasm2-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (698.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

qiskit_qasm2-0.3.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (724.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

qiskit_qasm2-0.3.0-cp39-cp39-macosx_11_0_arm64.whl (351.4 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

qiskit_qasm2-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl (357.2 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

qiskit_qasm2-0.3.0-cp38-cp38-win_amd64.whl (251.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

qiskit_qasm2-0.3.0-cp38-cp38-win32.whl (245.6 kB view details)

Uploaded CPython 3.8 Windows x86

qiskit_qasm2-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (698.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

qiskit_qasm2-0.3.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (725.1 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

qiskit_qasm2-0.3.0-cp38-cp38-macosx_11_0_arm64.whl (351.5 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

qiskit_qasm2-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl (357.3 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

File details

Details for the file qiskit_qasm2-0.3.0.tar.gz.

File metadata

  • Download URL: qiskit_qasm2-0.3.0.tar.gz
  • Upload date:
  • Size: 45.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for qiskit_qasm2-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b4d6f46dec4644c13c9ac5200388d688006bae8b3c14342a87715d5d193de233
MD5 73d59a5fb1913b6ce5b163d9f209d1a2
BLAKE2b-256 9a9dec64d458b1027f6d9eff72469ed8e1c252c0237d83b2840e0a08f6c54816

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a32cda151359a0a862b629d112ff47a1067d1f2c775a0cf6ba0c47756eba3138
MD5 3681ee13e9bf375ce9796a879f2c99f1
BLAKE2b-256 2a78496a35f2f518bfa69c8095a1dd48cfe1ec80c4e67439ff3319874e6dc2d8

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 13773b68922a79655c48cebe76506e5928055a57a6ab3192c57d3ff21b81ff1e
MD5 373d6cc146ed9351085f8cd40bfa1014
BLAKE2b-256 181b5f06ed54c0f04f7c8df1b1b25fa04f9bd00c92362670f33bd9338ceabe65

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d0d25513bdf719ede7f39151893dcc69fa51fee3b8ba37a735568be826329832
MD5 b7f5957306ca3ed32db75af6c60deff7
BLAKE2b-256 2624c127593833e8a477c8eabbe4d5c76872c58eb56bc2f6a86962d6cb60d43e

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 972edf553924b6681c5f4a4158d9490f49f392e2edaf477fbadaabfc050982bd
MD5 c6016b2a11b9f5026678218f16563e43
BLAKE2b-256 f9e25921c6eae18cdfe914562a8aebcfa2d2593af138b1891b01cc5b9d3190b3

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72bac7262546b4a33ed3c504b5081c92bb415593f10bcd7ab57dea1c5d9d645b
MD5 34f95297364f6ece34cc1a0367c70616
BLAKE2b-256 4c2d1f6b1ff8fdde11cc23d6468c7b1a4d7a8e6472b28ccc05f97465374fb151

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3545d76426442eb941c93238c7d99f6c86c6e30a900995a2d0d1daef0f502660
MD5 9d6d0c7fef0a25737831e1d28704c123
BLAKE2b-256 1f911fecc32324257f088482836dad4714a6471065c62c6bdc4c99a571e98cbf

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a1b298b3b0e11845d18eacaa3cb838c6ecfe438642b3cacad8a01fa03448e2e2
MD5 2da3ae61d143bfdb98caf5f9036ba76a
BLAKE2b-256 d2037774b18c19cd556d983089635e0279122c2c0f50d0ec3252aeab6107a397

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp310-cp310-win32.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 352238602efefb6568cfd7a384bb3b4ace2c4ba697910da31538f8677209b17a
MD5 07f996ff4804fed4fa3e5d6b23c59d49
BLAKE2b-256 92b1cf61544f1e1e4d14709b1a2d19610c427e4c7160e5796d9da7bbbf8e556d

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a82a03b5adabc3767ac956619b0b6f0aa247f98e81a8fedd9e2b798caa86c0ba
MD5 b9e8daa4ffd07fd178941709e4ebad9d
BLAKE2b-256 d21b30143521f70705bc9975eb7187a6a383100f8b91fa941ad349bf8d723c5b

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b3b723aced720354957310c30d6df467ce988d4518084af2c74e70c595a0e658
MD5 4fbf846766ebb5c1c74ba6b78e7a7638
BLAKE2b-256 e6538c855473c3e36f564c4cfb8f8d138f5be556f2d1e06d21ff1be31ae92f65

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dacb193c935f286c7d26c2776931b08013bd58241331f43915fbd08a2323a659
MD5 feeff627490f012141eb09da123d5c63
BLAKE2b-256 c4a1ca50ec7ea6dc26282e672df7c882539ab151457513b8003e9512443fee27

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9fe3c0bfbfc060d31ca145c9e83d6a0c00fb2eca9a91ae1e254ffea42adedcc8
MD5 11274698417e029302658f4847ea4588
BLAKE2b-256 94d9ac7f9a64be488d5da8a1bd766c5500293195c09a8d3c1f5bd2ba8443056b

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a8e3a5db563889bf554ad12644461a4349df0d115b445c9d6bf7c6e520adc5b8
MD5 da78b7f2693c1007b3aa1327b20e5bb2
BLAKE2b-256 744e102bf8129c242af6bbd0120f99293c63e52bf1097c87aa4e7ca8b64be485

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp39-cp39-win32.whl.

File metadata

  • Download URL: qiskit_qasm2-0.3.0-cp39-cp39-win32.whl
  • Upload date:
  • Size: 245.4 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for qiskit_qasm2-0.3.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 dab1edfa25deb2a6b2922ce3ec187aad16d779a4e3334789c802e479c0a1e25e
MD5 5e4106df49f9d1783cbfe80b61a2ce99
BLAKE2b-256 5a93a8e67c01d400cfb65710dc320d46740b4a23413a399cb1d5d1c096427914

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d21517a651f1fe288f9513c021e1fa38da5f25399c01fd2eea3eaeb144e6875a
MD5 88f255afaad19dabb652a6ceca805ea8
BLAKE2b-256 9587694bfcd425d9db86dce90c1966a786915d9da5f12ff4d156ac3de2f8b884

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ddf3e1d9f2b17ea4a9f8eabb72930d8faa3a406061887c85e48a8c4d4ea80c51
MD5 d7ec129ad12026e3018f0b530d9c40fc
BLAKE2b-256 3ebd2806ac534eee6fed8f715febec3ebecb4c1d158902d5259be4460ea5641b

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f6a58f4bb0f3c0446a5cfe8b0aa5a54a225daf5ff27b79d2fc9d17321e84385
MD5 36d01e95bc916a56262787bf3d61e997
BLAKE2b-256 a0b5080a909b36e7024df53978fa5c01f11bf878a402b56dce38230c3935f6e8

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 48b7d9854fed3480856019e8cab5aba8b34f5195d10b65c5a26a9a88e8f37c9f
MD5 ea4cdac8dc0b803cc32c682a5e68db28
BLAKE2b-256 0ccc23b88aa54614a3c03405a23565710350dea8c4007b601ca82615a63cdcb3

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 284abfd294b130fa2b4f364fae206115532632d26270f31126a6625defc8607a
MD5 7057ac5e300ffbec4f1e1dca31df9851
BLAKE2b-256 9204e9f5ccdb80c56fa657dfed47d85feff65f55487aae9d7aba07a95cc389f6

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp38-cp38-win32.whl.

File metadata

  • Download URL: qiskit_qasm2-0.3.0-cp38-cp38-win32.whl
  • Upload date:
  • Size: 245.6 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for qiskit_qasm2-0.3.0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 784ae02564a30ad26bf37714feb395b50e2a54ac5f2f5551b1ea9549c6ba9077
MD5 3a56dff6568453a0105f9e46d48ac136
BLAKE2b-256 501d2e489dc3754dc24a856434df9ae67bb28ff5824736e30a393b09379147c4

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6006f38210fb9f02858ca27f3d3c7139183b0869c8d5cabcbd76da82ff690470
MD5 1e8072daf7808842fadee1ba39eb56eb
BLAKE2b-256 4b4e7c1e7d5768e97c5d118f71ab072fd79dfc58d925bf9da2c347519a0efde3

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ad5ad6e8a622a36968424e8a5b5409e5602b630f4009274aa50a599bd09dfc5d
MD5 d695452dcbdfb0b50391331e6e351613
BLAKE2b-256 271d9367f86993ce3daad91f307e795ea4fbe5566f575fafb637956939520d04

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e41297701812b3e61518e0cb914507248c523157ecafd6db303f5d65019ba556
MD5 085ebb51212ffa0cfe615358d51986f6
BLAKE2b-256 c9c08229d6690c791483d4b5070cf1a08923681a9d96e1809304c4472cc71181

See more details on using hashes here.

File details

Details for the file qiskit_qasm2-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_qasm2-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 640f74501ed38a7bdd84e3fbbf3e8e9bc64e6c0aea0a0580639be2d1ee9ccd88
MD5 a44aff60d81ec6ae1a7180ff72f23be2
BLAKE2b-256 ab17a55fd825d4a84deae4b03729569f48c401c50cfc6bafeb35f24814082e5e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page