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
- Classical computation and control flow are not yet fully supported.
- Only branching based on measurement results is currently possible.
- See issue #2: Support control flow and classical computation in PyQIR Generator.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for pyqir_generator-0.4.2a1-cp36-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67da2ce8dfac1531e9c1e45d8957e3e7393f23c9bdef0cb6838c374f48e2226b |
|
MD5 | 34719659f5f24e3a4922acb9478b881d |
|
BLAKE2b-256 | d9c34d95b798faf210d109a7b8e6c6c4aca032acc40c84820d18cf694d055038 |
Hashes for pyqir_generator-0.4.2a1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 704c4649efe61fc6073088308767d8a67e9a42b5ca3f8ac1d0d55fde7fadbeea |
|
MD5 | 3589223e6ad6718283e464164ae1d04a |
|
BLAKE2b-256 | 765b915dd50c9bcbb597826421daa0a07c5f407796218275f6fc73d124bfc31f |
Hashes for pyqir_generator-0.4.2a1-cp36-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14c7d7e951cfb97f83bb5424a2a0c901d560ad4635850d0b0c7096d01f909ca8 |
|
MD5 | 3db5d06cdbbaea2a247d0007c6b3f6a8 |
|
BLAKE2b-256 | 022b695f16b445e6c78916b543f6b8fe5cdd5850f9d095971aafcb3fa512130c |