diff --git a/documentation/source/general/changelog/0.5.rst b/documentation/source/general/changelog/0.5.rst index f4b8100b..e694d2ab 100644 --- a/documentation/source/general/changelog/0.5.rst +++ b/documentation/source/general/changelog/0.5.rst @@ -8,7 +8,7 @@ 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 ` 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: @@ -16,6 +16,7 @@ For this we provide the following classes: * :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 `_ 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 ---- @@ -23,13 +24,14 @@ 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 `_. +* 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 `__. Algorithmic primitives ---------------------- * :ref:`A module ` for the efficient treatment of Phase polynomials has been implemented. +* :ref:`Quantum switch-case ` can be used to execute a `switch statement `_ in superposition Minor features -------------- @@ -38,17 +40,4 @@ Minor features * Deprecated the QuantumNetworks module. * :ref:`Operations ` 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 ` 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 ` 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 ` for utilizing the Quantum-Backtracking algorithm for solving Sudokus is now available. \ No newline at end of file diff --git a/documentation/source/reference/Primitives/index.rst b/documentation/source/reference/Primitives/index.rst index c31a9daa..02484c19 100644 --- a/documentation/source/reference/Primitives/index.rst +++ b/documentation/source/reference/Primitives/index.rst @@ -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 `, :ref:`Shifting `, and :ref:`Permutation ` - low-level manipulations of quantum arguments like :ref:`QuantumVariable ` or :ref:`QuantumArray ` + * - :ref:`Quantum Switch Case ` + - Executes a `switch statement `_. The condition can be a :ref:`QuantumVariable`. * - :ref:`Prefix arithmetic ` - Several arithmetic functions that allow better control over precision and output types than the infix version. @@ -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 diff --git a/documentation/source/reference/Primitives/qswitch.rst b/documentation/source/reference/Primitives/qswitch.rst new file mode 100644 index 00000000..c004c341 --- /dev/null +++ b/documentation/source/reference/Primitives/qswitch.rst @@ -0,0 +1,8 @@ +.. _qswitch: + +Quantum Switch Case +=================== + +.. currentmodule:: qrisp + +.. autofunction:: qswitch \ No newline at end of file diff --git a/src/qrisp/alg_primitives/switch_case.py b/src/qrisp/alg_primitives/switch_case.py index ef884193..6cf04b54 100644 --- a/src/qrisp/alg_primitives/switch_case.py +++ b/src/qrisp/alg_primitives/switch_case.py @@ -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)): diff --git a/tests/operator_tests/test_VQE_heisenberg.py b/tests/operator_tests/test_VQE_heisenberg.py index f63382e7..21375dd5 100644 --- a/tests/operator_tests/test_VQE_heisenberg.py +++ b/tests/operator_tests/test_VQE_heisenberg.py @@ -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