Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove warning example qsvt #6693

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ such as `shots`, `rng` and `prng_key`.
* The `qml.qsvt` function has been improved to be more user-friendly. Old functionality is moved to `qml.qsvt_legacy`
and it will be deprecated in release v0.40.
[(#6520)](https://github.com/PennyLaneAI/pennylane/pull/6520/)
[(#6693)](https://github.com/PennyLaneAI/pennylane/pull/6693)

<h4>Other Improvements</h4>

Expand Down
10 changes: 5 additions & 5 deletions pennylane/templates/subroutines/qsvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def qsvt(A, poly, encoding_wires=None, block_encoding=None, **kwargs):

@qml.qnode(dev)
def circuit():
qml.qsvt(hamiltonian, poly, encoding_wires=[0])
qml.qsvt(hamiltonian, poly, encoding_wires=[0], block_encoding="prepselprep")
return qml.state()


Expand Down Expand Up @@ -328,9 +328,9 @@ def circuit():

if encoding_wires is None or block_encoding is None or "wires" in kwargs.keys():
warnings.warn(
"You may be trying to use the old `qsvt` functionality (now `qml.qsvt_legacy`)."
"Make sure you pass a polynomial instead of angles."
"Set a value for `block_encoding` to silence this warning.",
"You may be trying to use the old `qsvt` functionality (now `qml.qsvt_legacy`).\n"
"Make sure you pass a polynomial instead of angles.\n"
"Set a value for `block_encoding` to silence this warning.\n",
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
qml.PennyLaneDeprecationWarning,
)

Expand Down Expand Up @@ -369,7 +369,7 @@ def circuit():
"block_encoding = {block_encoding} not supported for A of type {type(A)}. When A is a matrix block_encoding should take the value 'embedding' or 'fable'. Otherwise, please provide an input with a Pauli decomposition. For more details, see the 'qml.pauli_decompose' function."
)

A = qml.math.array(A)
A = qml.math.atleast_2d(A)
max_dimension = 1 if len(qml.math.array(A).shape) == 0 else max(A.shape)

if block_encoding == "fable":
Expand Down
11 changes: 9 additions & 2 deletions tests/templates/test_subroutines/test_qsvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,12 @@ def test_qsvt_warning(self):
"fable",
[0, 1, 2, 3, 4],
),
(
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
0.3,
[0.2, 0, 0.3],
"embedding",
[0],
),
],
)
def test_matrix_input(self, A, poly, encoding_wires, block_encoding):
Expand All @@ -707,10 +713,11 @@ def circuit():
qml.qsvt(A, poly, encoding_wires, block_encoding)
return qml.state()

A_matrix = qml.math.atleast_2d(A)
# Calculation of the polynomial transformation on the input matrix
expected = sum(coef * matrix_power(A, i) for i, coef in enumerate(poly))
expected = sum(coef * matrix_power(A_matrix, i) for i, coef in enumerate(poly))

assert np.allclose(qml.matrix(circuit)()[: len(A), : len(A)].real, expected)
assert np.allclose(qml.matrix(circuit)()[: len(A_matrix), : len(A_matrix)].real, expected)

@pytest.mark.parametrize(
("A", "poly", "block_encoding", "encoding_wires"),
Expand Down
Loading