BlockEncoding.__matmul__#
- BlockEncoding.__matmul__(other: 'ArrayLike' | BlockEncoding) BlockEncoding[source]#
Returns a BlockEncoding of the product of two operators.
This method implements the operator product \(A \cdot B\) by composing two BlockEncodings, where \(A\) and \(B\) are the operators encoded by the respective instances.
- Parameters:
- otherBlockEncoding
The BlockEncoding instance to be multiplied.
- Returns:
- BlockEncoding
A new BlockEncoding representing the operator product.
Notes
Can only be used when both BlockEncodings have the same operand structure.
The
@operator should be used sparingly, primarily to combine a few block encodings. For larger-scale polynomial transformations, Quantum Signal Processing (QSP) is the superior method.The product of two Hermitian operators A and B is Hermitian if and only if they commute, i.e., AB = BA.
Examples
Define two block-encodings and multiply them.
from qrisp import * from qrisp.block_encodings import BlockEncoding from qrisp.operators import X, Y, Z # Commuting operators H1 and H2 H1 = X(0)*X(1) + 0.2*Y(0)*Y(1) H2 = Z(0)*Z(1) + X(2) H3 = H1 * H2 BE1 = BlockEncoding.from_operator(H1) BE2 = BlockEncoding.from_operator(H2) BE3 = BlockEncoding.from_operator(H3) BE_mul = BE1 @ BE2 def operand_prep(): qv = QuantumFloat(3) return qv @terminal_sampling def main(BE): qv = BE.apply_rus(operand_prep)() return qv res_be3 = main(BE3) res_be_mul = main(BE_mul) print("Result from BE of H1 * H2: ", res_be3) print("Result from BE1 @ BE2: ", res_be_mul) # Result from BE of H1 * H2: {3.0: 0.5, 7.0: 0.5} # Result from BE1 @ BE2: {3.0: 0.5, 7.0: 0.5}