Skip to main content

Quantinuum's tool for converting HUGR to QIR

Project description

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).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hugr_qir-0.1.1.tar.gz (1.4 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

hugr_qir-0.1.1-cp310-abi3-win_amd64.whl (29.5 MB view details)

Uploaded CPython 3.10+Windows x86-64

hugr_qir-0.1.1-cp310-abi3-manylinux_2_34_x86_64.whl (34.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ x86-64

hugr_qir-0.1.1-cp310-abi3-macosx_13_0_x86_64.whl (32.5 MB view details)

Uploaded CPython 3.10+macOS 13.0+ x86-64

hugr_qir-0.1.1-cp310-abi3-macosx_13_0_arm64.whl (29.7 MB view details)

Uploaded CPython 3.10+macOS 13.0+ ARM64

File details

Details for the file hugr_qir-0.1.1.tar.gz.

File metadata

  • Download URL: hugr_qir-0.1.1.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.0

File hashes

Hashes for hugr_qir-0.1.1.tar.gz
Algorithm Hash digest
SHA256 88975d2774d80dfa8a0ec50b2e36d9a893de08782baf80a7a5cdd6e86e254666
MD5 16331ae4639c541d0ad0f370771b48de
BLAKE2b-256 0f898ece38503c3c65d66955e0c3eac2db9bab818e11e99933fcb2c66e3652c7

See more details on using hashes here.

File details

Details for the file hugr_qir-0.1.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: hugr_qir-0.1.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 29.5 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.0

File hashes

Hashes for hugr_qir-0.1.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a2f7dca868a53cb70d8f0a7081807e78fdd9f0f53eb7c12351463d96a4a99577
MD5 f341772ba5049d155da2e09abb862084
BLAKE2b-256 7252aa9bf1939fe53bf414db131da1d7c0ac83d1ab9e4d2caffd7e3d812ce9fd

See more details on using hashes here.

File details

Details for the file hugr_qir-0.1.1-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for hugr_qir-0.1.1-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 448afd62adf4b2aa1d464718c7d83862b49e7c46c5f0f8edd32012ae4cf5b209
MD5 8ca45ad349cc904d184770d7d24d68d9
BLAKE2b-256 aafb2f289503826609454bf708ef0d8ef9f0550f985b8a8cc4655ef8a4a36561

See more details on using hashes here.

File details

Details for the file hugr_qir-0.1.1-cp310-abi3-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for hugr_qir-0.1.1-cp310-abi3-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 b14fdb947ee9fff643c752c77c5e8b3be82198a98fcef8c40796b0e3ca0351ef
MD5 288c48cb11636af0b77675b7a9dfa140
BLAKE2b-256 0a5dd3e56572643037c83ca6eb7f64c692106715ef42a2c5056f3060ff79590e

See more details on using hashes here.

File details

Details for the file hugr_qir-0.1.1-cp310-abi3-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for hugr_qir-0.1.1-cp310-abi3-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 18968eb9a1038640f7f95d430732069fad3d74cd036a514770db91e7dce3cfc6
MD5 0e631f48af2929b5905b85e91c5e59c1
BLAKE2b-256 6cde1f18c122863eb0e921f06a84298ee1b3691d7327d1b42201b4520d493727

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page