Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Nov 24, 2023
1 parent 6444603 commit 90dc071
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 19 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: documentation

on: [push, pull_request, workflow_dispatch]

permissions:
contents: write

jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Install dependencies
run: |
pip install sphinx sphinx_rtd_theme myst_parser
- name: Sphinx build
run: |
sphinx-build doc _build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: _build/
force_orphan: true
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def h(k: Qint4) -> bool:
return h
```


Qlasskit will take care of translating the function to boolean expressions, simplify them and
translate to a quantum circuit.

Expand All @@ -36,7 +37,7 @@ algo = Grover(h, True)
qc = algo.circuit().export("circuit", "qiskit")
```

And that's it:
And that's the result:

![Grover](docs/source/_images/grover_circ.png)

Expand Down
7 changes: 4 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@
- [x] Qint multiplier
- [x] Allow quantum gates inside sympy expressions
- [x] CNotSim dummy simulator for circuit testing
- [ ] Improve exporting utilities

## Month 3:

- [x] Improve exporting utilities
- [ ] Use cases
- [ ] Documentation

## Month 3:

### Week 1: (20 Nov 23)
### Week 2: (27 Nov 23)
Expand Down Expand Up @@ -144,7 +146,6 @@
- [ ] PyQrack (without qiskit provider)
- [ ] QuTip
- [ ] Pennylane
- [ ] Cirq
- [ ] Sympy quantum computing expressions

### Tools
Expand Down
1 change: 1 addition & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ API
:recursive:

qlasskit.qlassfun.qlassf
qlasskit.qlassfun.qlassfa
qlasskit.qlassfun.QlassF
qlasskit.algorithms.qalgorithm
qlasskit.algorithms.grover.Grover
Expand Down
22 changes: 11 additions & 11 deletions docs/source/howitworks.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
How it works
============

In order to translate python code to quantum circuit, qlasskit performs several transformations;
To convert Python code into a quantum circuit, qlasskit implements a series of transformations:

1. it starts from the python *AST* (abstract syntax tree) rewriting it to a simplified version
by the _ast2ast_ module.
2. Then the simplified *AST* is translated to *boolean expressions* as intermediate
form by the _ast2logic_ module. In this step, boolean expression are simplified and optimized
for the final transformation.
3. Finally, these boolean expressions are compiled into a *quantum circuit* by the _compiler_ module.
1. It begins with the Python *AST* (Abstract Syntax Tree), converting it into a more streamlined form using the _ast2ast_ module.
2. Next, the streamlined AST is translated into *boolean expressions* as an intermediate step by the _ast2logic_ module.
During this phase, boolean expressions are refined and optimized in preparation for the final transformation.
3. Finally, the _compiler_ module takes these optimized boolean expressions and compiles them into a
*quantum circuit*.

Unlike other libraries that translate individual operations into quantum circuits before combining them,
qlasskit constructs a singular boolean expression for each output qubit of the entire function.
This unique approach facilitates advanced optimization leveraging boolean algebraic properties.

While other existing libraries translate individual operations into quantum circuits and then
combine them, qlasskit creates a single boolean expression for every output qubit of the entire
function. This approach allows for further optimization using boolean properties.

For instance, let assume we have the following function:

Expand Down Expand Up @@ -91,7 +91,7 @@ Is translated to this boolean expression:
Compiler
------------
The boolean expressions are then being fed to the `qlasskit.compiler`` which translates boolean expressions
The boolean expressions are then being fed to the `qlasskit.compiler`` which compiles boolean expressions
to invertible circuits, introducing auxiliary qubits. In this step, the compiler will automatically uncompute
auxiliary qubits in order to reduce the number of qubits needed and the circuit footprint.

Expand Down
33 changes: 31 additions & 2 deletions docs/source/supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Container type holding different types.
List
^^^^

A fixed size list; its type is `Qlist[T, size]`.
Qlist[T, size] denotes a fixed-size list in qlasskit.
For example, the list `[1,2,3]` is typed as `Qlist[Qint2,3]`.



Expressions
Expand Down Expand Up @@ -110,7 +112,7 @@ Comparators

.. code-block:: python
a > b or b <= c
a > b or b <= c and c == d or c != a
Unary Op
Expand Down Expand Up @@ -141,6 +143,10 @@ Bin Op
a - b
.. code-block:: python
a * b
Function call
Expand Down Expand Up @@ -184,6 +190,10 @@ For loop
a += i
.. note::
Please note that in qlasskit, for loops are unrolled during compilation. Therefore,
it is essential that the number of iterations for each for loop is known at the
time of compilation.

Function def
^^^^^^^^^^^^
Expand All @@ -204,3 +214,22 @@ If then else
c += 12
else:
c += 13
.. note::
At present, the if-then-else statement in qlasskit is designed to support branch bodies
that exclusively contain assignment statements.



Quantum Hybrid
---------------

In a qlassf function, you have the option to utilize quantum gates through the Q module. It's
important to keep in mind that incorporating quantum gates within a qlasskit function leads
to a Python function that exhibits distinct behaviors compared to its quantum counterpart.

.. code-block:: python
def bell(a: bool, b: bool) -> bool:
return Q.CX(Q.H(a), b)
2 changes: 1 addition & 1 deletion qlasskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
__version__ = "0.0.2"

from .qcircuit import QCircuit, SupportedFrameworks, SupportedFramework # noqa: F401
from .qlassfun import QlassF, qlassf, qlassf_a # noqa: F401
from .qlassfun import QlassF, qlassf, qlassfa # noqa: F401
from .ast2ast import ast2ast # noqa: F401
from .ast2logic import exceptions # noqa: F401
from .types import ( # noqa: F401, F403
Expand Down
2 changes: 1 addition & 1 deletion qlasskit/qlassfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def qlassf(
)


def qlassf_a(
def qlassfa(
types: List[Qtype] = [],
defs: List[QlassF] = [],
to_compile: bool = True,
Expand Down
20 changes: 20 additions & 0 deletions test/test_algo_grover.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ def hash(k: Qint4) -> bool:
self.assertEqual(algo.output_qubits, [0, 1, 2, 3])
self.assertEqual(counts_readable[15] > 600, True)

def test_grover_list_search(self):
f = """
def hash(k: Qint4) -> bool:
h = False
for i in [7]:
if i == k:
h = True
return h
"""
qf = qlassf(f)
algo = Grover(qf, True)

qc = algo.circuit().export("circuit", "qiskit")
counts = qiskit_measure_and_count(qc, shots=1024)
counts_readable = algo.decode_counts(counts)

self.assertEqual(15 in counts_readable, True)
self.assertEqual(algo.output_qubits, [0, 1, 2, 3])
self.assertEqual(counts_readable[7] > 600, True)

def test_grover_without_element_to_search(self):
f = """
def hash(k: Qint4) -> bool:
Expand Down

0 comments on commit 90dc071

Please sign in to comment.