# qrisp.quantum_backtracking.QuantumBacktrackingTree.statevector_graph#

QuantumBacktrackingTree.statevector_graph(return_root=False)[source]#

Returns a NetworkX Graph representing the quantum state of the backtracking tree. The nodes have an amplitude attribute, indicating the complex amplitude of that node.

Parameters
return_rootbool, optional

If set to True, this method will also return the root node. The default is False.

Returns
networkx.DiGraph

A graph representing the statevector.

Examples

We initialize a backtracking tree, initialize a $$\ket{\phi}$$ state and retrieve the statevector graph.

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

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

@auto_uncompute
def accept(tree):
return (tree.branch_qa[0] == 1) & (tree.branch_qa[1] == 1) & (tree.branch_qa[2] == 1)


Create backtracking tree and initialize $$\ket{\phi}$$.

>>> tree = QuantumBacktrackingTree(3, QuantumFloat(1, name = "branch_qf*"), accept, reject)
>>> tree.init_phi([1,1,1])
>>> statevector_graph = tree.statevector_graph()
>>> print(statevector_graph.nodes())
[QBTNode(path = [], amplitude = (0.7071066+0j)), QBTNode(path = [0], amplitude = 0j), QBTNode(path = [1], amplitude = (-0.408248-4.4703484e-08j)), QBTNode(path = [0, 0], amplitude = 0j), QBTNode(path = [0, 1], amplitude = 0j), QBTNode(path = [1, 0], amplitude = 0j), QBTNode(path = [1, 1], amplitude = (0.4082481+1.4901161e-08j)), QBTNode(path = [0, 0, 0], amplitude = 0j), QBTNode(path = [0, 0, 1], amplitude = 0j), QBTNode(path = [0, 1, 0], amplitude = 0j), QBTNode(path = [0, 1, 1], amplitude = 0j), QBTNode(path = [1, 0, 0], amplitude = 0j), QBTNode(path = [1, 0, 1], amplitude = 0j), QBTNode(path = [1, 1, 0], amplitude = 0j), QBTNode(path = [1, 1, 1], amplitude = (-0.40824816+5.9604645e-08j))]
>>> statevector_graph, root = tree.statevector_graph(return_root = True)
>>> print(root)
QBTNode(path = [], amplitude = (0.7071066+0j))