pyqir


Namepyqir JSON
Version 0.10.2 PyPI version JSON
download
home_pagehttps://github.com/qir-alliance/pyqir
SummaryPyQIR parses, generates and evaluates the Quantum Intermediate Representation.
upload_time2024-05-22 17:17:58
maintainerNone
docs_urlNone
authorMicrosoft
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyQIR

The `pyqir` package provides the ability to generate
[QIR](https://github.com/qir-alliance/qir-spec) 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:

```bash
pip install pyqir
```

## Examples

PyQIR examples can be found in this repository's [examples folder](../examples).

### 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:

```python
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:

```llvm
; 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](../CONTRIBUTING.md) 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)](https://en.wikipedia.org/wiki/Contributor_License_Agreement) 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.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/qir-alliance/pyqir",
    "name": "pyqir",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Microsoft",
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# PyQIR\n\nThe `pyqir` package provides the ability to generate\n[QIR](https://github.com/qir-alliance/qir-spec) as well as an easy way to\nparse and analyze QIR.\n\nQIR generation is intended to be used by code automating translation processes\nenabling the conversion in some format to QIR via Python; i.e., this is a\nlow-level API intended to be used as a bridge to existing Python frameworks\nenabling the generation of QIR rather than directly consumed by an end-user. It\nis **not** intended to be used as a framework for algorithm and application\ndevelopment.\n\n## Installation\n\nThe package is released on PyPI and can be installed via pip:\n\n```bash\npip install pyqir\n```\n\n## Examples\n\nPyQIR examples can be found in this repository's [examples folder](../examples).\n\n### Generation\n\nThe following code creates QIR for a Bell pair before measuring each qubit and\nreturning the result. The unoptimized QIR is displayed in the terminal when\nexecuted:\n\n```python\nfrom pyqir import BasicQisBuilder, SimpleModule\n\nmodule = SimpleModule(\"Bell\", num_qubits=2, num_results=2)\nqis = BasicQisBuilder(module.builder)\n\nqis.h(module.qubits[0])\nqis.cx(module.qubits[0], module.qubits[1])\n\nqis.mz(module.qubits[0], module.results[0])\nqis.mz(module.qubits[1], module.results[1])\n\nprint(module.ir())\n```\n\nThe QIR output will look like:\n\n```llvm\n; ModuleID = 'Bell'\nsource_filename = \"Bell\"\n\n%Qubit = type opaque\n%Result = type opaque\n\ndefine void @main() #0 {\nentry:\n  call void @__quantum__qis__h__body(%Qubit* null)\n  call void @__quantum__qis__cnot__body(%Qubit* null, %Qubit* inttoptr (i64 1 to %Qubit*))\n  call void @__quantum__qis__mz__body(%Qubit* null, %Result* null)\n  call void @__quantum__qis__mz__body(%Qubit* inttoptr (i64 1 to %Qubit*), %Result* inttoptr (i64 1 to %Result*))\n  ret void\n}\n\ndeclare void @__quantum__qis__h__body(%Qubit*)\n\ndeclare void @__quantum__qis__cnot__body(%Qubit*, %Qubit*)\n\ndeclare void @__quantum__qis__mz__body(%Qubit*, %Result* writeonly) #1\n\nattributes #0 = { \"entry_point\" \"output_labeling_schema\" \"qir_profiles\"=\"custom\" \"required_num_qubits\"=\"2\" \"required_num_results\"=\"2\" }\nattributes #1 = { \"irreversible\" }\n\n!llvm.module.flags = !{!0, !1, !2, !3}\n\n!0 = !{i32 1, !\"qir_major_version\", i32 1}\n!1 = !{i32 7, !\"qir_minor_version\", i32 0}\n!2 = !{i32 1, !\"dynamic_qubit_management\", i1 false}\n!3 = !{i32 1, !\"dynamic_result_management\", i1 false}\n```\n\n## Contributing\n\nThere are many ways in which you can contribute to PyQIR, whether by\ncontributing a feature or by engaging in discussions; we value contributions in\nall shapes and sizes! We refer to [this document](../CONTRIBUTING.md) for\nguidelines and ideas for how you can get involved.\n\nContributing a pull request to this repo requires to agree to a [Contributor\nLicense Agreement\n(CLA)](https://en.wikipedia.org/wiki/Contributor_License_Agreement) declaring\nthat you have the right to, and actually do, grant us the rights to use your\ncontribution. A CLA-bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately. Simply follow the\ninstructions provided by the bot. You will only need to do this once.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PyQIR parses, generates and evaluates the Quantum Intermediate Representation.",
    "version": "0.10.2",
    "project_urls": {
        "Homepage": "https://github.com/qir-alliance/pyqir",
        "Source Code": "https://github.com/qir-alliance/pyqir"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8f5c70ddc6838622e006b7f8002473eb6a2ba9ec12712eb0800a16d97113d285",
                "md5": "75425b05b282b241463b507a4a57d6d4",
                "sha256": "c36bb36e8350bfa1c19a4dbca4532de68b7359909f67f28ddaa9fa645f9b7cdd"
            },
            "downloads": -1,
            "filename": "pyqir-0.10.2-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl",
            "has_sig": false,
            "md5_digest": "75425b05b282b241463b507a4a57d6d4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 3337343,
            "upload_time": "2024-05-22T17:17:58",
            "upload_time_iso_8601": "2024-05-22T17:17:58.379390Z",
            "url": "https://files.pythonhosted.org/packages/8f/5c/70ddc6838622e006b7f8002473eb6a2ba9ec12712eb0800a16d97113d285/pyqir-0.10.2-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "52e2e5a1ae3acae6f13b82365602d4de1330131306881de6f1ae0562ff8596e6",
                "md5": "06a43c4768093e66b19b98ed6dede0eb",
                "sha256": "2da2f25fed9048f3dcd80659abc1836456f9b476cd211fadb981a24f45d25af8"
            },
            "downloads": -1,
            "filename": "pyqir-0.10.2-cp38-abi3-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "06a43c4768093e66b19b98ed6dede0eb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 1720953,
            "upload_time": "2024-05-22T17:18:01",
            "upload_time_iso_8601": "2024-05-22T17:18:01.235461Z",
            "url": "https://files.pythonhosted.org/packages/52/e2/e5a1ae3acae6f13b82365602d4de1330131306881de6f1ae0562ff8596e6/pyqir-0.10.2-cp38-abi3-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "588395111a2d4c2a038d9c85fc3ff2209e1ecc04ebe97858efa18bb96837d4df",
                "md5": "ccd36a97ca811ffd8cbc199e4afb8d55",
                "sha256": "51f9e54f7e8c420a794fea8320f29f0bf03ca008c28c3e49e2d39a01da801673"
            },
            "downloads": -1,
            "filename": "pyqir-0.10.2-cp38-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "ccd36a97ca811ffd8cbc199e4afb8d55",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 1649279,
            "upload_time": "2024-05-22T17:18:04",
            "upload_time_iso_8601": "2024-05-22T17:18:04.148692Z",
            "url": "https://files.pythonhosted.org/packages/58/83/95111a2d4c2a038d9c85fc3ff2209e1ecc04ebe97858efa18bb96837d4df/pyqir-0.10.2-cp38-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "924e0ea27f4195f90837d13fc668608cebcc8db4be508c146bf174c82f9bfd5a",
                "md5": "19abad27c503f43a054ddc46eaf1ad29",
                "sha256": "e7e610b715b9cdbf507ee45b6b0f5d7731cda75369a57a09dd2fe6fe8e234da3"
            },
            "downloads": -1,
            "filename": "pyqir-0.10.2-cp38-abi3-manylinux_2_31_x86_64.whl",
            "has_sig": false,
            "md5_digest": "19abad27c503f43a054ddc46eaf1ad29",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 2215345,
            "upload_time": "2024-05-22T17:18:06",
            "upload_time_iso_8601": "2024-05-22T17:18:06.813832Z",
            "url": "https://files.pythonhosted.org/packages/92/4e/0ea27f4195f90837d13fc668608cebcc8db4be508c146bf174c82f9bfd5a/pyqir-0.10.2-cp38-abi3-manylinux_2_31_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4e9514d556db52595a1420cedc2883cddc156b45184b05bdfc39b5d45912ce53",
                "md5": "daf937683db4c6e3f9cb9e5612cd7ca7",
                "sha256": "e994938521af707d60af579e684af8271882f9b852916da4f6b4c535718d5e82"
            },
            "downloads": -1,
            "filename": "pyqir-0.10.2-cp38-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "daf937683db4c6e3f9cb9e5612cd7ca7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 1632870,
            "upload_time": "2024-05-22T17:18:09",
            "upload_time_iso_8601": "2024-05-22T17:18:09.209776Z",
            "url": "https://files.pythonhosted.org/packages/4e/95/14d556db52595a1420cedc2883cddc156b45184b05bdfc39b5d45912ce53/pyqir-0.10.2-cp38-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-22 17:17:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "qir-alliance",
    "github_project": "pyqir",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyqir"
}
        
Elapsed time: 0.28845s