Skip to main content

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

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.1.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.1-py3-none-any.whl (80.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for opensquirrel-0.9.1.tar.gz
Algorithm Hash digest
SHA256 35edd824876ef648a45f01db7f432f37a2a552541cc417e20adb6a5aa766ecec
MD5 c17b83c8bc6661acf014a8b49238434f
BLAKE2b-256 fe2c8b43dd00e22ab1fc3c71c4904a4bc5fa37978f4433654e6121ba092433ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for opensquirrel-0.9.1.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.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for opensquirrel-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc3a51f080a4a5c7a1ee1508821e7942b8dd4330ca35617ee77e6b2583c58154
MD5 7422d4458df9b6a55fbf4523feb857d1
BLAKE2b-256 1be312fd8dd0e6fb5b9234a329d91f397c5a1f3ee5dad80ff0497161a29a00db

See more details on using hashes here.

Provenance

The following attestation bundles were made for opensquirrel-0.9.1-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 Sentry Error logging StatusPage Status page