Skip to main content

Python based QIR generator library.

Project description

pyqir-generator

The pyqir-generator package provides the ability to generate QIR using a Python API.

It 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-generator

Examples

There are generator examples in the repository.

Let's look at a short example. 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*)

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.

Building and Testing

See Building.

Current Limitations

Loops are not supported.

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_generator-0.6.0-cp36-abi3-win_amd64.whl (5.1 MB view details)

Uploaded CPython 3.6+ Windows x86-64

pyqir_generator-0.6.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.1 MB view details)

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

pyqir_generator-0.6.0-cp36-abi3-macosx_10_7_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.6+ macOS 10.7+ x86-64

File details

Details for the file pyqir_generator-0.6.0-cp36-abi3-win_amd64.whl.

File metadata

  • Download URL: pyqir_generator-0.6.0-cp36-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: CPython 3.6+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for pyqir_generator-0.6.0-cp36-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a66db0975a2b47a229559c112d91a6f3d1323e22560e28aaa5dab292eecab3fb
MD5 910aa2ef428e8653db6fe20c037e9d8b
BLAKE2b-256 f39641faf1930744957a223ea2e47e84906fde4a1ad373b68060879fc2755e45

See more details on using hashes here.

File details

Details for the file pyqir_generator-0.6.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: pyqir_generator-0.6.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 7.1 MB
  • Tags: CPython 3.6+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for pyqir_generator-0.6.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09207da64a9428dd67e2682f019c85ed8cc3f180c7b93186d70087e04d2defd5
MD5 c8e66a00fea3ef16666a0a955cdfecb2
BLAKE2b-256 7ecba1875e22b63de163524378829e7a71fa0575dd93c42ee0991a3390056821

See more details on using hashes here.

File details

Details for the file pyqir_generator-0.6.0-cp36-abi3-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: pyqir_generator-0.6.0-cp36-abi3-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.6+, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for pyqir_generator-0.6.0-cp36-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 6814c37173b711c27d2715aeb82ec01966be3c9e310dcc2fad1252a484b1b5f2
MD5 de494538cdc8e96a79003a6a3c83d6e9
BLAKE2b-256 945fd2a105cd48b5ec871e8fe5f2323673b30bd5e6129403d2a30bac1acd8775

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