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"
%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" "num_required_qubits"="2" "num_required_results"="2" "output_labeling_schema" "qir_profiles"="custom" }
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.
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
File details
Details for the file pyqir-0.8.2-cp37-abi3-win_amd64.whl
.
File metadata
- Download URL: pyqir-0.8.2-cp37-abi3-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.7+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a0b441a511a30168423016391246a10a318b272afb21005a4c2c69abb7545e |
|
MD5 | 14a15b1084e39710555cefe9f8aa2254 |
|
BLAKE2b-256 | b4204276604f34e4df5e006394dff2f1b4f4d850e5bea02b67fc023d7794a1df |
File details
Details for the file pyqir-0.8.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: pyqir-0.8.2-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.7+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b66cc0bb1a422e6c9f3821ba6d69e10896c7adf9b6751252934ec1d6de989752 |
|
MD5 | fe14733965a8b11a5ef2d1711b78bb3b |
|
BLAKE2b-256 | dd2007197ac6417e8b5fc203eb4e32e74d695d478aee265ed90a4bf4fc0127bc |
File details
Details for the file pyqir-0.8.2-cp37-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: pyqir-0.8.2-cp37-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.7+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd993ee01e7120ae0932df6d27c878819664c65120cbffbb03b2c8dd17f79299 |
|
MD5 | e2d73ad606fe9f870bd5a1bb901d9d57 |
|
BLAKE2b-256 | 2532b32d3ca5269217f09a03de39ed82cc336b83b21ce20e35c431172543e20b |
File details
Details for the file pyqir-0.8.2-cp37-abi3-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: pyqir-0.8.2-cp37-abi3-macosx_10_7_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.7+, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e50136edcd7051bbb7a3096c4b24f0cb5b8a866ead8590de7d3f7692141d8d84 |
|
MD5 | e2ba38b81a150f87b9e03fba017ea7eb |
|
BLAKE2b-256 | 06af38983c83a22f5b10ff6108e0ebc9f9141ac5660e73a513fa2d257b931603 |