{"id":20779745,"url":"https://github.com/openqasm/oqpy","last_synced_at":"2025-08-02T03:38:12.298Z","repository":{"id":62049422,"uuid":"553142758","full_name":"openqasm/oqpy","owner":"openqasm","description":"OpenQASM 3 + OpenPulse in Python","archived":false,"fork":false,"pushed_at":"2025-05-21T23:22:00.000Z","size":316,"stargazers_count":25,"open_issues_count":13,"forks_count":11,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-06-23T03:04:30.465Z","etag":null,"topics":["openqasm","python","quantum","quantum-computing","quantum-programming"],"latest_commit_sha":null,"homepage":"https://oqpy.readthedocs.io/en/latest/","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/openqasm.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":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-10-17T19:32:55.000Z","updated_at":"2025-05-21T23:22:04.000Z","dependencies_parsed_at":"2023-09-29T20:23:07.221Z","dependency_job_id":"868cfdd6-7879-4db6-bd94-a3df2e8b1456","html_url":"https://github.com/openqasm/oqpy","commit_stats":{"total_commits":18,"total_committers":8,"mean_commits":2.25,"dds":0.6111111111111112,"last_synced_commit":"ddffe1741fa11533e4350c9e0a77ef471f7a2893"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/openqasm/oqpy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openqasm%2Foqpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openqasm%2Foqpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openqasm%2Foqpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openqasm%2Foqpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openqasm","download_url":"https://codeload.github.com/openqasm/oqpy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openqasm%2Foqpy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268331278,"owners_count":24233217,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","python","quantum","quantum-computing","quantum-programming"],"created_at":"2024-11-17T13:29:28.165Z","updated_at":"2025-08-02T03:38:12.271Z","avatar_url":"https://github.com/openqasm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OQpy: Generating OpenQASM 3 + OpenPulse in Python\n\n[![Latest Version](https://img.shields.io/pypi/v/oqpy.svg)](https://pypi.python.org/pypi/oqpy)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/oqpy.svg)](https://pypi.python.org/pypi/oqpy)\n[![Build status](https://github.com/openqasm/oqpy/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/openqasm/oqpy/actions/workflows/test.yml)\n[![Documentation Status](https://img.shields.io/readthedocs/oqpy.svg?logo=read-the-docs)](https://oqpy.readthedocs.io/en/latest/?badge=latest)\n\nThe goal of `oqpy` (\"ock-pie\") is to make it easy to generate OpenQASM 3 + OpenPulse in Python. The\n`oqpy` library builds off of the [`openqasm3`][openqasm3] and [`openpulse`][openpulse] packages,\nwhich serve as Python reference implementations of the _abstract syntax tree_ (AST) for the\nOpenQASM 3 and OpenPulse grammars.\n\n[openqasm3]: https://pypi.org/project/openqasm3/\n[openpulse]: https://pypi.org/project/openpulse/\n\n## What are OpenQASM 3 and OpenPulse?\n\nOpenQASM is an imperative programming language designed for near-term quantum computing algorithms\nand applications. [OpenQASM 3][openqasm3-docs] extends the original specification by adding support\nfor classical logic, explicit timing, and pulse-level definitions. The latter is enabled via the use\nof [_calibration grammars_][pulses-docs] which allow quantum hardware builders to extend the language\nto support hardware-specific directives via `cal` and `defcal` blocks. One such grammar is\n[OpenPulse][openpulse-docs], which provides the instructions required for pulse-based control of\nmany common quantum computing architectures (e.g. superconducting qubits).\n\n[openqasm3-docs]: https://openqasm.com/\n[pulses-docs]: https://openqasm.com/language/pulses.html\n[openpulse-docs]: https://openqasm.com/language/openpulse.html\n\n## Installation and Getting Started\n\nOQpy can be installed from [PyPI][pypi] or from source in an environment with Python 3.7 or greater.\n\nTo install it from PyPI (via `pip`), do the following:\n\n```\npip install oqpy\n```\n\nTo instead install OQpy from source, do the following from within the repository after cloning it:\n\n```\npoetry install\n```\n\nNext, check out the following example to get a sense of the kinds of programs we can write with\nOQpy.\n\n[pypi]: https://pypi.org/project/oqpy/\n\n## Example: Ramsey Interferometry\n\nA common and useful experiment for qubit characterization is [Ramsey interferometry][ramsey],\nwhich can be used for two purposes: performing a careful measurement of a qubit’s resonant\nfrequency, and for investigating how long a qubit retains its coherence. In a typical Ramsey\nexperiment, one varies the length of a delay between the two π/2 pulses, and then measures the state\nof the qubit. Below, we'll create a Ramsey interferometry experiment in OpenQASM 3 using OQpy.\nAs part of this, we’ll use the OpenPulse grammar to allow this experiment to specify its operation\nimplementations at the calibrated pulse level.\n\n[ramsey]: https://en.wikipedia.org/wiki/Ramsey_interferometry\n\n```python\nimport oqpy\nprog = oqpy.Program()  # create a new oqpy program\n\n# Declare frames: transmon driving frame and readout receive/transmit frames\nxy_frame = oqpy.FrameVar(oqpy.PortVar(\"dac0\"), 6.431e9, name=\"xy_frame\")\nrx_frame = oqpy.FrameVar(oqpy.PortVar(\"adc0\"), 5.752e9, name=\"rx_frame\")\ntx_frame = oqpy.FrameVar(oqpy.PortVar(\"dac1\"), 5.752e9, name=\"tx_frame\")\n\n# Declare the type of waveform we are working with\nconstant_waveform = oqpy.declare_waveform_generator(\n    \"constant\",\n    [(\"length\", oqpy.duration),\n     (\"amplitude\", oqpy.float64)],\n)\ngaussian_waveform = oqpy.declare_waveform_generator(\n    \"gaussian\",\n    [(\"length\", oqpy.duration),\n     (\"sigma\", oqpy.duration),\n     (\"amplitude\", oqpy.float64)],\n)\n\n# Provide gate / operation definitions as defcals\nqubit = oqpy.PhysicalQubits[1]  # get physical qubit 1\n\nwith oqpy.defcal(prog, qubit, \"reset\"):\n    prog.delay(1e-3)  # reset to ground state by waiting 1 ms\n\nwith oqpy.defcal(prog, qubit, \"measure\"):\n    prog.play(tx_frame, constant_waveform(2.4e-6, 0.2))\n    prog.capture(rx_frame, constant_waveform(2.4e-6, 1))\n\nwith oqpy.defcal(prog, qubit, \"x90\"):\n    prog.play(xy_frame, gaussian_waveform(32e-9, 8e-9, 0.2063))\n\n# Loop over shots (i.e. repetitions)\ndelay_time = oqpy.DurationVar(0, \"delay_time\")  # initialize a duration\nwith oqpy.ForIn(prog, range(100), \"shot_index\"):\n    prog.set(delay_time, 0)                     # reset delay time to zero\n    # Loop over delays\n    with oqpy.ForIn(prog, range(101), \"delay_index\"):\n        (prog.reset(qubit)                      # prepare in ground state\n         .gate(qubit, \"x90\")                    # pi/2 pulse (90° rotation about the x-axis)\n         .delay(delay_time, qubit)              # variable delay\n         .gate(qubit, \"x90\")                    # pi/2 pulse (90° rotation about the x-axis)\n         .measure(qubit)                        # final measurement\n         .increment(delay_time, 100e-9))        # increase delay by 100 ns\n```\n\nRunning `print(prog.to_qasm(encal_declarations=True))` generates the following OpenQASM:\n\n```qasm3\nOPENQASM 3.0;\ndefcalgrammar \"openpulse\";\ncal {\n    extern constant(duration, float[64]) -\u003e waveform;\n    extern gaussian(duration, duration, float[64]) -\u003e waveform;\n    port dac1;\n    port adc0;\n    port dac0;\n    frame tx_frame = newframe(dac1, 5752000000.0, 0);\n    frame rx_frame = newframe(adc0, 5752000000.0, 0);\n    frame xy_frame = newframe(dac0, 6431000000.0, 0);\n}\nduration delay_time = 0.0ns;\ndefcal reset $1 {\n    delay[1000000.0ns];\n}\ndefcal measure $1 {\n    play(tx_frame, constant(2400.0ns, 0.2));\n    capture(rx_frame, constant(2400.0ns, 1));\n}\ndefcal x90 $1 {\n    play(xy_frame, gaussian(32.0ns, 8.0ns, 0.2063));\n}\nfor int shot_index in [0:99] {\n    delay_time = 0.0ns;\n    for int delay_index in [0:100] {\n        reset $1;\n        x90 $1;\n        delay[delay_time] $1;\n        x90 $1;\n        measure $1;\n        delay_time += 100.0ns;\n    }\n}\n```\n\n## Contributing\n\nWe welcome contributions to OQpy including bug fixes, feature requests, etc. To get started, check\nout our [contributing guidelines](CONTRIBUTING.md). Those who make a nontrivial contribution to the\nsource code will be added as an author to the [`CITATION.cff`][citation-file] file (see below).\n\n## Citation\n\nIf you use OQpy in your work or research, please cite it using the metadata in the\n[`CITATION.cff`][citation-file] file in the repository (which includes a\n[Zenodo DOI][zenodo-doi]). You can copy the citation in BibTeX format using the\n[\"Cite this repository\" widget][citation-widget] in the About section of the\n[repository page on GitHub][github].\n\n[zenodo-doi]: https://doi.org/10.5281/zenodo.7349265\n[citation-file]: https://github.com/openqasm/oqpy/blob/main/CITATION.cff\n[citation-widget]: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-citation-files\n[github]: https://github.com/openqasm/oqpy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenqasm%2Foqpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenqasm%2Foqpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenqasm%2Foqpy/lists"}