qrisp.quantum_backtracking.QuantumBacktrackingTree.subtree#

QuantumBacktrackingTree.subtree(new_root)[source]#

Returns the subtree of a given node.

Parameters
new_rootlist

The path from the root of self to the root of the subtree.

Returns
QuantumBacktrackingTree

The subtree starting at the specified root.

Examples

We initiate a QuantumBacktrackingTree with trivial reject function and create a subtree starting at an accepted node-

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

@auto_uncompute
def accept(tree):
    height_cond = (tree.h == 2)
    return height_cond

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

Create and initiate the parent tree.

>>> depth = 5
>>> tree = QuantumBacktrackingTree(depth, QuantumFloat(1, name = "branch_qf*"), accept, reject)
>>> tree.init_node([])
>>> print(accept(tree))
{False: 1.0}

We now create the subtree, where the new root has height two, ie. the accept function returns True.

>>> subtree = tree.subtree([0,1,0])
>>> subtree.init_node([])
>>> print(accept(subtree))
{True: 1.0}