{"id":28552247,"url":"https://github.com/qiskit/qiskit-qasm3-import","last_synced_at":"2025-07-06T03:31:25.631Z","repository":{"id":62969089,"uuid":"564021503","full_name":"Qiskit/qiskit-qasm3-import","owner":"Qiskit","description":"Importer from OpenQASM 3 to Qiskit's QuantumCircuit","archived":false,"fork":false,"pushed_at":"2025-06-03T21:35:16.000Z","size":109,"stargazers_count":24,"open_issues_count":11,"forks_count":9,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-06-04T06:03:53.061Z","etag":null,"topics":["openqasm","qiskit","quantum-computing"],"latest_commit_sha":null,"homepage":"https://qiskit.github.io/qiskit-qasm3-import","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Qiskit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-09T20:33:03.000Z","updated_at":"2025-06-03T21:35:17.000Z","dependencies_parsed_at":"2024-03-14T17:59:22.223Z","dependency_job_id":"7bc2f785-096a-4e6c-814d-d59001d252e3","html_url":"https://github.com/Qiskit/qiskit-qasm3-import","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/Qiskit/qiskit-qasm3-import","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qiskit%2Fqiskit-qasm3-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qiskit%2Fqiskit-qasm3-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qiskit%2Fqiskit-qasm3-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qiskit%2Fqiskit-qasm3-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Qiskit","download_url":"https://codeload.github.com/Qiskit/qiskit-qasm3-import/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Qiskit%2Fqiskit-qasm3-import/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263843043,"owners_count":23518709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openqasm","qiskit","quantum-computing"],"created_at":"2025-06-10T04:08:31.631Z","updated_at":"2025-07-06T03:31:25.619Z","avatar_url":"https://github.com/Qiskit.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Importer from OpenQASM 3 to Qiskit\n\n[![License](https://img.shields.io/github/license/Qiskit/qiskit-qasm3-import.svg?style=flat)](https://opensource.org/licenses/Apache-2.0)[![Release](https://img.shields.io/github/release/Qiskit/qiskit-qasm3-import.svg?style=flat)](https://github.com/Qiskit/qiskit-qasm3-import/releases)[![Downloads](https://img.shields.io/pypi/dm/qiskit-qasm3-import.svg?style=flat)](https://pypi.org/project/qiskit-qasm3-import/)\n\nThis repository provides the Python package `qiskit_qasm3_import`, which is a\nbasic and temporary importer from OpenQASM 3 into Qiskit's `QuantumCircuit`.\n\nQiskit itself accepts this package as an optional dependency if it is installed.\nIn that case, Qiskit exposes the functions `qiskit.qasm3.load` and\n`qiskit.qasm3.loads`, which are wrappers around `qiskit_qasm3_import.parse`.\nThis project is a stop-gap measure until various technical decisions can be\nresolved the correct way; Terra makes strong guarantees of stability and support\nin its interfaces, and we are not yet ready to make that commitment for this\nproject, hence the minimal wrappers.\n\n\n## Example\n\nThe principal entry point to the package is the top-level `parse` function,\nwhich accepts a string containing a complete OpenQASM 3 programme.  This complex\nexample shows a lot of the capabilities of the importer.\n\n```qasm\nOPENQASM 3.0;\n// The 'stdgates.inc' include is supported, and the gates are only available\n// if it has correctly been included.\ninclude \"stdgates.inc\";\n\n// Parametrised inputs are supported.\ninput float[64] a;\n\nqubit[3] q;\nbit[2] mid;\nbit[3] out;\n\n// Aliasing and re-aliasing are supported.\nlet aliased = q[0:1];\n\n// Parametrised gates that make use of the stdlib.\ngate my_gate(a) c, t {\n  gphase(a / 2);\n  ry(a) c;\n  cx c, t;\n}\n\n// Gate modifiers work as well; this gate is equivalent to `p(-a) c;`.\ngate my_phase(a) c {\n  ctrl @ inv @ gphase(a) c;\n}\n\n// We handle mathematical expressions on gate creation and complex indexing\n// of temporary collections.\nmy_gate(a * 2) aliased[0], q[{1, 2}][0];\nmeasure q[0] -\u003e mid[0];\nmeasure q[1] -\u003e mid[1];\n\nwhile (mid == \"00\") {\n  reset q[0];\n  reset q[1];\n  my_gate(a) q[0], q[1];\n  // We support the builtin mathematical symbols.\n  my_phase(a - pi/2) q[1];\n  mid[0] = measure q[0];\n  mid[1] = measure q[1];\n}\n\n// The condition resolver can also handle simple cases that don't look\n// _exactly_ like equality conditions.\nif (mid[0]) {\n  // There is limited support for aliasing within nested scopes.\n  let inner_alias = q[{0, 1}];\n  reset inner_alias;\n}\n\nout = measure q;\n```\n\nAssuming this program is stored as a string in a variable `program`, we then\nimport it into a `QuantumCircuit` by doing:\n\n```python\nfrom qiskit_qasm3_import import parse\ncircuit = parse(program)\n```\n\n`circuit` is now a complete `QuantumCircuit`, so we can see exactly what it\nturned into:\n\n```python\ncircuit.draw()\n```\n```text\n       ┌───────────────┐┌─┐   ┌─────────────┐┌──────────┐┌─┐\n  q_0: ┤0              ├┤M├───┤0            ├┤0         ├┤M├───\n       │  my_gate(2*a) │└╥┘┌─┐│             ││          │└╥┘┌─┐\n  q_1: ┤1              ├─╫─┤M├┤1            ├┤1         ├─╫─┤M├\n       └──────┬─┬──────┘ ║ └╥┘│             ││  If_else │ ║ └╥┘\n  q_2: ───────┤M├────────╫──╫─┤  While_loop ├┤          ├─╫──╫─\n              └╥┘        ║  ║ │             ││          │ ║  ║\nmid_0: ════════╬═════════╩══╬═╡1            ╞╡0         ╞═╬══╬═\n               ║            ║ │             │└──────────┘ ║  ║\nmid_1: ════════╬════════════╩═╡0            ╞═════════════╬══╬═\n               ║              └─────────────┘             ║  ║\nout_0: ════════╬══════════════════════════════════════════╩══╬═\n               ║                                             ║\nout_1: ════════╬═════════════════════════════════════════════╩═\n               ║\nout_2: ════════╩═══════════════════════════════════════════════\n```\n\n\n## Installation\n\nInstall the latest release of the `qiskit_qasm3_import` package from pip:\n\n```text\npip install qiskit_qasm3_import\n```\n\nThis will automatically install all the dependencies as well (an OpenQASM 3\nparser, for example) if they are not already installed.  Alternatively, you can\ninstall Qiskit Terra directly with this package as an optional dependency by\ndoing\n\n```text\npip install qiskit-terra[qasm3-import]\n```\n\n\n## Developing\n\nIf you're looking to contribute to this project, please first read\n[our contributing guidelines](CONTRIBUTING.md).\n\nSet up your development environment by installing the development requirements\nwith pip:\n\n```bash\npip install -r requirements-dev.txt tox\n```\n\nThis installs a few more packages than the dependencies of the package at\nruntime, because there are some tools we use for testing also included, such as\n`tox` and `pytest`.\n\nAfter the development requirements are installed, you can install an editable\nversion of the package with\n\n```bash\npip install -e .\n```\n\nAfter this, any changes you make to the library code will immediately be present\nwhen you open a new Python interpreter session.\n\n\n### Building documentation\n\nAfter the development requirements have been installed, the command\n\n```bash\ntox -e docs\n```\n\nwill build the HTML documentation, and place it in `docs/_build/html`.  The\ndocumentation state of the `main` branch of this repository is published to\nhttps://qiskit.github.io/qiskit-qasm3-import.\n\n\n### Code style and linting\n\nThe Python components of this repository are formatted using `black`.  You can\nrun this on the required files by running\n\n```bash\ntox -e black\n```\n\nThe full lint suite can be run with\n\n```bash\ntox -e lint\n```\n\n\n## License\n\nThis project is licensed under [version 2.0 of the Apache License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiskit%2Fqiskit-qasm3-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqiskit%2Fqiskit-qasm3-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiskit%2Fqiskit-qasm3-import/lists"}