A quantum circuit transformation and manipulation tool
Project description
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
CircuitBuilder
or 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
:
import math
from opensquirrel.circuit_builder import CircuitBuilder
from opensquirrel.ir import Qubit, Float
# Initialize the builder and build your circuit
builder = CircuitBuilder(qubit_register_size=1)
builder.H(Qubit(0)).Z(Qubit(0)).Y(Qubit(0)).Rx(Qubit(0), Float(math.pi / 3))
# Get the circuit from the circuit builder
qc = 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
qc = 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.decomposer.aba_decomposer import ZYZDecomposer
qc.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(qc)
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 theCircuit
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file opensquirrel-0.1.0.tar.gz
.
File metadata
- Download URL: opensquirrel-0.1.0.tar.gz
- Upload date:
- Size: 35.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ef746188922fc7d323d05ad2c96ae0240f60589feadbe0b2e83e93afdcf42b8 |
|
MD5 | ae07f6e5c68b78bafbe88d53a0d02968 |
|
BLAKE2b-256 | e96eb682afb4a15b87276a653c0079476a514c774d0848927b6f0a3e37479b17 |
File details
Details for the file opensquirrel-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: opensquirrel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 44.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 901690f3f8eacaff9a67d971fb43b70f1b2dc7e3c684ccc59225db5230dabb11 |
|
MD5 | e964bf6604fbdf44fbdea143e40b6d7f |
|
BLAKE2b-256 | 249d692ff794170becd5881d23bfaa3769520ab9fa875e4054d1e773205131f4 |