{"id":19695931,"url":"https://github.com/bbn-q/pyqgl2","last_synced_at":"2025-07-07T02:07:22.932Z","repository":{"id":73325219,"uuid":"87845619","full_name":"BBN-Q/pyqgl2","owner":"BBN-Q","description":"An imperative Quantum Gate Language (QGL) embedded in python.","archived":false,"fork":false,"pushed_at":"2021-12-26T21:40:03.000Z","size":1857,"stargazers_count":9,"open_issues_count":40,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-29T11:41:43.210Z","etag":null,"topics":["compilers","programming-language","quantum-computing"],"latest_commit_sha":null,"homepage":null,"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/BBN-Q.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-04-10T18:44:19.000Z","updated_at":"2024-01-13T23:56:36.000Z","dependencies_parsed_at":"2023-03-11T15:08:58.849Z","dependency_job_id":null,"html_url":"https://github.com/BBN-Q/pyqgl2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BBN-Q/pyqgl2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBN-Q%2Fpyqgl2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBN-Q%2Fpyqgl2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBN-Q%2Fpyqgl2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBN-Q%2Fpyqgl2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BBN-Q","download_url":"https://codeload.github.com/BBN-Q/pyqgl2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BBN-Q%2Fpyqgl2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264000631,"owners_count":23542113,"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":["compilers","programming-language","quantum-computing"],"created_at":"2024-11-11T19:32:05.109Z","updated_at":"2025-07-07T02:07:22.916Z","avatar_url":"https://github.com/BBN-Q.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QGL2 Compiler\n\n[![Build Status](https://travis-ci.org/BBN-Q/pyqgl2.svg?branch=master)](https://travis-ci.org/BBN-Q/pyqgl2) [![Coverage Status](https://coveralls.io/repos/BBN-Q/pyqgl2/badge.svg?branch=master)](https://coveralls.io/r/BBN-Q/pyqgl2)\n\nThis is the QGL2 language compiler. QGL2 is a python-like language for\nprogramming quantum computers. It is a \"low-level language\" in the sense that\nprograms directly specify gates at the physical layer, but with many of the\nniceties of a high-level programming language provided by the python host\nlanguage.\n\nDocumentation on the QGL2 compiler and language, including current known limitations, is in [doc](doc).\n\n## Examples\n\nFor usage examples, see the sample Jupyter notebooks in the [sample notebooks directory](/notebooks).\n\nFor code samples, see the [Basic Sequences](/src/python/qgl2/basic_sequences).\n\nFor an example of compiling a QGL2 program from the command-line, see the [docs README](doc/README.txt).\n\nQGL2 directly parses the Python syntax to give natural looking qubit sequences and control flow.\nmeasurement results to variables and control flow statements. For example:\n\n```python\n@qgl2decl\ndef RabiAmp(qubit: qreg, amps, phase=0):\n    \"\"\"Variable amplitude Rabi nutation experiment.\"\"\"\n    for amp in amps:\n        init(qubit)\n        Utheta(qubit, amp=amp, phase=phase)\n        MEAS(qubit)\n\nOnce a function is decorated with `@qgl2decl` it can act as the `main` for\ncompiling a QGL2 program. If the `RabiAmp` function is placed in a Python module\nthen it can be compiled with something like:\n\n```python\nfrom pyqgl2.main import compile_function\nfrom pyqgl2.qreg import QRegister\nimport numpy as np\nq = QRegister(1)\nqgl1Function = compile_function(filename, \"RabiAmp\", (q, np.linspace(0, 1, 1), 0))\n```\n\nThe result is a function, whose execution generates a QGL sequence.\n```python\n# Run the compiled function. Note that the generated function takes no arguments itself\nseq = qgl1Function()\n```\nThat sequence can then be examined or compiled to hardware, as described in the [QGL documentation](https://github.com/BBN-Q/QGL).\n\nQGL2 uses type annotations in function calls to mark quantum and classical\nvalues. Encapsulating subroutines makes it possible to write tidy compact code\nusing natural pythonic iteration tools.\n\n```python\n# multi-qubit QFT\nfrom qgl2.qgl2 import qgl2decl, qreg, QRegister\nfrom qgl2.qgl1 import Id, X90, Y90, X, Y, Ztheta, MEAS, CNOT\n\nfrom math import pi\n\n@qgl2decl\ndef hadamard(q: qreg):\n    Y90(q)\n    X(q)\n\n@qgl2decl\ndef CZ_k(c: qreg, t: qreg, k):\n    theta = 2 * pi / 2**k\n    Ztheta(t, angle=theta/2)\n    CNOT(c, t)\n    Ztheta(t, angle=-theta/2)\n    CNOT(c, t)\n\n@qgl2decl\ndef qft(qs: qreg):\n    for i in range(len(qs)):\n        hadamard(qs[i])\n        for j in range(i+1, len(qs)):\n            CZ_k(qs[i], qs[j], j-i)\n    MEAS(qs)\n```\n\nBy embedding in Python, powerful metaprogramming of sequences is possible. For\nexample process tomography on a two qubit sequence becomes a function.\n\n```python\n@qgl2decl\ndef tomo(f, q1: qreg, q2: qreg):\n    fncs = [Id, X90, Y90, X]\n    for prep in product(fncs, fncs):\n        for meas in product(fncs, fncs):\n            init(q1, q2)\n            for p, q in zip(prep, (q1,q2)):\n                p(q)\n            f(q1, q2)\n            for m, q in zip(meas, (q1, q2)):\n                m(q)\n            for q in (q1, q2):\n                MEAS(q)\n```\n\n\n## Installation\n### Current instructions\n\u003c!-- Be sure to keep this in sync with .travis.yml and setup.py --\u003e\n * Most any OS should be OK. Instructions tested on Ubuntu 18.04\n * Install `git` and `buildessentials` packages\n * `git-lfs` is now required: See https://git-lfs.github.com/\n  * Download it \u0026 unpack and run `install.sh`\n * Install python 3.6; easiest done using [Anaconda](https://www.anaconda.com/distribution/#download-section)\n  * See below for sample installation given an Anaconda install\n  * You will need python 3 compatible atom (either atom 1.0.0-dev or ecpy channel atom 0.4)\n * Install [QGL](https://github.com/BBN-Q/QGL)\n  * Install QGL dependencies: `cd QGL; pip install -e .`\n  * From within the QGL git clone, set up git lfs: `\u003cQGL\u003e$ git lfs install`\n  * Add QGL to your `.bashrc`: `export PYTHONPATH=$QHOME/QGL:$QHOME/pyqgl2/src/python`\n * Then: `pip install meta` and `pip install watchdog`\n * Optional: `pip install pep8` and `pip install pylint`\n * For typical usage, you also need [Auspex](https://github.com/BBN-Q/Auspex)\n  * See install instructions at https://auspex.readthedocs.io/en/latest/\n   * Download or clone, then `cd auspex; pip install -e .`\n  * Put `Auspex/src` on your `PYTHONPATH` as in above\n * Install `bbndb` as well (if not installed by QGL): `git clone git@github.com:BBN-Q/bbndb.git`\n  * Put the bbndb directory on your PYTHONPATH\n  * `pip install -e .`\n * ?Optional: Get the BBN Adapt module as well\n  * `git@github.com:BBN-Q/Adapt.git`\n  * Put `Adapt/src` on your `PYTHONPATH` as in above\n * Create a measurement file, typically eg `QHOME/test_measure.yml`, containing:\n```\nconfig:\n  AWGDir: /tmp/awg\n  KernelDir: /tmp/kern\n  LogDir: /tmp/alog\n```\n * Set an environment variable to point to it in your `.bashrc`: `export BBN_MEAS_FILE=$QHOME/test_measure.yml`\n * Optional: Install `coveralls` (i.e. for CI)\n * Download `pyqgl2` source from git (https://github.com/BBN-Q/pyqgl2)\n * Test: `cd pyqgl2; python -m unittest discover`. Should see 80+ tests run without errors (warnings are OK).\n\n### Dependencies\n\u003c!-- Be sure to keep this in sync with .travis.yml and setup.py --\u003e\n * Working [QGL](https://github.com/BBN-Q/QGL) installation (including `networkx`, `numpy`, `scipy`, `bqplot`, `sqlalchemy`)\n * Python 3.6\n * watchdog and meta\n * PYTHONPATH includes `\u003cQGL2 install directory\u003e/src/python`\n\n### Sample install using Anaconda\n```bash\n# install anaconda python3\nconda install future\nconda install -c ecpy atom watchdog\npip install meta\ngit clone --recurse-submodules git@github.com:BBN-Q/QGL\ncd QGL\npip install -e .\ngit lfs install\ncd ..\ngit clone https://github.com/BBN-Q/auspex.git\ncd auspex\npip install -e .\ncd ..\ngit clone git@qiplab.bbn.com:buq-lab/pyqgl2.git\n```\n\n## License\n\nApache License v2.0\n\n## Funding ##\n\nThis software is based in part upon work supported by the Office of the Director\nof National Intelligence (ODNI), Intelligence Advanced Research Projects\nActivity (IARPA), through the Army Research Office contract Nos.\nW911NF-10-1-0324 and W911NF-16-1-0114. All statements of fact, opinion or\nconclusions contained herein are those of the authors and should not be\nconstrued as representing the official views or policies of IARPA, the ODNI, or\nthe U.S. Government.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbn-q%2Fpyqgl2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbn-q%2Fpyqgl2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbn-q%2Fpyqgl2/lists"}