Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

hugr-qir

build_status codecov

A tool for converting Hierarchical Unified Graph Representation (HUGR, pronounced hugger) formatted quantum programs into QIR format.

[!NOTE] Not all Guppy/HUGR programs can be converted to QIR.

Documentation

Project documentation lives in docs/ and can be viewed online here.

To build the documentation locally:

uv run --group docs sphinx-build -M html docs docs/_build

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:

  1. 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())
    
  2. Generate the hugr file with:

    python guppy_examples/general/quantum-classical-1.py > test-guppy.hugr
    

See docs/guppy-for-h-series/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.3.0rc0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hugr-qir 0.3.0rc0
File Size Uploaded
hugr_qir-0.3.0rc0.tar.gz 1.5 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for hugr-qir 0.3.0rc0
File
hugr_qir-0.3.0rc0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
hugr_qir-0.3.0rc0-cp310-abi3-manylinux_2_34_x86_64.whl CPython 3.10 abi3 Linux glibc 2.34+ x86-64 Details
hugr_qir-0.3.0rc0-cp310-abi3-macosx_13_0_x86_64.whl CPython 3.10 abi3 macOS 13.0+ x86-64 Details
hugr_qir-0.3.0rc0-cp310-abi3-macosx_13_0_arm64.whl CPython 3.10 abi3 macOS 13.0+ ARM64 Details

Total release size: 113.8 MB

Release files / hugr_qir-0.3.0rc0.tar.gz

Download URL hugr_qir-0.3.0rc0.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
b0ceb35aeb81f4343761a6b31cdbb443d7b57900abde6c329e5922e51c3910b3
BLAKE2b-256 checksum
How to use checksums
1bbb8f7d0a87053b28574db97982305205001e674285018780f83676b555ecd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / hugr_qir-0.3.0rc0-cp310-abi3-win_amd64.whl

Download URL hugr_qir-0.3.0rc0-cp310-abi3-win_amd64.whl
Size 25.1 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b7d849f81806d22ef7241956f685b36c3bb6592b5030ebce80e3a8d8ef5dddcb
BLAKE2b-256 checksum
How to use checksums
caf56e8c71c81e12d02e8c974e0498a37cb076c913b6c7172a7ccbce9a7c1c0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / hugr_qir-0.3.0rc0-cp310-abi3-manylinux_2_34_x86_64.whl

Download URL hugr_qir-0.3.0rc0-cp310-abi3-manylinux_2_34_x86_64.whl
Size 35.3 MB
Tags CPython 3.10 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
ebe32a9af1f76501212107d62cb74e0d67fc2ec3b6b82c16b0d549a15e857b3b
BLAKE2b-256 checksum
How to use checksums
8543ac1e001275c8895f45d496784b71008cf980cc363d6589bb0be3fc3fdd0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / hugr_qir-0.3.0rc0-cp310-abi3-macosx_13_0_x86_64.whl

Download URL hugr_qir-0.3.0rc0-cp310-abi3-macosx_13_0_x86_64.whl
Size 26.7 MB
Tags CPython 3.10 abi3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
3ff4f581081b8d839e0f1d9e9d9e734fe906efe4d05022f2d8a5ab134f01094e
BLAKE2b-256 checksum
How to use checksums
b620a91cb85edd1e2b669c5d5376b3b5dcd9114432c39be15143de693beb795c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / hugr_qir-0.3.0rc0-cp310-abi3-macosx_13_0_arm64.whl

Download URL hugr_qir-0.3.0rc0-cp310-abi3-macosx_13_0_arm64.whl
Size 25.2 MB
Tags CPython 3.10 abi3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
97e7e80efa63f64b014ed046e4e1ecf1259c50ee046827d240e3ad68d5edb337
BLAKE2b-256 checksum
How to use checksums
fe0179c0641c4d3f58980f3ad2a5214d8dc1f0a10e6c49db4a0ac4343fddb6b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

0.3.0

5 release files

This release

0.3.0rc0 This release

5 release files

0.2.0

5 release files

0.1.2

5 release files

0.1.1

5 release files

0.1.0

5 release files

0.0.25

5 release files

0.0.24

5 release files

0.0.20

5 release files

0.0.19

5 release files

0.0.18

5 release files

0.0.16

5 release files

0.0.14

5 release files

0.0.13

5 release files

0.0.9

5 release files

0.0.8

5 release files

0.0.7

5 release files

0.0.6

5 release files

0.0.5

5 release files

0.0.4

5 release files

0.0.3

5 release files

0.0.2

5 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page