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.m(module.qubits[0], module.results[0])
qis.m(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*))
  %result0 = call %Result* @__quantum__qis__m__body(%Qubit* null)
  %result1 = call %Result* @__quantum__qis__m__body(%Qubit* inttoptr (i64 1 to %Qubit*))
  ret void
}

declare void @__quantum__qis__h__body(%Qubit*)

declare void @__quantum__qis__cnot__body(%Qubit*, %Qubit*)

declare %Result* @__quantum__qis__m__body(%Qubit*)

attributes #0 = { "EntryPoint" "requiredQubits"="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

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.4.0a1-cp36-abi3-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.6+ Windows x86-64

pyqir_generator-0.4.0a1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.2 MB view details)

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

pyqir_generator-0.4.0a1-cp36-abi3-macosx_10_7_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.6+ macOS 10.7+ x86-64

File details

Details for the file pyqir_generator-0.4.0a1-cp36-abi3-win_amd64.whl.

File metadata

  • Download URL: pyqir_generator-0.4.0a1-cp36-abi3-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.6+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.8.2 requests/2.25.1 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for pyqir_generator-0.4.0a1-cp36-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6f54a3bc5393b9fae67f239554b4a34d882e2ef76d34f3701862f45a9966448b
MD5 b670ebf745ab107865dd0a77f0313aeb
BLAKE2b-256 291e8e5d555225cf01292fa9d1d78f934e81b6f36c2695a122476e8efd6f70fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyqir_generator-0.4.0a1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 454eeda9dd464d47228221b04f3cfd4c7e9d52c16804fc5520a762fcc8797aec
MD5 8de5cb2eb99b73d991439f95db2e2c11
BLAKE2b-256 1a2859c2431f5864ec7428e861f7a0613b056f681f50745341623fdb8c4a720a

See more details on using hashes here.

File details

Details for the file pyqir_generator-0.4.0a1-cp36-abi3-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: pyqir_generator-0.4.0a1-cp36-abi3-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 4.8 MB
  • Tags: CPython 3.6+, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.8.2 requests/2.25.1 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for pyqir_generator-0.4.0a1-cp36-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 35719da1060d72df1b133bc2d85fa92739a0034408c6e792d6f7d066b2b13e3d
MD5 d8ce283241d911e653c2dc68876d4dde
BLAKE2b-256 dbc0fdfac7855df29814fcbf73216cd78e3baac4d92b8123d0ad98c7b740902e

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