BlockEncoding.apply_rus#

BlockEncoding.apply_rus(operand_prep: Callable[[...], Any]) Callable[[...], Any][source]#

Applies the BlockEncoding using Repeat-Until-Success.

Parameters:
operand_prepCallable

A function operand_prep(*args) that prepares and returns the operand QuantumVariables.

Returns:
Callable

A function rus_function(*args) with the same signature as operand_prep. It prepares the operands and ancillas, and applies the block-encoding unitary within a repeat-until-success protocol. Returns the transformed operand QuantumVariables.

Raises:
TypeError

If operand_prep is not a callable object.

ValueError

If the number of provided operands does not match the required number of operands (self.num_ops).

Examples

Define a block-encoding and apply it using Repeat-Until-Success.

import numpy as np
from qrisp import *
from qrisp.block_encodings import BlockEncoding
from qrisp.operators import X, Y, Z

H = X(0)*X(1) + 0.5*Z(0)*Z(1)
BE = BlockEncoding.from_operator(H)

def operand_prep(phi):
    qv = QuantumFloat(2)
    ry(phi, qv[0])
    return qv

@terminal_sampling
def main(BE):
    qv = BE.apply_rus(operand_prep)(np.pi / 4)
    return qv

main(BE)
#{3: 0.6828427278345078, 0: 0.17071065215630213, 2: 0.11715730494804945, 1: 0.02928931506114055}