Skip to content

Commit

Permalink
Update block encoding demo (#1080)
Browse files Browse the repository at this point in the history
Update the demo on block encoding with matrix access oracles to:

1. Add the newly implemented `qml.FABLE` to the demo.
2. Correct an equation to allow block encoding `2 x 2` matrices.
  • Loading branch information
soranjh authored Apr 26, 2024
1 parent 4f50ea0 commit 65aeaf3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demonstrations/tutorial_block_encoding.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"dateOfPublication": "2023-11-28T00:00:00+00:00",
"dateOfLastModification": "2024-01-01T00:00:00+00:00",
"dateOfLastModification": "2024-04-26T00:00:00+00:00",
"categories": [
"Quantum Computing",
"Algorithms"
Expand Down
11 changes: 8 additions & 3 deletions demonstrations/tutorial_block_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
be obtained with the :func:`~.pennylane.templates.state_preparations.mottonen.compute_theta`
function of PennyLane.
Let's now construct the FABLE block encoding circuit for a structured matrix.
The :class:`~.pennylane.FABLE` circuit is implemented in PennyLane and
can be easily used to block encode matrices of any given shape. Here, we manually construct the
circuit for a structured :math:`4 \times 4` matrix.
.
"""

import pennylane as qml
Expand Down Expand Up @@ -116,7 +119,7 @@
# Finally, we obtain the control wires for the C-NOT gates and a wire map that we later use to
# translate the control wires into the wire registers we prepared.

code = gray_code(2*np.sqrt(len(A)))
code = gray_code(2 * np.log2(len(A)))
n_selections = len(code)

control_wires = [int(np.log2(int(code[i], 2) ^ int(code[(i + 1) %
Expand Down Expand Up @@ -173,7 +176,9 @@ def circuit():
##############################################################################
# You can easily confirm that the circuit block encodes the original matrix defined above. Note that
# the dimension of :math:`A` should be :math:`2^n` where :math:`n` is an integer. For matrices with
# an arbitrary size, we can add zeros to reach the correct dimension.
# an arbitrary size, we can add zeros to reach the correct dimension. The padding will be
# automatically applied in :class:`~.pennylane.FABLE` implemented in
# PennyLane.
#
# The interesting point about the FABLE method is that we can eliminate those rotation gates that
# have an angle smaller than a defined threshold. This leaves a sequence of C-NOT gates that in
Expand Down

0 comments on commit 65aeaf3

Please sign in to comment.