BlockEncoding class represents as a qfunc, together with the
triple, as a single Python object. It also provides constructors and algebraic operations so you
can build and combine block encodings without hand-managing quantum variables.
The BlockEncoding class
BlockEncoding is a frozen dataclass with the following fields:
You rarely construct a
BlockEncoding by filling in these fields directly. Instead, use one of
its classmethod constructors — covered in
Constructing Block Encodings
— to build one from a NumPy matrix, a set of diagonals, a sum of Pauli operators, and more.
Quick start
be.unitary is a qfunc like any other, so you call it directly on your own variables inside
main. The following example block-encodes a diagonal matrix , loads a non-uniform vector
x_vector onto the data variable, applies the block encoding,
synthesizes and executes the resulting circuit. Filtering the state vector on block == 0
recovers , which is the block-encoded action of on the input, up
to the scaling factor :
print gives:
And the second gives
8.0, matching be.alpha.
See State Vector Filtering for more on
calculate_state_vector and filtering by variable.
Where to go next
- Constructing Block Encodings —
build a
BlockEncodingfrom a matrix, diagonals, or a Pauli operator. - Composing and Transforming Block Encodings —
combine block encodings with
+,*,@,weighted_sum, andproduct, and transform them withinverseandqubitize.