qrisp.quantum_backtracking.QuantumBacktrackingTree.find_solution#

QuantumBacktrackingTree.find_solution(precision, cl_accept=None, measurement_kwargs={})[source]#

Determines a path to a solution.

Parameters
precisioninteger

The precision to perform the quantum phase estimation(s) with.

cl_acceptfunction, optional

A classical version of the accept function of self. Needs to receive a list to indicate a path and returns a bool wether the node is accepted. By default, the accept function of self will be evaluated on a simulator.

measurement_kwargsdictionary

A dictionary to give keyword arguments that specify how measurements are evaluated. The default is {}.

Returns
List

A list indicating the path to a node where the accept function returns True.

Examples

We create a accept function that marks the node [0,1] and a trivial reject function.

from qrisp import auto_uncompute, QuantumBool, QuantumFloat, mcx
from qrisp.quantum_backtracking import QuantumBacktrackingTree

@auto_uncompute
def accept(tree):
    height_cond = (tree.h == 1) # The [0,1] node has height 1
    path_cond = QuantumBool()
    mcx(list(tree.branch_qa)[1:], path_cond, ctrl_state="10")
    return path_cond & height_cond

@auto_uncompute
def reject(tree):
    return QuantumBool()

Create backtracking tree object:

>>> depth = 3
>>> tree = QuantumBacktrackingTree(depth, QuantumFloat(1, name = "branch_qf*"), accept, reject)

Find solution

>>> res = tree.find_solution(4)
>>> print(res)
[0, 1]