hugr-qir
A tool for converting Hierarchical Unified Graph Representation (HUGR, pronounced hugger) formatted quantum programs into QIR format.
Documentation
Project documentation lives in docs/ and can be viewed online here.
- Getting started: docs/getting-started.md
- Examples: docs/examples/index.md
- Guppylang support: docs/guppy-for-h2/index.md
- Python API: docs/python-api.md
- CLI: docs/cli.md
- WASM support: docs/wasm.md
- Development: docs/development.md
To build the documentation locally:
just docs
This builds the documentation in an isolated environment so that Sphinx is not
installed into the test environment. Then open
docs/_build/html/index.html in a browser.
Installation
You can install from pypi via pip install hugr-qir.
Usage
Python
Use hugr_to_qir to convert a HUGR package or serialized HUGR bytes into QIR.
from hugr_qir.hugr_to_qir import hugr_to_qir
from hugr_qir.output import OutputFormat
qir = hugr_to_qir(
hugr_package,
validate_qir=False,
output_format=OutputFormat.LLVM_IR,
)
By default, basic validity checks are run on the generated QIR. These can be disabled by passing validate_qir=False.
You can find an example notebook at examples/submit-guppy-h2-via-qir.ipynb showing the conversion and the submission to Quantinuum System Model H2.
CLI
You can use the available CLI after installing the python package.
This will generate qir for a given hugr file:
hugr-qir test-file.hugr
Run hugr-qir --help to see the available options.
If you want to generate a HUGR file from Guppy, you can do this in two steps:
-
Add this to the end of your guppy file:
if __name__ == "__main__": sys.stdout.buffer.write(main.compile().to_bytes()) # Or to compile a non-main guppy function: sys.stdout.buffer.write(guppy_func.compile_function().to_bytes())
-
Generate the hugr file with:
python guppy_examples/general/quantum-classical-1.py > test-guppy.hugr
See docs/guppy-for-h2/support-matrix.md for the current Guppylang support matrix and caveats.
Development
Setting up the development environment
The easiest way to set up the development environment is to use the provided
devenv.nix file. This will set up a development shell with all the
required dependencies.
To use this, you will need to install devenv. Once you have it running, open a shell with:
devenv shell
All the required dependencies should be available. You can automate loading the shell by setting up direnv.
Run tests
You can run the rust test with:
cargo test
You can run the Python test with:
uv run pytest -n auto
You can type-check the Python sources with:
uv run ty check
You can run the Python formatter and linter with:
uv run ruff format --check python guppy_examples
uv run ruff check python guppy_examples
You can run the configured Git hooks with:
uvx prek run --all-files
If you want to update the snapshots you can do that via:
uv run pytest --snapshot-update
License
This project is licensed under Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Metadata
Release files for hugr-qir 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hugr_qir-0.4.0.tar.gz | 1.6 MB | Without provenance | Details for hugr_qir-0.4.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| hugr_qir-0.4.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for hugr_qir-0.4.0-cp310-abi3-win_amd64.whl |
| hugr_qir-0.4.0-cp310-abi3-manylinux_2_34_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.34+ x86-64 | Details for hugr_qir-0.4.0-cp310-abi3-manylinux_2_34_x86_64.whl |
| hugr_qir-0.4.0-cp310-abi3-macosx_13_0_x86_64.whl | CPython 3.10 | abi3 | macOS 13.0+ x86-64 | Details for hugr_qir-0.4.0-cp310-abi3-macosx_13_0_x86_64.whl |
| hugr_qir-0.4.0-cp310-abi3-macosx_13_0_arm64.whl | CPython 3.10 | abi3 | macOS 13.0+ ARM64 | Details for hugr_qir-0.4.0-cp310-abi3-macosx_13_0_arm64.whl |
Total release size: 114.0 MB
Release files / hugr_qir-0.4.0.tar.gz
| Download URL | hugr_qir-0.4.0.tar.gz |
|---|---|
| Size | 1.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c187198d87e6f8ed596171d53f55833c9b7463f68c67e6e6273b57da54f25776
|
|
BLAKE2b-256 checksum How to use checksums |
08765c38b1a5936a616b3aa6df6f44d111017cd2fa2504cd58408e53f6ce64fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / hugr_qir-0.4.0-cp310-abi3-win_amd64.whl
| Download URL | hugr_qir-0.4.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 25.1 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
3d91a0fdb696afff99db741547e9c46469e7f6b4c3da99ed04de90817e358a70
|
|
BLAKE2b-256 checksum How to use checksums |
8f6f74c7f867d69c4244dbac41439f1cccf39147457ce1361a90c4ee1f848e2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / hugr_qir-0.4.0-cp310-abi3-manylinux_2_34_x86_64.whl
| Download URL | hugr_qir-0.4.0-cp310-abi3-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 35.4 MB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
aacab69913c3880177cc344beae7b64ff1a2d0a53289e8207161aabbfafa9b20
|
|
BLAKE2b-256 checksum How to use checksums |
14c4380d41997218e7c97d02703bee877ff69d5ec117d091710fed5780202652
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / hugr_qir-0.4.0-cp310-abi3-macosx_13_0_x86_64.whl
| Download URL | hugr_qir-0.4.0-cp310-abi3-macosx_13_0_x86_64.whl |
|---|---|
| Size | 26.8 MB |
| Tags | CPython 3.10 abi3 macOS 13.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
214b65f06d7b4946dce315d0834966b35d182a6f597b4a2dd552cce08762f3f8
|
|
BLAKE2b-256 checksum How to use checksums |
7003431b543fe63f986f6af052dccfe925ff60bea3f801febeea3f35737f8ed1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / hugr_qir-0.4.0-cp310-abi3-macosx_13_0_arm64.whl
| Download URL | hugr_qir-0.4.0-cp310-abi3-macosx_13_0_arm64.whl |
|---|---|
| Size | 25.3 MB |
| Tags | CPython 3.10 abi3 macOS 13.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3a54d8ee43f774b076cffebee938de285771b3fc254674622e0f4085260162b4
|
|
BLAKE2b-256 checksum How to use checksums |
903aa915df767e0a814dcfeff95de398fc697fdce54f1535ac6afea949403470
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Security for hugr-qir 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.