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

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.6
File
pyqir-0.12.6-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details
pyqir-0.12.6-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
pyqir-0.12.6-cp39-abi3-manylinux_2_38_aarch64.whl CPython 3.9 abi3 Linux glibc 2.38+ ARM64 Details
pyqir-0.12.6-cp39-abi3-manylinux_2_34_x86_64.whl CPython 3.9 abi3 Linux glibc 2.34+ x86-64 Details
pyqir-0.12.6-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
pyqir-0.12.6-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 13.5 MB

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

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

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

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

Release files / pyqir-0.12.6-cp39-abi3-manylinux_2_38_aarch64.whl

Download URL pyqir-0.12.6-cp39-abi3-manylinux_2_38_aarch64.whl
Size 2.7 MB
Tags CPython 3.9 Linux glibc 2.38+ ARM64 abi3
SHA-256 checksum
How to use checksums
216451808d5a6b4b7be8913e2391746e2171445a64aa61aeeb81580ed37c3fc2
BLAKE2b-256 checksum
How to use checksums
a9b8050ddc70d29036a2508771561be4ce3c1f54c5a44aca51ead31e54ff12f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

Release files / pyqir-0.12.6-cp39-abi3-manylinux_2_34_x86_64.whl

Download URL pyqir-0.12.6-cp39-abi3-manylinux_2_34_x86_64.whl
Size 2.6 MB
Tags CPython 3.9 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
fda9f40a5cb5191a0b938524b60695ac0ceeba48da4c9807035191088d4fb69b
BLAKE2b-256 checksum
How to use checksums
0918c4d2840af6dc6ca2dc99102f7b6d0566a0c1407dbefef17a5977b27596b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via RestSharp/106.13.0.0

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

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

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

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