PyQIR parses, generates and evaluates the Quantum Intermediate Representation.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyqir-0.12.3-cp39-abi3-win_arm64.whl.
File metadata
- Download URL: pyqir-0.12.3-cp39-abi3-win_arm64.whl
- Upload date:
- Size: 1.8 MB
- Tags: CPython 3.9+, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf25cdb2e750cb1a9ebe205c7ad27fe1a188cb2c01e15072389ec5b88df0e37b
|
|
| MD5 |
d1073818cca05e456cf379639da43fa7
|
|
| BLAKE2b-256 |
5fa1e923765c9b1bcfb22a9c48aea2fc90bd11c0fd6e770c1f5bd48d60843803
|
File details
Details for the file pyqir-0.12.3-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: pyqir-0.12.3-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0516b7f5f44987647398f8f589424a720878928d3178b2a852783e9cf2ff204
|
|
| MD5 |
82213467239e00e970f1c97fa87f6fc7
|
|
| BLAKE2b-256 |
9ecd7482249691fbe1115ad4a59517ae72dde31e28dd1b4d27eba28b23b9821f
|
File details
Details for the file pyqir-0.12.3-cp39-abi3-manylinux_2_38_aarch64.whl.
File metadata
- Download URL: pyqir-0.12.3-cp39-abi3-manylinux_2_38_aarch64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.9+, manylinux: glibc 2.38+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37e5fd01d5e2261f522c9274c309a3e67210d0560c44209397a87818c1b7588c
|
|
| MD5 |
90dc1aeaa3d8883b1f7b58a4d36468c1
|
|
| BLAKE2b-256 |
928de071b2daf23ba8f5f1680c3ce184542e40118253ea3148355ce5d889cf32
|
File details
Details for the file pyqir-0.12.3-cp39-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: pyqir-0.12.3-cp39-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 2.6 MB
- Tags: CPython 3.9+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ceeb69a009c906a22569f048967c8e59c269f2ed5856116d1ce474a27b38c28
|
|
| MD5 |
d853e3b20ea4d63972c6e0de2391eba5
|
|
| BLAKE2b-256 |
50ba9bb1e84a2eb13058d2f1253805af52c7d14e531078c70f64f846623b3e4a
|
File details
Details for the file pyqir-0.12.3-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyqir-0.12.3-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb2c41c124dd05dabfafa934dd0a6228783fdd1b32b93effecd4128bb931f2e1
|
|
| MD5 |
e7c6f9155ccb921a02f4ea7e0ed1cf2d
|
|
| BLAKE2b-256 |
c90eef16d3deb2c8143746499b1b15172332bf95a5e5692da3f582b77179f3f8
|
File details
Details for the file pyqir-0.12.3-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: pyqir-0.12.3-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2e5298b14350b7edb1145ebedeeab61f260df880542c0b5d557991b2f49334f
|
|
| MD5 |
8727aa9b3acab749c654da93ebfc880d
|
|
| BLAKE2b-256 |
46484bab05ea1bc1ccb6e721d89957f1d9ebb833bf705fc68778740142324565
|