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

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.7
File Actions
pyqir-0.12.7-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl CPython 3.15 abi3, abi3t Linux glibc 2.28+ x86-64 Details for pyqir-0.12.7-cp315-abi3.abi3t-manylinux_2_28_x86_64.whl
pyqir-0.12.7-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl CPython 3.15 abi3t, abi3 Linux glibc 2.28+ ARM64 Details for pyqir-0.12.7-cp315-abi3.abi3t-manylinux_2_28_aarch64.whl
pyqir-0.12.7-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for pyqir-0.12.7-cp39-abi3-win_arm64.whl
pyqir-0.12.7-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for pyqir-0.12.7-cp39-abi3-win_amd64.whl
pyqir-0.12.7-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details for pyqir-0.12.7-cp39-abi3-manylinux_2_28_x86_64.whl
pyqir-0.12.7-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for pyqir-0.12.7-cp39-abi3-manylinux_2_28_aarch64.whl
pyqir-0.12.7-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for pyqir-0.12.7-cp39-abi3-macosx_11_0_arm64.whl
pyqir-0.12.7-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for pyqir-0.12.7-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 16.7 MB

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

Download URL pyqir-0.12.7-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
5259014b10c2106a3ab3a76cc56f78da589360ecb99d282d8ccd98fe85c5d28b
BLAKE2b-256 checksum
How to use checksums
e515be0b9de56342578c6417201c43e06baa70c5f34ea0c05f9c4dc0a2b5a9bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL pyqir-0.12.7-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
238cd638ca96c0fc732b55e6be4d135a61e4ba420159441311f51f9dfda91f9f
BLAKE2b-256 checksum
How to use checksums
16b3cf7d138692f93bf191cf3cf9e73ce662ccfb8108782e0e22677e2cdba46a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

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

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

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

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

Download URL pyqir-0.12.7-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
a2c3fa533e8012e7123eaa0a2d7fdcba9787d9b7062358134e419a08ce3fdcba
BLAKE2b-256 checksum
How to use checksums
36b06a576a9a3af4a0a159a7d1e9ffc4fd3f8249c7f519847059a414025b10ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL pyqir-0.12.7-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
78997e64f7b9321c4b5b749189a4ae9ec56b0128813c3a9325d256930a6bd28c
BLAKE2b-256 checksum
How to use checksums
797389cc628e93a902991f9369a8f9f841bd5eb8747ca62aca40d50481231df4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL pyqir-0.12.7-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
b7dd774702a8a725463b1ab122dc34915d6f1bfa6844355bf8a6390e42eb8b00
BLAKE2b-256 checksum
How to use checksums
1f368cd3f35d4dc3e2e7db5f579db97f2237f6426236c017bb15a308090e4459
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

Download URL pyqir-0.12.7-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
b481e1ffebaeadef248aca6b16f071e84169a430bd2d951ccf6ec8308b721546
BLAKE2b-256 checksum
How to use checksums
3485ccd58b9c376f16b1ece7de39453cec806ed87e8ed5fa1516f38d3f73da3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Security for pyqir 0.12.7

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