qrisp.quantum_backtracking.QuantumBacktrackingTree.init_phi#

QuantumBacktrackingTree.init_phi(path)[source]#

Initializes the normalized version of the state \(\ket{\phi}\).

\[\begin{split}\ket{\phi} = \sqrt{n}\ket{r} + \sum_{x \neq r, \\ x \rightsquigarrow x_0} (-1)^{l(x)} \ket{x}\end{split}\]

Where \(x \rightsquigarrow x_0\) means that \(x\) is on the path from \(r\) to \(x_0\) (including \(x_0\)).

If \(x_0\) is a marked node, this state is invariant under the quantum step operator.

Parameters
pathList

The list of branches specifying the path from the root to \(x_0\).

Examples

We set up a backtracking tree of depth 3, where the marked element is the 111 node.

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)

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

Initialize \(\ket{\phi}\) and evaluate the statevector:

>>> tree.init_phi([1,1,1])
>>> print(tree.qs.statevector())
(0.816496014595032*|0>*|1>**3 - 0.816496014595032*|0>**2*|1>*|2> + 1.0*sqrt(2)*|0>**3*|3> - 0.816496014595032*|1>**3*|0>)/2

Perform the quantum step and evaluate the statevector again:

>>> tree.quantum_step()
>>> print(tree.qs.statevector())
(0.816496014595032*|0>*|1>**3 - 0.816496014595032*|0>**2*|1>*|2> + 1.0*sqrt(2)*|0>**3*|3> - 0.816496014595032*|1>**3*|0>)/2

We see that the node (as expected) is invariant under the quantum step operator.