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.generator 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)

attributes #0 = { "EntryPoint" "requiredQubits"="2" "requiredResults"="2" }

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.0a1-cp37-abi3-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.7+ Windows x86-64

pyqir-0.8.0a1-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.0a1-cp37-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

pyqir-0.8.0a1-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.0a1-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: pyqir-0.8.0a1-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.9.6

File hashes

Hashes for pyqir-0.8.0a1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 51094521c3d90e47edcfbac247aaa248164b433be4e3b16b5a4b94526b612c32
MD5 612ebe027fa56f2f9613af65ce5b03eb
BLAKE2b-256 7a25f3434a57af18879737ef1a51125e49fa0b10335c6b10d1d4c22c5d20d1f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqir-0.8.0a1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bc923f359c39578c6d7f7efd0c68b1c65608382e49e9d269c25c0d14ac09f53b
MD5 8bc845d33ee78f8ac8f30e3e4e06cd14
BLAKE2b-256 948f47096091c56971c771163508a724ec536a8f5872eff780621330bc32174d

See more details on using hashes here.

File details

Details for the file pyqir-0.8.0a1-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqir-0.8.0a1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 23f4cda2ee31de4cfc8c609bd12359e467b15df11dddafcf6274b9cfcf2d9193
MD5 179e767bd2a5aee22565f5927c16061b
BLAKE2b-256 aa4c5d70744ce62ad79120c8582f58c7da841462af6f26772584c1e33f3df8c6

See more details on using hashes here.

File details

Details for the file pyqir-0.8.0a1-cp37-abi3-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for pyqir-0.8.0a1-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 379b2f6da00de77eda24c5cd479956224e8a9a61caad89f12823ee342106c7eb
MD5 e1b9334a4cca2a795b092134311f8788
BLAKE2b-256 2671fb0eb5d0198730072d7317a9c101189aa07686a215cd4df63586fab1ce44

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