Skip to main content

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


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

pyqir-0.8.1-cp37-abi3-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.7+ Windows x86-64

pyqir-0.8.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

pyqir-0.8.1-cp37-abi3-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

pyqir-0.8.1-cp37-abi3-macosx_10_7_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

File details

Details for the file pyqir-0.8.1-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: pyqir-0.8.1-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

Hashes for pyqir-0.8.1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d71cad8898097481f2b39c0d72875f99dd069213a3b8219fab4cfcc44f3d9ade
MD5 1cb05af37a45a25f3487df3b5a6b7f40
BLAKE2b-256 a66a78bb10df614ead481f9e8dbe126e2a22c6b7e43bcdd6f605a243d3d4d09b

See more details on using hashes here.

File details

Details for the file pyqir-0.8.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyqir-0.8.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 077ad71f0f28cc7ae193aed0bd891f6165062afd7d67fa7b2d4dad103623bb9b
MD5 fed0e6dcfe2449e4ca5628bc116244af
BLAKE2b-256 42aaf8e2edd50ffed7096eafb84a4f543612cdbc64676fe9bbb5b0fe54394d77

See more details on using hashes here.

File details

Details for the file pyqir-0.8.1-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqir-0.8.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 104e3b405cd68b650fe7b773bd17c6aa19ef9878e0988290f711bf0b4b33dd51
MD5 2e114aa1c7b0cf4b71e1dafb2568378a
BLAKE2b-256 e60aca3b9d57653ddcd4ab36174293b4a004e2b3bf47b893f14b953b5259ffa2

See more details on using hashes here.

File details

Details for the file pyqir-0.8.1-cp37-abi3-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for pyqir-0.8.1-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 1f0598ef7800352025392cb42f6c3b37e824a3720e0f403b105dec561fd0df18
MD5 8b0cd96fe96df80935cd4cadaa32dfaf
BLAKE2b-256 3492724542a75c6e68d9864d5195939e2e9f3fface8873f04733a233693e9177

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page