Skip to content

Commit

Permalink
wrote documentation for qswitch
Browse files Browse the repository at this point in the history
  • Loading branch information
positr0nium committed Nov 15, 2024
1 parent 199fb70 commit d0b77a8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 23 deletions.
23 changes: 6 additions & 17 deletions documentation/source/general/changelog/0.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@ In this update many things revolve around one of the most original purposes of q
The Operators module
--------------------

This module allows you to describe operators that are not necessarily unitary or even hermitian. With these tools at hand you can effectively set up two of quantum's most important algorithms: :meth:`Hamiltonian simulation <qrisp.operators.QubitOperator.trotterization>` and :ref:`VQE`.
This module allows you to describe operators that are not necessarily unitary or even hermitian. With these tools at hand you can effectively set up two of quantum's most important algorithms: Hamiltonian simulation and :ref:`VQE`.

For this we provide the following classes:

* :ref:`QubitOperator` is a class that enables the representation and processing of arbitrary operators. Operators can be constructed based on a variety of tensor factors including the Pauli-matrices but also projector, creators and annihilators. For the latter Qrisp features a highly performant algorithm for Hamiltonian simulation proposed by `Kornell and Selinger <https://arxiv.org/abs/2310.12256>`_.
* :ref:`FermionicOperator` provides you with the tools to describe and manipulate fermionic systems. This type of system is of particular importance for applications in chemistry because the many computations for molecular dynamics involve the simulation of electrons, which are fermions. FermionicOperators can be constructed effortlessly from `PySCF <https://pyscf.org/>`_ data. PySCF is one of the most popular quantum chemistry Python packages.
* :ref:`VQEProblem` which allows you to quickly formulate and run the VQE algorithm using Hamiltonians expressed through the two operator classes.


QIRO
----


Compiler upgrades
-----------------

* A significantly fast algorithm for memory management has been implemented. With this feature, managing circuits with thousands of qubits is no more a problem.
* The compiler can now also leverage X-Permeability type commutativity relations. More info _`here <https://quantum-compilers.github.io/iwqc2024/papers/IWQC2024_paper_16.pdf>`_.
* A significantly fast algorithm for memory management has been implemented. With this feature, managing circuits with thousands of qubits is no problem.
* The compiler can now also leverage X-Permeability type commutativity relations. More info `here <https://quantum-compilers.github.io/iwqc2024/papers/IWQC2024_paper_16.pdf>`__.

Algorithmic primitives
----------------------

* :ref:`A module <phase_polynomials>` for the efficient treatment of Phase polynomials has been implemented.
* :ref:`Quantum switch-case <qswitch>` can be used to execute a `switch statement <https://en.wikipedia.org/wiki/Switch_statement>`_ in superposition

Minor features
--------------
Expand All @@ -38,17 +40,4 @@ Minor features
* Deprecated the QuantumNetworks module.
* :ref:`Operations <Operation>` can now receive complex numbers as parameters.
* :ref:`QuantumModulus` will now use the user-specified adder for all arithmetic evaluations (previously only in-place multiplication).
* A :ref:`tutorial <sudoku>` for utilizing the Quantum-Backtracking algorithm for solving Sudokus is now available.



Bug-fixes
---------

* Fixed a bug that caused false results in some simulations containing a Y-gate.
* Fixed a bug that prevented proper QFT cancellation within the :meth:`compile <qrisp.QuantumSession.compile>` method in some cases.
* Fixed a bug that prevented proper verification of correct automatic uncomputation in some cases.
* Fixed a bug that caused false determination of the unitary of controlled gates with a non-trivial control state.
* Fixed a bug that caused problems during circuit visualisation on some platforms.
* Fixed a bug that caused the simulation progress bar to not vanish after the simulation concluded.
* Fixed a bug that introduced an extra phase in the compilation of dirty-ancillae supported ``balauca`` MCX gates.
* A :ref:`tutorial <sudoku>` for utilizing the Quantum-Backtracking algorithm for solving Sudokus is now available.
3 changes: 3 additions & 0 deletions documentation/source/reference/Primitives/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ This submodule of Qrisp provides a collection of commonly used buildings blocks
- algorithm for the preparation of Dicke states, i.e. states with a given Hamming weight.
* - Iterable :ref:`Demuxing <ItDemuxing>`, :ref:`Shifting <ItShifting>`, and :ref:`Permutation <ItPermutation>`
- low-level manipulations of quantum arguments like :ref:`QuantumVariable <QuantumVariable>` or :ref:`QuantumArray <QuantumArray>`
* - :ref:`Quantum Switch Case <qswitch>`
- Executes a `switch statement <https://en.wikipedia.org/wiki/Switch_statement>`_. The condition can be a :ref:`QuantumVariable`.
* - :ref:`Prefix arithmetic <prefix_arithmetic>`
- Several arithmetic functions that allow better control over precision and output types than the infix version.

Expand All @@ -47,5 +49,6 @@ We encourage you to explore these algorithms, delve into their documentation, an
Grover tools
DickeStates
demux
qswitch
cyclic_shift
iterable_permutation
8 changes: 8 additions & 0 deletions documentation/source/reference/Primitives/qswitch.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _qswitch:

Quantum Switch Case
===================

.. currentmodule:: qrisp

.. autofunction:: qswitch
43 changes: 38 additions & 5 deletions src/qrisp/alg_primitives/switch_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,52 @@ def qswitch(operand, case, case_function_list, method = "sequential"):
"""
Executes a switch - case statement distinguishing between a list of
given in-place functions.
Parameters
----------
operand : QuantumVariable
The QuantumVariable to operate on.
The quantum argument on which to execute the case function.
case : QuantumFloat
The QuantumFloat indicating which functions to execute.
A QuantumFloat specifying which case function should be executed.
case_function_list : list[callable]
The list of functions which are executed depending on the case.
A list of functions, performing some in-place operation on ``operand``.
method : str, optional
The compilation method. Available are ``parallel`` and ``sequential``.
``parallel`` is exponentially fast but requires more temporary qubits.
The default is "sequential".
Examples
--------
We create some sample functions:
>>> from qrisp import *
>>> def f0(x): x += 1
>>> def f1(x): inpl_mult(x, 3, treat_overflow = False)
>>> def f2(x): pass
>>> def f3(x): h(x[1])
>>> case_function_list = [f0, f1, f2, f3]
Create operand and case variable
>>> operand = QuantumFloat(4)
>>> operand[:] = 1
>>> case = QuantumFloat(2)
>>> h(case)
Execute switch_case function
>>> qswitch(operand, case, case_function_list)
Simulate
>>> print(multi_measurement([case, operand]))
{(0, 2): 0.25, (1, 3): 0.25, (2, 1): 0.25, (3, 1): 0.125, (3, 3): 0.125}
"""


if method == "sequential":

for i in range(len(case_function_list)):
Expand Down
3 changes: 2 additions & 1 deletion tests/operator_tests/test_VQE_heisenberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_vqe_heisenberg():
for i in range(5):
res = vqe.run(QuantumVariable(G.number_of_nodes()),
depth=2,
max_iter=50)
max_iter=50,
mes_kwargs = {"shots" : 100000})
results.append(res)

assert np.abs(min(results)-(-8.0)) < 1e-2

0 comments on commit d0b77a8

Please sign in to comment.