qrisp.quantum_backtracking.QuantumBacktrackingTree.path_decoder#

QuantumBacktrackingTree.path_decoder(h, branch_qa)[source]#

Returns the path representation for a given constellation of the h and branch_qa variables. The path representation is a list indicating which branches to take starting from the root. This function exists because the encoding of the nodes is hardware efficient but inconvenient for humans to read.

Parameters
hinteger

The integer describing the height of the node.

branch_qalist

The list of branches to take to reach the root, starting from the node.

Returns
list

The list of path variables to take to reach the node, starting from the root.

Examples

We create a QuantumBacktrackingTree, initiate a node and retrieve the path.

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

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

@auto_uncompute
def reject(tree):
    return QuantumBool()
>>> depth = 5
>>> tree = QuantumBacktrackingTree(depth, QuantumFloat(1, name = "branch_qf*"), accept, reject)
>>> tree.init_node([1,0])
>>> multi_measurement([tree.h, tree.branch_qa])
{(3, OutcomeArray([0, 0, 0, 0, 1])): 1.0}

Retrieve the path

>>> tree.path_decoder(3, [0, 0, 0, 0, 1])
[1, 0]