opensquirrel


Nameopensquirrel JSON
Version 0.6.0 PyPI version JSON
download
home_pageNone
SummaryA quantum circuit transformation and manipulation tool
upload_time2025-08-28 12:34:14
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9.0
licenseNone
keywords circuits compilation quantum
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
from math import pi
from opensquirrel.circuit_builder import CircuitBuilder

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

# Get the circuit from the circuit builder
circuit = 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
circuit = 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.passes.decomposer.aba_decomposer import ZYZDecomposer

circuit.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(circuit)
```

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": null,
    "name": "opensquirrel",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9.0",
    "maintainer_email": null,
    "keywords": "circuits, compilation, quantum",
    "author": null,
    "author_email": "Quantum Inspire <support@quantum-inspire.com>",
    "download_url": "https://files.pythonhosted.org/packages/82/6d/0793d7e9788f367eec7a5a7bd8899e85da6480d90d7c8a9968df12878149/opensquirrel-0.6.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\nfrom math import pi\nfrom opensquirrel.circuit_builder import CircuitBuilder\n\n# Initialize the builder and build your circuit\nbuilder = CircuitBuilder(qubit_register_size=1)\nbuilder.H(0).Z(0).Y(0).Rx(0, pi / 3)\n\n# Get the circuit from the circuit builder\ncircuit = 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\ncircuit = 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.passes.decomposer.aba_decomposer import ZYZDecomposer\n\ncircuit.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(circuit)\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",
    "bugtrack_url": null,
    "license": null,
    "summary": "A quantum circuit transformation and manipulation tool",
    "version": "0.6.0",
    "project_urls": {
        "Homepage": "https://qutech-delft.github.io/OpenSquirrel/",
        "Repository": "https://github.com/QuTech-Delft/OpenSquirrel"
    },
    "split_keywords": [
        "circuits",
        " compilation",
        " quantum"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0a22dc7b46970db1807784e22fa73ae530095729b080433599bfe8b3b45807c9",
                "md5": "3e97789da2ca79c8936729088e0dd152",
                "sha256": "1dd1ef271fab9ad768a99452da6040d5e7ebdd5de014098c30d6518576972010"
            },
            "downloads": -1,
            "filename": "opensquirrel-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3e97789da2ca79c8936729088e0dd152",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.0",
            "size": 70612,
            "upload_time": "2025-08-28T12:34:12",
            "upload_time_iso_8601": "2025-08-28T12:34:12.745307Z",
            "url": "https://files.pythonhosted.org/packages/0a/22/dc7b46970db1807784e22fa73ae530095729b080433599bfe8b3b45807c9/opensquirrel-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "826d0793d7e9788f367eec7a5a7bd8899e85da6480d90d7c8a9968df12878149",
                "md5": "9e4ee440a02eca2a9589cc4987de3cf2",
                "sha256": "68427422a806a3c4ad550fdca0342ed22dcf1f94c65d499d8ea38c0b7678f1c0"
            },
            "downloads": -1,
            "filename": "opensquirrel-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "9e4ee440a02eca2a9589cc4987de3cf2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0",
            "size": 45319,
            "upload_time": "2025-08-28T12:34:14",
            "upload_time_iso_8601": "2025-08-28T12:34:14.461433Z",
            "url": "https://files.pythonhosted.org/packages/82/6d/0793d7e9788f367eec7a5a7bd8899e85da6480d90d7c8a9968df12878149/opensquirrel-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-28 12:34:14",
    "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: 3.00579s