OpenSquirrel: a flexible quantum program compiler.
,;;:;,
;;;;;
,:;;:; ,'=.
;:;:;' .=" ,'_\
':;:;,/ ,__:=@
';;:; =./)_
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:
- Defining and building the quantum circuit using either the
CircuitBuilderor from a cQASM string. - Executing (multiple) compilation passes on the circuit, each traversing and modifying it (e.g., decomposition of the gates).
- 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
Circuitobject is by default a cQASM string. Moreover, simply printing theCircuitobject 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 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| opensquirrel-0.9.1.tar.gz | 52.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| opensquirrel-0.9.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 132.6 kB
Release files / opensquirrel-0.9.1.tar.gz
| Download URL | opensquirrel-0.9.1.tar.gz |
|---|---|
| Size | 52.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35edd824876ef648a45f01db7f432f37a2a552541cc417e20adb6a5aa766ecec
|
|
BLAKE2b-256 checksum How to use checksums |
fe2c8b43dd00e22ab1fc3c71c4904a4bc5fa37978f4433654e6121ba092433ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Jul 30, 2026.
Transparency logRelease files / opensquirrel-0.9.1-py3-none-any.whl
| Download URL | opensquirrel-0.9.1-py3-none-any.whl |
|---|---|
| Size | 80.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc3a51f080a4a5c7a1ee1508821e7942b8dd4330ca35617ee77e6b2583c58154
|
|
BLAKE2b-256 checksum How to use checksums |
1be312fd8dd0e6fb5b9234a329d91f397c5a1f3ee5dad80ff0497161a29a00db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Jul 30, 2026.
Transparency log