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"

%Qubit = type opaque
%Result = type opaque

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

declare void @__quantum__qis__h__body(%Qubit*)

declare void @__quantum__qis__cnot__body(%Qubit*, %Qubit*)

declare void @__quantum__qis__mz__body(%Qubit*, %Result* 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 1}
!1 = !{i32 7, !"qir_minor_version", i32 0}
!2 = !{i32 1, !"dynamic_qubit_management", i1 false}
!3 = !{i32 1, !"dynamic_result_management", i1 false}

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 iqm-pyqir 0.12.0

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 iqm-pyqir 0.12.0
File Actions
iqm_pyqir-0.12.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details for iqm_pyqir-0.12.0-cp38-abi3-win_amd64.whl
iqm_pyqir-0.12.0-cp38-abi3-manylinux_2_31_x86_64.whl CPython 3.8 abi3 Linux glibc 2.31+ x86-64 Details for iqm_pyqir-0.12.0-cp38-abi3-manylinux_2_31_x86_64.whl
iqm_pyqir-0.12.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details for iqm_pyqir-0.12.0-cp38-abi3-macosx_11_0_arm64.whl
iqm_pyqir-0.12.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.8 abi3 macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64 Details for iqm_pyqir-0.12.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Total release size: 7.9 MB

Release files / iqm_pyqir-0.12.0-cp38-abi3-win_amd64.whl

Download URL iqm_pyqir-0.12.0-cp38-abi3-win_amd64.whl
Size 1.7 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
73dc870519df09b60c303e421a61bcde563d0df8c11bb83ea206f17aa14a4ecd
BLAKE2b-256 checksum
How to use checksums
7b95e76f67f976b84b09208c86c6a1a06c3b49cbaf2c5bc1de228729f7915102
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / iqm_pyqir-0.12.0-cp38-abi3-manylinux_2_31_x86_64.whl

Download URL iqm_pyqir-0.12.0-cp38-abi3-manylinux_2_31_x86_64.whl
Size 2.3 MB
Tags CPython 3.8 Linux glibc 2.31+ x86-64 abi3
SHA-256 checksum
How to use checksums
28a1a2daeff5749fc8dea1122fe64a777b22a778d991cd9c8b7a8ae383efca8b
BLAKE2b-256 checksum
How to use checksums
6c219f3ad7f2b9a22c11dbd3f3bc1f0a593fc55fbf05c529ea651f73322b73df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / iqm_pyqir-0.12.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL iqm_pyqir-0.12.0-cp38-abi3-macosx_11_0_arm64.whl
Size 1.7 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8f508cda10e48be776c28482fd68b734e981ff57ae0366a0ee5f0e642e9b02e2
BLAKE2b-256 checksum
How to use checksums
9d39dc5883b5a767256a0e35c1e099f07f447cb3c49b556d2a574492a5f0cb97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / iqm_pyqir-0.12.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL iqm_pyqir-0.12.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 2.1 MB
Tags CPython 3.8 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
628ad8ef42bfd209e0a38c2a342b6bbf76cf1042164ac3218f57634178ce8fc4
BLAKE2b-256 checksum
How to use checksums
954dddcb71dd61d31c3fcdec0e402a59239ca3aa11a743975914bca71a7bd97e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Security for iqm-pyqir 0.12.0

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.0 This release

4 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