Skip to main content

No project description provided

Project description

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.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

pyqir-0.12.5-cp39-abi3-win_arm64.whl (1.9 MB view details)

Uploaded CPython 3.9+Windows ARM64

pyqir-0.12.5-cp39-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.9+Windows x86-64

pyqir-0.12.5-cp39-abi3-manylinux_2_38_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.38+ ARM64

pyqir-0.12.5-cp39-abi3-manylinux_2_34_x86_64.whl (2.6 MB view details)

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

pyqir-0.12.5-cp39-abi3-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

pyqir-0.12.5-cp39-abi3-macosx_10_12_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file pyqir-0.12.5-cp39-abi3-win_arm64.whl.

File metadata

  • Download URL: pyqir-0.12.5-cp39-abi3-win_arm64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.9+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: RestSharp/106.13.0.0

File hashes

Hashes for pyqir-0.12.5-cp39-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1be238924839fa5edbae20fb5a039f0caabe349e96c20029e7decf180a7aa1ae
MD5 05340a1c80718a0996525d049217e4ed
BLAKE2b-256 a96e575bbfe2382e15c2c1e1a3062ba5f1f0b61d73da05b2ff1b130dbda1214b

See more details on using hashes here.

File details

Details for the file pyqir-0.12.5-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: pyqir-0.12.5-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: RestSharp/106.13.0.0

File hashes

Hashes for pyqir-0.12.5-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c70381e8e1e2db8e2a9d5aec484f51328b66f7ac9cc72989ba05a61d7689f950
MD5 75755c5625a12505d622bff45e2d2c97
BLAKE2b-256 04b2970e1621e372dffbb540cbb06518d0af4a16e63c074db61d60fb3d464ae2

See more details on using hashes here.

File details

Details for the file pyqir-0.12.5-cp39-abi3-manylinux_2_38_aarch64.whl.

File metadata

File hashes

Hashes for pyqir-0.12.5-cp39-abi3-manylinux_2_38_aarch64.whl
Algorithm Hash digest
SHA256 ced0baf85371393bae59c3c93a97d3de68217f43fde21b7be8c6ed31b1e00128
MD5 b15cc8b7d9ee45fdb39a9754ca34dbd1
BLAKE2b-256 319fe78010a4158e65be86b0013bccd5b0709ae87d8af9da82685464fb8e784c

See more details on using hashes here.

File details

Details for the file pyqir-0.12.5-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyqir-0.12.5-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4304984337a26cb01f8f0b0b0b436737e90379fbd0adfb48f142cfd942234384
MD5 d47eadf4eb0dea3a4463482811e44b25
BLAKE2b-256 5bb7da263a4c694b062d94b899a7248dec2238f965dc4ee58c69c6ba1263297e

See more details on using hashes here.

File details

Details for the file pyqir-0.12.5-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqir-0.12.5-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f568054dbb42b7fd33e0d5b58e7ac60ad6af496e9e1376fcb4a45290e9f510d
MD5 bf17b0aabf035b53cd22d9bb6385722b
BLAKE2b-256 8894a120794a8048291203b28c96e1c212243c45d8d99e2dad9002d67c0559ce

See more details on using hashes here.

File details

Details for the file pyqir-0.12.5-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyqir-0.12.5-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9bc8232f028f40e026cb72c7f654cf63f4c464ff4695874b70a45e8c34969665
MD5 c81dc679e702e7748c372549a54784e2
BLAKE2b-256 6e103b041f225dac208451f568188fd06524360ffc66ff855a1a205af0a895a0

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