Skip to main content

OpenSquirrel: a flexible quantum program compiler.

CI pypi image Ruff pytest License

OpenSquirrel logo

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 example folder. 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

Metadata

Release files for opensquirrel 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opensquirrel 1.0.0
File Size Uploaded Provenance Actions
opensquirrel-1.0.0.tar.gz 68.9 kB With provenance Details for opensquirrel-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for opensquirrel 1.0.0
File Interpreter ABI Platform Actions
opensquirrel-1.0.0-py3-none-any.whl Python 3 none any Details for opensquirrel-1.0.0-py3-none-any.whl

Total release size: 172.9 kB

Release files / opensquirrel-1.0.0.tar.gz

Download URL opensquirrel-1.0.0.tar.gz
Size 68.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ec1ea4f75ca74456465b8465fed2ba324e3b13cfe912fb2a28d0af5704e496e7
BLAKE2b-256 checksum
How to use checksums
f3d66d6e565e2054bf5463e84573e2d71426a8c43ab0455acd9d54506719f9e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / opensquirrel-1.0.0-py3-none-any.whl

Download URL opensquirrel-1.0.0-py3-none-any.whl
Size 104.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6e235f0fa7ed9d8b08832c97400dc69b1f5a306e381a4d562008a112d2f5b5f
BLAKE2b-256 checksum
How to use checksums
66163121108ac1d94e53e73ffbfb97a8aa1000063b1ff595f392a5494b4ac99b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for opensquirrel 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for opensquirrel-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page