From d6a8f9af0f83a40a7ab93bead3706098da80f612 Mon Sep 17 00:00:00 2001
From: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Date: Mon, 9 Dec 2024 18:37:47 -0500
Subject: [PATCH 1/6] removing warning in example + scalar case
---
pennylane/templates/subroutines/qsvt.py | 4 ++--
tests/templates/test_subroutines/test_qsvt.py | 7 +++++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/pennylane/templates/subroutines/qsvt.py b/pennylane/templates/subroutines/qsvt.py
index 3cf7cc409aa..eb540ba9a7e 100644
--- a/pennylane/templates/subroutines/qsvt.py
+++ b/pennylane/templates/subroutines/qsvt.py
@@ -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()
@@ -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":
diff --git a/tests/templates/test_subroutines/test_qsvt.py b/tests/templates/test_subroutines/test_qsvt.py
index ffddc951288..badebe9add8 100644
--- a/tests/templates/test_subroutines/test_qsvt.py
+++ b/tests/templates/test_subroutines/test_qsvt.py
@@ -696,6 +696,12 @@ def test_qsvt_warning(self):
"fable",
[0, 1, 2, 3, 4],
),
+ (
+ 0.3,
+ [0.2, 0, 0.3],
+ "embedding",
+ [0],
+ ),
],
)
def test_matrix_input(self, A, poly, encoding_wires, block_encoding):
@@ -707,6 +713,7 @@ def circuit():
qml.qsvt(A, poly, encoding_wires, block_encoding)
return qml.state()
+ A = 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))
From 3988511e3fb9f54e74600d4a32b8d9ce566bb821 Mon Sep 17 00:00:00 2001
From: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Date: Mon, 9 Dec 2024 18:40:14 -0500
Subject: [PATCH 2/6] Update changelog-dev.md
---
doc/releases/changelog-dev.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 2899afeee90..1482bf0c51b 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -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)
Other Improvements
From d268303df4a1157add77cb7c13e3662449a22b43 Mon Sep 17 00:00:00 2001
From: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Date: Mon, 9 Dec 2024 18:50:37 -0500
Subject: [PATCH 3/6] Update test_qsvt.py
---
tests/templates/test_subroutines/test_qsvt.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/templates/test_subroutines/test_qsvt.py b/tests/templates/test_subroutines/test_qsvt.py
index badebe9add8..3e16541c2b1 100644
--- a/tests/templates/test_subroutines/test_qsvt.py
+++ b/tests/templates/test_subroutines/test_qsvt.py
@@ -713,11 +713,11 @@ def circuit():
qml.qsvt(A, poly, encoding_wires, block_encoding)
return qml.state()
- A = qml.math.atleast_2d(A)
+ 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"),
From e6682030d39723ce01caa31ba8ec98b655a47ba8 Mon Sep 17 00:00:00 2001
From: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Date: Tue, 10 Dec 2024 09:23:37 -0500
Subject: [PATCH 4/6] Update qsvt.py
---
pennylane/templates/subroutines/qsvt.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pennylane/templates/subroutines/qsvt.py b/pennylane/templates/subroutines/qsvt.py
index eb540ba9a7e..9477e097d6c 100644
--- a/pennylane/templates/subroutines/qsvt.py
+++ b/pennylane/templates/subroutines/qsvt.py
@@ -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",
qml.PennyLaneDeprecationWarning,
)
From 2a759e3638009cd19fe0fe7a637d309b62f2e439 Mon Sep 17 00:00:00 2001
From: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Date: Tue, 10 Dec 2024 10:06:34 -0500
Subject: [PATCH 5/6] Update pennylane/templates/subroutines/qsvt.py
Co-authored-by: Jay Soni
---
pennylane/templates/subroutines/qsvt.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pennylane/templates/subroutines/qsvt.py b/pennylane/templates/subroutines/qsvt.py
index 9477e097d6c..684fc73a73b 100644
--- a/pennylane/templates/subroutines/qsvt.py
+++ b/pennylane/templates/subroutines/qsvt.py
@@ -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`).\n"
- "Make sure you pass a polynomial instead of angles.\n"
- "Set a value for `block_encoding` to silence this warning.\n",
+ f"You may be trying to use the old `qsvt` functionality (now `qml.qsvt_legacy`).\n"
+ f"Make sure you pass a polynomial instead of angles.\n"
+ f"Set a value for `block_encoding` to silence this warning.\n",
qml.PennyLaneDeprecationWarning,
)
From fe7561206a55b13f2da588ae23df3f5aa25115ee Mon Sep 17 00:00:00 2001
From: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Date: Tue, 10 Dec 2024 10:19:18 -0500
Subject: [PATCH 6/6] Update qsvt.py
---
pennylane/templates/subroutines/qsvt.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/pennylane/templates/subroutines/qsvt.py b/pennylane/templates/subroutines/qsvt.py
index 684fc73a73b..9477e097d6c 100644
--- a/pennylane/templates/subroutines/qsvt.py
+++ b/pennylane/templates/subroutines/qsvt.py
@@ -328,9 +328,9 @@ def circuit():
if encoding_wires is None or block_encoding is None or "wires" in kwargs.keys():
warnings.warn(
- f"You may be trying to use the old `qsvt` functionality (now `qml.qsvt_legacy`).\n"
- f"Make sure you pass a polynomial instead of angles.\n"
- f"Set a value for `block_encoding` to silence this warning.\n",
+ "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",
qml.PennyLaneDeprecationWarning,
)