Skip to content

Commit 2e586b3

Browse files
authored
Release 0.1.0 (#353)
1 parent 8e3c6e4 commit 2e586b3

File tree

132 files changed

+13389
-6396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+13389
-6396
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN apt-get update -y && \
1010
apt-get clean
1111

1212
# Set up user
13-
ARG USER=vscode
13+
ARG USER=pydev
1414
ENV PATH /home/${USER}/.local/bin:$PATH
1515
RUN groupadd -r ${USER} && \
1616
useradd -m -r -s /bin/bash -g ${USER} ${USER} && \

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"build": {
44
"dockerfile": "Dockerfile",
55
"args": {
6-
"USER": "vscode"
6+
"USER": "pydev"
77
}
88
},
9-
"remoteUser": "vscode"
9+
"remoteUser": "pydev"
1010
}

.github/workflows/release.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Releases
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "release-*"
8+
release:
9+
types:
10+
- created
11+
12+
jobs:
13+
publish:
14+
name: Publish assets
15+
runs-on: "ubuntu-latest"
16+
permissions:
17+
id-token: write
18+
steps:
19+
- uses: actions/checkout@master
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.11"
24+
- name: Install poetry
25+
uses: abatilo/actions-poetry@v3
26+
with:
27+
poetry-version: "1.8.3"
28+
29+
# Setting the proper version
30+
- name: Get previous Tag
31+
if: contains(github.ref, 'refs/heads/release-')
32+
id: previous_tag
33+
uses: WyriHaximus/github-action-get-previous-tag@v1
34+
with:
35+
fallback: 0.1.0
36+
- name: Set Build version
37+
if: contains(github.ref, 'refs/heads/release-')
38+
run: poetry version "${{ steps.previous_tag.outputs.tag }}.dev${{ github.run_number }}"
39+
- name: Set Release version
40+
if: github.event_name == 'release' && github.event.action == 'created'
41+
run: poetry version ${{ github.ref_name }}
42+
43+
# Build package
44+
- name: Build poetry package
45+
run: poetry build
46+
47+
# Publishing the package
48+
- name: Publish distribution 📦 to Test PyPI
49+
if: contains(github.ref, 'refs/heads/release-')
50+
uses: pypa/gh-action-pypi-publish@release/v1
51+
with:
52+
repository-url: https://test.pypi.org/legacy/
53+
verbose: true
54+
- name: Publish distribution 📦 to PyPI
55+
if: github.event_name == 'release' && github.event.action == 'created'
56+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/tests.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Set up Python
16-
uses: actions/setup-python@v4
16+
uses: actions/setup-python@v5
1717
with:
1818
python-version: "3.11"
1919
- name: Install poetry
20-
uses: abatilo/actions-poetry@v2
20+
uses: abatilo/actions-poetry@v3
2121
with:
2222
poetry-version: "1.3.2"
2323
- name: Install tox
2424
run: pip install tox
2525
- name: run tox lint and type
26-
run: tox -e lint #,type
26+
run: tox -e lint,type
2727
unit-test:
2828
name: Unit testing
2929
needs: lint
@@ -35,7 +35,6 @@ jobs:
3535
- macos-latest
3636
- windows-latest
3737
python-version:
38-
- "3.8"
3938
- "3.9"
4039
- "3.10"
4140
- "3.11"
@@ -44,11 +43,11 @@ jobs:
4443
steps:
4544
- uses: actions/checkout@v4
4645
- name: Set up Python
47-
uses: actions/setup-python@v4
46+
uses: actions/setup-python@v5
4847
with:
4948
python-version: ${{ matrix.python-version }}
5049
- name: Install poetry
51-
uses: abatilo/actions-poetry@v2
50+
uses: abatilo/actions-poetry@v3
5251
with:
5352
poetry-version: "1.3.2"
5453
- name: Install tox

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ instance/
6868
# Scrapy stuff:
6969
.scrapy
7070

71-
# Sphinx documentation
72-
docs/_build/
71+
# MkDocs documentation
72+
site/
7373

7474
# PyBuilder
7575
.pybuilder/
7676
target/
7777

7878
# Jupyter Notebook
7979
.ipynb_checkpoints
80+
example/tutorials/.ipynb_checkpoints
8081

8182
# IPython
8283
profile_default/
@@ -127,6 +128,7 @@ venv/
127128
ENV/
128129
env.bak/
129130
venv.bak/
131+
venv38/
130132

131133
# Spyder project settings
132134
.spyderproject
@@ -153,6 +155,7 @@ dmypy.json
153155
cython_debug/
154156

155157
# PyCharm
158+
.idea/
156159
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157160
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158161
# and can be added to the global gitignore or merged into this file. For a more nuclear

CONTRIBUTING.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
We recommend working on a feature branch and pull request from there.
2+
3+
## Requirements
4+
5+
- `poetry`,
6+
- `PyCharm` (recommended).
7+
8+
## Creating a feature branch
9+
10+
Make sure your environment contains all the updated versions of the dependencies.
11+
12+
From an OpenSquirrel checkout:
13+
14+
```
15+
$ poetry shell
16+
$ poetry install
17+
```
18+
19+
And that you base your feature branch off an updated `develop`.
20+
21+
From a `poetry` shell (started from an OpenSquirrel checkout):
22+
23+
```
24+
$ git checkout develop
25+
$ git fetch origin
26+
$ git pull
27+
$ git branch <feature branch name>
28+
```
29+
30+
## Before creating the pull request
31+
32+
Make sure the tests and the following linters pass.
33+
From a `poetry` shell (started from an OpenSquirrel checkout):
34+
35+
```
36+
$ poetry run pytest . -vv
37+
$ poetry run ruff check --fix
38+
$ poetry run ruff format
39+
$ poetry run mypy opensquirrel --strict
40+
```
41+
42+
## Setting the Python interpreter (PyCharm)
43+
44+
You can choose the Python interpreter from the `poetry` environment.
45+
46+
- Go to `Settings` > `Project: OpenSquirrel` > `Python Interpreter`.
47+
- Click on `Add Interpeter`, and then select `Add Local Interpreter`.
48+
- Select `Poetry Environment`, and then `Existing environment`.
49+
- Click on `...` to navigate to the `Interpreter` binary.
50+
51+
## Running/Debugging tests (PyCharm)
52+
53+
To run/debug all tests:
54+
55+
- Right-click on the `test` folder of the Project tree.
56+
- Click `Run 'pytest' in test` or `Debug 'pytest' in test`.
57+
58+
This will also create a `Run/Debug Configuration`.
59+
60+
### Troubleshooting
61+
62+
If breakpoints are not hit during debugging:
63+
64+
- Go to `Run/Debug Configurations`.
65+
- Add `--no-cov` in the `Additional arguments` text box.
66+
67+
This issue may be due to the code coverage module _hijacking_ the tracing mechanism
68+
(check [this link](https://stackoverflow.com/a/56235965/260313) for a more detailed explanation).

LICENSE renamed to LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2023 Quantum Inspire: QuTech (TNO, TU Delft)
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 118 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
### Mini-compiler for Quantum Inspire's quantum chip[munks]
1+
# OpenSquirrel: a flexible quantum program compiler.
2+
3+
![CI](https://github.com/QuTech-Delft/OpenSquirrel/actions/workflows/tests.yaml/badge.svg)
4+
[![pypi](https://img.shields.io/pypi/v/opensquirrel.svg)](https://pypi.org/project/opensquirrel/)
5+
[![image](https://img.shields.io/pypi/pyversions/opensquirrel.svg)](https://pypi.python.org/pypi/opensquirrel)
6+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
7+
[![pytest](https://img.shields.io/badge/py-test-blue?logo=pytest)](https://github.com/pytest-dev/pytest)
8+
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
29

310
```
411
,;;:;,
@@ -11,43 +18,133 @@
1118
``'"`
1219
```
1320

14-
# Installation
21+
OpenSquirrel is a quantum compiler that chooses a _modular_, over a _configurable_,
22+
approach to prepare and optimize quantum circuits for heterogeneous target architectures.
23+
24+
It has a user-friendly interface and is straightforwardly extensible with custom-made readers,
25+
compiler passes, and exporters.
26+
As a quantum circuit compiler,
27+
it is fully aware of the semantics of each gate and arbitrary quantum gates can be constructed manually.
28+
It supports the [cQASM](https://qutech-delft.github.io/cQASM-spec/latest/) quantum programming language,
29+
using [libQASM](https://github.com/QuTech-Delft/libqasm) as language parser.
30+
It is developed in modern Python and follows best practices.
31+
32+
## Installation
1533

16-
## General installation
34+
OpenSquirrel can be easily installed from PyPI.
35+
We recommend using a virtual environment (_e.g._, venv).
1736

1837
```shell
1938
$ pip install opensquirrel
2039
```
2140

22-
## Editable installation
41+
To install the dependencies to run the examples on `jupyter`, install:
2342

24-
To perform an editable install, run the following command in the root directory of `OpenSquirrel` with the `-e` flag
2543
```shell
26-
$ pip install -e .
44+
$ pip install opensquirrel[examples]
2745
```
2846

29-
To install the developer specific dependencies, run the command
30-
```shell
31-
$ pip install -e '.[dev]'
47+
## Getting started
48+
49+
Once installed, the `opensquirrel` module can be imported accordingly:
50+
51+
```python
52+
import opensquirrel
3253
```
3354

34-
# Documentation
55+
Essentially, compiling a quantum circuit in OpenSquirrel can be seen as a 3-stage process:
56+
1. Defining and building the quantum circuit using either the `CircuitBuilder` or from a cQASM string.
57+
2. Executing (multiple) compilation passes on the circuit,
58+
each traversing and modifying it (_e.g._, decomposition of the gates).
59+
3. Writing the circuit to cQASM or exporting it to a specific quantum circuit format.
60+
61+
Here is an example of building a circuit using the `CircuitBuilder`:
3562

36-
The package exposes only the `Circuit` class, whose up-to-date documentation is accessed:
63+
```python
64+
import math
65+
from opensquirrel.circuit_builder import CircuitBuilder
66+
from opensquirrel.ir import Qubit, Float
3767

38-
- from the Python console:
39-
```pycon
40-
>>> import opensquirrel
41-
>>> help(opensquirrel.Circuit)
68+
# Initialize the builder and build your circuit
69+
builder = CircuitBuilder(qubit_register_size=1)
70+
builder.H(Qubit(0)).Z(Qubit(0)).Y(Qubit(0)).Rx(Qubit(0), Float(math.pi / 3))
71+
72+
# Get the circuit from the circuit builder
73+
qc = builder.to_circuit()
4274
```
4375

44-
- from a Linux shell: `python3 -c "import opensquirrel; help(opensquirrel.Circuit)"`
76+
Alternatively, one can define the same circuit as a cQASM string:
4577

46-
Currently there is also a set of default gates exposed as `opensquirrel.DefaultGates` to use in the `Circuit` constructor.
78+
```python
79+
cqasm_string = ("""
80+
version 3.0
4781
48-
# Testing
82+
qubit q
4983
50-
To run the tests, run the following command in the root directory of `OpenSquirrel`
51-
```shell
52-
$ pytest
84+
H q
85+
Z q
86+
Y q
87+
Rx(1.0471976) q
88+
""")
89+
90+
from opensquirrel.circuit import Circuit
91+
qc = Circuit.from_string(cqasm_string)
92+
```
93+
94+
The circuit can then be decomposed using a decomposition strategy.
95+
The different decomposition strategies can be found in the
96+
[examples](https://github.com/QuTech-Delft/OpenSquirrel/tree/develop/example/tutorials).
97+
In the example below, the circuit is decomposed using the Z-Y-Z decomposer.
98+
99+
```python
100+
from opensquirrel.decomposer.aba_decomposer import ZYZDecomposer
101+
102+
qc.decompose(decomposer=ZYZDecomposer())
103+
```
104+
105+
Once the circuit is decomposed, it can be written back to cQASM.
106+
This is done by invoking the `writer` class, as can be seen below.
107+
108+
```python
109+
from opensquirrel.writer import writer
110+
111+
writer.circuit_to_string(qc)
53112
```
113+
114+
The output is then given by the following cQASM string:
115+
116+
version 3.0
117+
118+
qubit[1] q
119+
120+
Rz(3.1415927) q[0]
121+
Ry(1.5707963) q[0]
122+
Rz(3.1415927) q[0]
123+
Ry(3.1415927) q[0]
124+
Rz(1.5707963) q[0]
125+
Ry(1.0471976) q[0]
126+
Rz(-1.5707963) q[0]
127+
128+
> __*Note*__: The cQASM writer is the standard writer of OpenSquirrel.
129+
> 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.
130+
131+
## Documentation
132+
133+
The [OpenSquirrel documentation](https://QuTech-Delft.github.io/OpenSquirrel/) is hosted through GitHub Pages.
134+
135+
136+
## Contributing
137+
138+
The contribution guidelines and set up can be found
139+
[here](https://github.com/QuTech-Delft/OpenSquirrel/blob/develop/CONTRIBUTING.md).
140+
141+
142+
## Licensing
143+
144+
OpenSquirrel is licensed under the Apache License, Version 2.0. See
145+
[LICENSE](https://github.com/QuTech-Delft/OpenSquirrel/blob/master/LICENSE.md) for the full license text.
146+
147+
148+
## Authors
149+
150+
Quantum Inspire: [support@quantum-inspire.com](mailto:"support@quantum-inspire.com")
1.07 KB
Loading
1.11 KB
Loading

docs/_static/terminal_icon.png

66.6 KB
Loading

0 commit comments

Comments
 (0)