Skip to main content

PyQIR

The pyqir package provides the ability to generate QIR as well as an easy way to parse and analyze QIR.

QIR generation is intended to be used by code automating translation processes enabling the conversion in some format to QIR via Python; i.e., this is a low-level API intended to be used as a bridge to existing Python frameworks enabling the generation of QIR rather than directly consumed by an end-user. It is not intended to be used as a framework for algorithm and application development.

Installation

The package is released on PyPI and can be installed via pip:

pip install pyqir

Examples

PyQIR examples can be found in this repository's examples folder.

Generation

The following code creates QIR for a Bell pair before measuring each qubit and returning the result. The unoptimized QIR is displayed in the terminal when executed:

from pyqir import BasicQisBuilder, SimpleModule

module = SimpleModule("Bell", num_qubits=2, num_results=2)
qis = BasicQisBuilder(module.builder)

qis.h(module.qubits[0])
qis.cx(module.qubits[0], module.qubits[1])

qis.mz(module.qubits[0], module.results[0])
qis.mz(module.qubits[1], module.results[1])

print(module.ir())

The QIR output will look like:

; ModuleID = 'Bell'
source_filename = "Bell"




define void @main() #0 {
entry:
  call void @__quantum__qis__h__body(ptr null)
  call void @__quantum__qis__cnot__body(ptr null, ptr inttoptr (i64 1 to ptr))
  call void @__quantum__qis__mz__body(ptr null, ptr null)
  call void @__quantum__qis__mz__body(ptr inttoptr (i64 1 to ptr), ptr inttoptr (i64 1 to ptr))
  ret void
}

declare void @__quantum__qis__h__body(ptr)

declare void @__quantum__qis__cnot__body(ptr, ptr)

declare void @__quantum__qis__mz__body(ptr, ptr writeonly) #1

attributes #0 = { "entry_point" "output_labeling_schema" "qir_profiles"="custom" "required_num_qubits"="2" "required_num_results"="2" }
attributes #1 = { "irreversible" }

!llvm.module.flags = !{!0, !1, !2, !3}

!0 = !{i32 1, !"qir_major_version", i32 2}
!1 = !{i32 7, !"qir_minor_version", i32 0}
!2 = !{i32 1, !"dynamic_qubit_management", i1 false}
!3 = !{i32 1, !"dynamic_result_management", i1 false}

LLVM Opaque Pointers

Starting in PyQIR 0.12, we support LLVM opaque pointers via dependency on LLVM version 18 or higher. These newer version of PyQIR can parse IR or bitcode (.ll or .bc) with either style of pointers, but will always produce opaque pointers in any QIR output. Given that, PyQIR 0.12 also produces QIR with major version 2 by default. If you have need to produce QIR output with major version 1 that uses typed pointers, use PyQIR 0.11 or earlier.

The following table describes the compatibility of PyQIR versions:

Input Output Tooling
Typed Pointer QIR Typed Pointer QIR Use PyQIR 0.11 or earlier
Typed Pointer QIR Opaque Pointer QIR Use PyQIR 0.12 or later
Opaque Pointer QIR Opaque Pointer QIR Use PyQIR 0.12 or later
Opaque Pointer QIR Typed Pointer QIR NOT SUPPORTED

For more information on QIR major version compatibility, see the QIR 2.0 Specification.

Contributing

There are many ways in which you can contribute to PyQIR, whether by contributing a feature or by engaging in discussions; we value contributions in all shapes and sizes! We refer to this document for guidelines and ideas for how you can get involved.

Contributing a pull request to this repo requires to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. A CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately. Simply follow the instructions provided by the bot. You will only need to do this once.

Metadata

Release files for pyqir 0.12.8

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

Built distributions (wheels)

Table of built distributions (wheels) for pyqir 0.12.8
File Actions
pyqir-0.12.8-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl CPython 3.15 abi3t, abi3 Linux glibc 2.28+ x86-64 Details for pyqir-0.12.8-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
pyqir-0.12.8-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl CPython 3.15 abi3t, abi3 Linux glibc 2.28+ ARM64 Details for pyqir-0.12.8-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
pyqir-0.12.8-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for pyqir-0.12.8-cp39-abi3-win_arm64.whl
pyqir-0.12.8-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for pyqir-0.12.8-cp39-abi3-win_amd64.whl
pyqir-0.12.8-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details for pyqir-0.12.8-cp39-abi3-manylinux_2_28_x86_64.whl
pyqir-0.12.8-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for pyqir-0.12.8-cp39-abi3-manylinux_2_28_aarch64.whl
pyqir-0.12.8-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for pyqir-0.12.8-cp39-abi3-macosx_11_0_arm64.whl
pyqir-0.12.8-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for pyqir-0.12.8-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 16.7 MB

Release files / pyqir-0.12.8-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl

Download URL pyqir-0.12.8-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
Size 2.2 MB
Tags CPython 3.15 Linux glibc 2.28+ x86-64 abi3 abi3t
SHA-256 checksum
How to use checksums
9c34959a2a2e8165c1739f82cbea807654971e96f3b07ce451fa90534de59100
BLAKE2b-256 checksum
How to use checksums
86defd44ec4d24354be87726fe90945181e653fafa61c4d9dc2c5255067bf9f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / pyqir-0.12.8-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl

Download URL pyqir-0.12.8-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
Size 2.2 MB
Tags CPython 3.15 Linux glibc 2.28+ ARM64 abi3 abi3t
SHA-256 checksum
How to use checksums
f0734feb441dd714cdacff439f9b422ff12cb9c1d1bba2f417f3465a247517f5
BLAKE2b-256 checksum
How to use checksums
f9b891e44aa8c9da59ce1d1cd50a29443fb4f12a21303a4d030c60ab1a73a414
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / pyqir-0.12.8-cp39-abi3-win_arm64.whl

Download URL pyqir-0.12.8-cp39-abi3-win_arm64.whl
Size 1.9 MB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
23d0f5dd8e1000baddfd42a9b23d9911d535b1b35da0d0a20a532fd7de0f4441
BLAKE2b-256 checksum
How to use checksums
88eee36ef07b44face43aa342fca1a58b4f4690814fe1b085b5ae3cdfe22cca9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / pyqir-0.12.8-cp39-abi3-win_amd64.whl

Download URL pyqir-0.12.8-cp39-abi3-win_amd64.whl
Size 2.0 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f62b0554e62607cc5a6d1aefd3bec64d8779a76fb0454584c5c5f16bd5b6555b
BLAKE2b-256 checksum
How to use checksums
b426bfbdeba86777a6f427e0eb7436dc37f80f19c4a971ea1dd082b842773933
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / pyqir-0.12.8-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL pyqir-0.12.8-cp39-abi3-manylinux_2_28_x86_64.whl
Size 2.1 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
47ff49878ef42e24a21516445c4f9c479ef8695f8be1a97e9999f1122ae2842b
BLAKE2b-256 checksum
How to use checksums
67929fef0c50986482846d85de5ac62a9967b6f6a1a807bcb95eec6bad377109
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / pyqir-0.12.8-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL pyqir-0.12.8-cp39-abi3-manylinux_2_28_aarch64.whl
Size 2.1 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
60b762a4452540ed139a2a0d37b8c2e85b4f09c3b0f7816968d15fe61fa0b6eb
BLAKE2b-256 checksum
How to use checksums
32653235dcfdf7026587407e5e6607bce53120b28512ff110e36f8c5e928bcd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / pyqir-0.12.8-cp39-abi3-macosx_11_0_arm64.whl

Download URL pyqir-0.12.8-cp39-abi3-macosx_11_0_arm64.whl
Size 2.1 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4dc166cb442cc8560b72ee4c25374452ab2a6a36cc8cb8aa67376335748a7c9b
BLAKE2b-256 checksum
How to use checksums
eefe9f8cb12c8e0d446a162ffb3ee3a2c6f9ea87b217f9213a25a07d7ee2d471
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / pyqir-0.12.8-cp39-abi3-macosx_10_12_x86_64.whl

Download URL pyqir-0.12.8-cp39-abi3-macosx_10_12_x86_64.whl
Size 2.2 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d53e27d3dd9badf417f8747e111ec140d0abb6235a117f29077e7f928292f9b7
BLAKE2b-256 checksum
How to use checksums
906e30e7b9d83daf48bdcac07e6a4faf7573cb936b0ffd2bc08c90e1f8771d94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Security for pyqir 0.12.8

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.

Release history Release notifications | RSS feed

This release

0.12.8 This release

8 release files No provenance

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