BlockEncoding.from_eye#
- classmethod BlockEncoding.from_eye(diagonal_index: int = 0) BlockEncoding#
Constructs a BlockEncoding of a 2-D array with ones on the diagonal and zeros elsewhere.
- Parameters:
- diagonal_indexint
Index of the diagonal to set to one: 0 (the default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.
- Returns:
- BlockEncoding
A BlockEncoding representing an array where all elements are equal to zero, except for the \(k\)-th diagonal, whose values are equal to one.
Examples
from qrisp import * from qrisp.block_encodings import BlockEncoding # diagonal_index = 0: ones on the main diagonal BE1 = BlockEncoding.from_eye(diagonal_index=0) # diagonal_index = -2: ones on the second lower subdiagonal # (non-cyclic) shift |x> -> |x+2> BE2 = BlockEncoding.from_eye(diagonal_index=-2) BE3 = BE1.kron(BE2) def operand_prep(): operand1 = QuantumFloat(3) operand2 = QuantumFloat(3) h(operand1) cx(operand1, operand2) return operand1, operand2 @terminal_sampling def main(): operand1, operand2 = BE3.apply_rus(operand_prep)() return operand1, operand2 main() # {(0.0, 2.0): 0.16666666666666666, # (1.0, 3.0): 0.16666666666666666, # (2.0, 4.0): 0.16666666666666666, # (3.0, 5.0): 0.16666666666666666, # (4.0, 6.0): 0.16666666666666666, # (5.0, 7.0): 0.16666666666666666}