qrisp.quantum_backtracking.QuantumBacktrackingTree.statevector#

QuantumBacktrackingTree.statevector()[source]#

Returns a SymPy statevector object representing the state of the tree with decoded node labels.

Returns:
statesympy.Expr

A SymPy quantum state representing the statevector of the tree.

Examples

We create a QuantumBacktrackingTree with and investigate the action of the quantum step diffuser

from qrisp import auto_uncompute, mcx, QuantumBool, QuantumFloat
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):
    height_cond = (tree.h == 2) # The [1] node has height 2
    path_cond = QuantumBool()
    mcx(list(tree.branch_qa)[-1], path_cond, ctrl_state="1")
    return path_cond & height_cond

Create tree and initialize a node where neither accept nor reject are True.

>>> tree = QuantumBacktrackingTree(3, QuantumFloat(1, name = "branch_qf*"), accept, reject)
>>> tree.init_node([0,0])

Evaluate statevector

>>> print(tree.statevector())
1.0*|[0, 0]>
>>> tree.qstep_diffuser(even = False)
>>> print(tree.statevector())
-0.666660010814667*|[0, 0, 0]> - 0.666660010814667*|[0, 0, 1]> + 0.333330005407333*|[0, 0]>

We see that the quantum step diffuser moves the state to the children of the [0,0] node (ie. [0,0,0] and [0,0,1]).

We now investigate how it behaves on nodes that are accepted/rejected:

Initiate a new tree

>>> tree = tree.copy()
>>> tree.init_node([0,1])
>>> tree.qstep_diffuser(even = False)
>>> tree.statevector()
1.0*|[0, 1]>

As expected, the accepted node is invariant.

To investigate the rejected node, we create another copy:

>>> tree = tree.copy()
>>> tree.init_node([1])
>>> tree.qstep_diffuser(even = True)
>>> tree.statevector()
-1*|[1]>

As expected, the node has eigenvalue -1.

If you are unsure why these statevectors are eigenvector please check the paper.