Skip to main content

A quantum circuit transformation and manipulation tool

Project description

OpenSquirrel: a flexible quantum program compiler.

CI pypi image Ruff pytest License

 ,;;:;,
   ;;;;;
  ,:;;:;    ,'=.
  ;:;:;' .=" ,'_\
  ':;:;,/  ,__:=@
   ';;:;  =./)_
 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 quantum programming language, using 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).

$ pip install opensquirrel

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

$ pip install opensquirrel[examples]

Getting started

Once installed, the opensquirrel module can be imported accordingly:

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:

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:

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. In the example below, the circuit is decomposed using the Z-Y-Z decomposer.

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.

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 is hosted through GitHub Pages.

Contributing

The contribution guidelines and set up can be found here.

Licensing

OpenSquirrel is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Authors

Quantum Inspire: support@quantum-inspire.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opensquirrel-0.9.0.tar.gz (52.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opensquirrel-0.9.0-py3-none-any.whl (80.5 kB view details)

Uploaded Python 3

File details

Details for the file opensquirrel-0.9.0.tar.gz.

File metadata

  • Download URL: opensquirrel-0.9.0.tar.gz
  • Upload date:
  • Size: 52.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opensquirrel-0.9.0.tar.gz
Algorithm Hash digest
SHA256 b9fc1f2e588ada96db31b94b81ef41d82e6b1b9ef3ced005a1b1eb28b9212781
MD5 8f849f852b5e3c2a1cd751445cf7e676
BLAKE2b-256 d4073b5d88c7ae7adb6836992c4388e251a23300724417dcbf756f223dc0532f

See more details on using hashes here.

Provenance

The following attestation bundles were made for opensquirrel-0.9.0.tar.gz:

Publisher: release.yaml on QuTech-Delft/OpenSquirrel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opensquirrel-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: opensquirrel-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 80.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opensquirrel-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54bf018b411aa5943138e7c269fea447567d6794cdb34dfff1e0faee5db3dac8
MD5 428beab596ee2b506ffa517c40776a01
BLAKE2b-256 9579127447b361695af0fd6552f67f34bb9bbbe0a3ec2d9584b4484082726cba

See more details on using hashes here.

Provenance

The following attestation bundles were made for opensquirrel-0.9.0-py3-none-any.whl:

Publisher: release.yaml on QuTech-Delft/OpenSquirrel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page