Skip to main content

PyQIR parses, generates and evaluates the Quantum Intermediate Representation.

Reason this release was yanked:

Apple aarch64 wheels fail to load

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" "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 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.10.1-cp38-abi3-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.8+ Windows x86-64

pyqir-0.10.1-cp38-abi3-manylinux_2_31_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.31+ x86-64

pyqir-0.10.1-cp38-abi3-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

pyqir-0.10.1-cp38-abi3-macosx_10_12_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.8+ macOS 10.12+ x86-64

pyqir-0.10.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (3.3 MB view details)

Uploaded CPython 3.8+ macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

File details

Details for the file pyqir-0.10.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pyqir-0.10.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: RestSharp/106.13.0.0

File hashes

Hashes for pyqir-0.10.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ab830a648515b9b8c081ef0baf77a6082c8e6d7f9ee2bf156a6a0c3db96f622c
MD5 63b8feca986fba33ce3cfb06abc1ce24
BLAKE2b-256 a4d7f6c6f7a2185c8c2c7806cc5f1fd8e8b82326ce48a0068ca7e720bb3cb5a1

See more details on using hashes here.

File details

Details for the file pyqir-0.10.1-cp38-abi3-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for pyqir-0.10.1-cp38-abi3-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 b163d20c8dbe7e006cab34c6037b6935ecca3e0b832dfeac2766c132a73ddaeb
MD5 4fd79b2c76f1d82e749d62e719273de7
BLAKE2b-256 1a14d81d1a905620ff4227fdd17b4af346785783cb1d11745fe2ae729fe43ef0

See more details on using hashes here.

File details

Details for the file pyqir-0.10.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqir-0.10.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a1bb6737febf00d02bc9a793d89d697f73b91dfe57d34dbb1fa0a141f55fcf0
MD5 8f1415a9e0ebe3d68c03277685a760db
BLAKE2b-256 445db46687fadda7090e1975fd3566bf8db1b3a7251b801ad14ef0de0ed433a0

See more details on using hashes here.

File details

Details for the file pyqir-0.10.1-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyqir-0.10.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ac9f7f6264d0795759f83e15a81e349a33f3ef74dc129ef06e270d803de8f709
MD5 98d2851d6d80050696fdf26577a25c9a
BLAKE2b-256 999595c78eb6faf92ca981b9c325936bd66a8e18e6c81e73a5d6bff9bc6888c3

See more details on using hashes here.

File details

Details for the file pyqir-0.10.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pyqir-0.10.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f72fd46673c52aded152765bc6ff14136afe6d668c391807e28ef2bf06e7c969
MD5 11975b23fa8cd95dd4860adda28e24ba
BLAKE2b-256 bcdd76b19304b817a0620dd9f57f71ff9835e9f5306a309e6e3b0722c06ca5cd

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