opensquirrel


Nameopensquirrel JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/QuTech-Delft/OpenSquirrel
SummaryA quantum circuit transformation and manipulation tool
upload_time2024-10-10 14:06:01
maintainerNone
docs_urlNone
authorQuantum Inspire
requires_python<4.0,>=3.9
licenseApache-2.0
keywords quantum circuits compilation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OpenSquirrel: a flexible quantum program compiler.

![CI](https://github.com/QuTech-Delft/OpenSquirrel/actions/workflows/tests.yaml/badge.svg)
[![pypi](https://img.shields.io/pypi/v/opensquirrel.svg)](https://pypi.org/project/opensquirrel/)
[![image](https://img.shields.io/pypi/pyversions/opensquirrel.svg)](https://pypi.python.org/pypi/opensquirrel)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![pytest](https://img.shields.io/badge/py-test-blue?logo=pytest)](https://github.com/pytest-dev/pytest)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

```
 ,;;:;,
   ;;;;;
  ,:;;:;    ,'=.
  ;:;:;' .=" ,'_\
  ':;:;,/  ,__:=@
   ';;:;  =./)_
 jgs `"=\_  )_"`
          ``'"`
```

OpenSquirrel is a quantum compiler that chooses a _modular_, over a _configurable_,
approach to prepare and optimize quantum circuits for heterogeneous target architectures.

It has a user-friendly interface and is straightforwardly extensible with custom-made readers,
compiler passes, and exporters.
As a quantum circuit compiler,
it is fully aware of the semantics of each gate and arbitrary quantum gates can be constructed manually.
It supports the [cQASM](https://qutech-delft.github.io/cQASM-spec/latest/) quantum programming language,
using [libQASM](https://github.com/QuTech-Delft/libqasm) as language parser.
It is developed in modern Python and follows best practices.

## Installation

OpenSquirrel can be easily installed from PyPI.
We recommend using a virtual environment (_e.g._, venv).

```shell
$ pip install opensquirrel
```

To install the dependencies to run the examples on `jupyter`, install:

```shell
$ pip install opensquirrel[examples]
```

## Getting started

Once installed, the `opensquirrel` module can be imported accordingly:

```python
import opensquirrel
```

Essentially, compiling a quantum circuit in OpenSquirrel can be seen as a 3-stage process:
1. Defining and building the quantum circuit using either the `CircuitBuilder` or from a cQASM string.
2. Executing (multiple) compilation passes on the circuit,
each traversing and modifying it (_e.g._, decomposition of the gates).
3. Writing the circuit to cQASM or exporting it to a specific quantum circuit format.

Here is an example of building a circuit using the `CircuitBuilder`:

```python
import math
from opensquirrel.circuit_builder import CircuitBuilder
from opensquirrel.ir import Qubit, Float

# Initialize the builder and build your circuit
builder = CircuitBuilder(qubit_register_size=1)
builder.H(Qubit(0)).Z(Qubit(0)).Y(Qubit(0)).Rx(Qubit(0), Float(math.pi / 3))

# Get the circuit from the circuit builder
qc = builder.to_circuit()
```

Alternatively, one can define the same circuit as a cQASM string:

```python
cqasm_string = ("""
    version 3.0

    qubit q

    H q
    Z q
    Y q
    Rx(1.0471976) q
""")

from opensquirrel.circuit import Circuit
qc = Circuit.from_string(cqasm_string)
```

The circuit can then be decomposed using a decomposition strategy.
The different decomposition strategies can be found in the
[examples](https://github.com/QuTech-Delft/OpenSquirrel/tree/develop/example/tutorials).
In the example below, the circuit is decomposed using the Z-Y-Z decomposer.

```python
from opensquirrel.decomposer.aba_decomposer import ZYZDecomposer

qc.decompose(decomposer=ZYZDecomposer())
```

Once the circuit is decomposed, it can be written back to cQASM.
This is done by invoking the `writer` class, as can be seen below.

```python
from opensquirrel.writer import writer

writer.circuit_to_string(qc)
```

The output is then given by the following cQASM string:

    version 3.0

    qubit[1] q

    Rz(3.1415927) q[0]
    Ry(1.5707963) q[0]
    Rz(3.1415927) q[0]
    Ry(3.1415927) q[0]
    Rz(1.5707963) q[0]
    Ry(1.0471976) q[0]
    Rz(-1.5707963) q[0]

> __*Note*__: The cQASM writer is the standard writer of OpenSquirrel.
> This means that the string representation of the `Circuit` object is by default a cQASM string. Moreover, simply printing the `Circuit` object will result in its cQASM string representation.

## Documentation

The [OpenSquirrel documentation](https://QuTech-Delft.github.io/OpenSquirrel/) is hosted through GitHub Pages.


## Contributing

The contribution guidelines and set up can be found
[here](https://github.com/QuTech-Delft/OpenSquirrel/blob/develop/CONTRIBUTING.md).


## Licensing

OpenSquirrel is licensed under the Apache License, Version 2.0. See
[LICENSE](https://github.com/QuTech-Delft/OpenSquirrel/blob/master/LICENSE.md) for the full license text.


## Authors

Quantum Inspire: [support@quantum-inspire.com](mailto:"support@quantum-inspire.com")


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/QuTech-Delft/OpenSquirrel",
    "name": "opensquirrel",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "quantum, circuits, compilation",
    "author": "Quantum Inspire",
    "author_email": "support@quantum-inspire.com",
    "download_url": "https://files.pythonhosted.org/packages/e9/6e/b682afb4a15b87276a653c0079476a514c774d0848927b6f0a3e37479b17/opensquirrel-0.1.0.tar.gz",
    "platform": null,
    "description": "# OpenSquirrel: a flexible quantum program compiler.\n\n![CI](https://github.com/QuTech-Delft/OpenSquirrel/actions/workflows/tests.yaml/badge.svg)\n[![pypi](https://img.shields.io/pypi/v/opensquirrel.svg)](https://pypi.org/project/opensquirrel/)\n[![image](https://img.shields.io/pypi/pyversions/opensquirrel.svg)](https://pypi.python.org/pypi/opensquirrel)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![pytest](https://img.shields.io/badge/py-test-blue?logo=pytest)](https://github.com/pytest-dev/pytest)\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n```\n ,;;:;,\n   ;;;;;\n  ,:;;:;    ,'=.\n  ;:;:;' .=\" ,'_\\\n  ':;:;,/  ,__:=@\n   ';;:;  =./)_\n jgs `\"=\\_  )_\"`\n          ``'\"`\n```\n\nOpenSquirrel is a quantum compiler that chooses a _modular_, over a _configurable_,\napproach to prepare and optimize quantum circuits for heterogeneous target architectures.\n\nIt has a user-friendly interface and is straightforwardly extensible with custom-made readers,\ncompiler passes, and exporters.\nAs a quantum circuit compiler,\nit is fully aware of the semantics of each gate and arbitrary quantum gates can be constructed manually.\nIt supports the [cQASM](https://qutech-delft.github.io/cQASM-spec/latest/) quantum programming language,\nusing [libQASM](https://github.com/QuTech-Delft/libqasm) as language parser.\nIt is developed in modern Python and follows best practices.\n\n## Installation\n\nOpenSquirrel can be easily installed from PyPI.\nWe recommend using a virtual environment (_e.g._, venv).\n\n```shell\n$ pip install opensquirrel\n```\n\nTo install the dependencies to run the examples on `jupyter`, install:\n\n```shell\n$ pip install opensquirrel[examples]\n```\n\n## Getting started\n\nOnce installed, the `opensquirrel` module can be imported accordingly:\n\n```python\nimport opensquirrel\n```\n\nEssentially, compiling a quantum circuit in OpenSquirrel can be seen as a 3-stage process:\n1. Defining and building the quantum circuit using either the `CircuitBuilder` or from a cQASM string.\n2. Executing (multiple) compilation passes on the circuit,\neach traversing and modifying it (_e.g._, decomposition of the gates).\n3. Writing the circuit to cQASM or exporting it to a specific quantum circuit format.\n\nHere is an example of building a circuit using the `CircuitBuilder`:\n\n```python\nimport math\nfrom opensquirrel.circuit_builder import CircuitBuilder\nfrom opensquirrel.ir import Qubit, Float\n\n# Initialize the builder and build your circuit\nbuilder = CircuitBuilder(qubit_register_size=1)\nbuilder.H(Qubit(0)).Z(Qubit(0)).Y(Qubit(0)).Rx(Qubit(0), Float(math.pi / 3))\n\n# Get the circuit from the circuit builder\nqc = builder.to_circuit()\n```\n\nAlternatively, one can define the same circuit as a cQASM string:\n\n```python\ncqasm_string = (\"\"\"\n    version 3.0\n\n    qubit q\n\n    H q\n    Z q\n    Y q\n    Rx(1.0471976) q\n\"\"\")\n\nfrom opensquirrel.circuit import Circuit\nqc = Circuit.from_string(cqasm_string)\n```\n\nThe circuit can then be decomposed using a decomposition strategy.\nThe different decomposition strategies can be found in the\n[examples](https://github.com/QuTech-Delft/OpenSquirrel/tree/develop/example/tutorials).\nIn the example below, the circuit is decomposed using the Z-Y-Z decomposer.\n\n```python\nfrom opensquirrel.decomposer.aba_decomposer import ZYZDecomposer\n\nqc.decompose(decomposer=ZYZDecomposer())\n```\n\nOnce the circuit is decomposed, it can be written back to cQASM.\nThis is done by invoking the `writer` class, as can be seen below.\n\n```python\nfrom opensquirrel.writer import writer\n\nwriter.circuit_to_string(qc)\n```\n\nThe output is then given by the following cQASM string:\n\n    version 3.0\n\n    qubit[1] q\n\n    Rz(3.1415927) q[0]\n    Ry(1.5707963) q[0]\n    Rz(3.1415927) q[0]\n    Ry(3.1415927) q[0]\n    Rz(1.5707963) q[0]\n    Ry(1.0471976) q[0]\n    Rz(-1.5707963) q[0]\n\n> __*Note*__: The cQASM writer is the standard writer of OpenSquirrel.\n> This means that the string representation of the `Circuit` object is by default a cQASM string. Moreover, simply printing the `Circuit` object will result in its cQASM string representation.\n\n## Documentation\n\nThe [OpenSquirrel documentation](https://QuTech-Delft.github.io/OpenSquirrel/) is hosted through GitHub Pages.\n\n\n## Contributing\n\nThe contribution guidelines and set up can be found\n[here](https://github.com/QuTech-Delft/OpenSquirrel/blob/develop/CONTRIBUTING.md).\n\n\n## Licensing\n\nOpenSquirrel is licensed under the Apache License, Version 2.0. See\n[LICENSE](https://github.com/QuTech-Delft/OpenSquirrel/blob/master/LICENSE.md) for the full license text.\n\n\n## Authors\n\nQuantum Inspire: [support@quantum-inspire.com](mailto:\"support@quantum-inspire.com\")\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A quantum circuit transformation and manipulation tool",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/QuTech-Delft/OpenSquirrel",
        "Repository": "https://github.com/QuTech-Delft/OpenSquirrel"
    },
    "split_keywords": [
        "quantum",
        " circuits",
        " compilation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "249d692ff794170becd5881d23bfaa3769520ab9fa875e4054d1e773205131f4",
                "md5": "e964bf6604fbdf44fbdea143e40b6d7f",
                "sha256": "901690f3f8eacaff9a67d971fb43b70f1b2dc7e3c684ccc59225db5230dabb11"
            },
            "downloads": -1,
            "filename": "opensquirrel-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e964bf6604fbdf44fbdea143e40b6d7f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 44776,
            "upload_time": "2024-10-10T14:05:58",
            "upload_time_iso_8601": "2024-10-10T14:05:58.835713Z",
            "url": "https://files.pythonhosted.org/packages/24/9d/692ff794170becd5881d23bfaa3769520ab9fa875e4054d1e773205131f4/opensquirrel-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e96eb682afb4a15b87276a653c0079476a514c774d0848927b6f0a3e37479b17",
                "md5": "ae07f6e5c68b78bafbe88d53a0d02968",
                "sha256": "5ef746188922fc7d323d05ad2c96ae0240f60589feadbe0b2e83e93afdcf42b8"
            },
            "downloads": -1,
            "filename": "opensquirrel-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ae07f6e5c68b78bafbe88d53a0d02968",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 35457,
            "upload_time": "2024-10-10T14:06:01",
            "upload_time_iso_8601": "2024-10-10T14:06:01.401651Z",
            "url": "https://files.pythonhosted.org/packages/e9/6e/b682afb4a15b87276a653c0079476a514c774d0848927b6f0a3e37479b17/opensquirrel-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-10 14:06:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "QuTech-Delft",
    "github_project": "OpenSquirrel",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "opensquirrel"
}
        
Elapsed time: 0.53670s