From eb77547c3325562046af84320c19e2a5f6e64a44 Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Mon, 25 Oct 2021 15:56:03 -0400 Subject: [PATCH 1/9] removed the pad argument from amplitude embedding template --- pennylane/templates/embeddings/amplitude.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pennylane/templates/embeddings/amplitude.py b/pennylane/templates/embeddings/amplitude.py index 76bfd808135..b8e3f31a0d9 100644 --- a/pennylane/templates/embeddings/amplitude.py +++ b/pennylane/templates/embeddings/amplitude.py @@ -52,7 +52,6 @@ class AmplitudeEmbedding(Operation): wires (Iterable): wires that the template acts on pad_with (float or complex): if not None, the input is padded with this constant to size :math:`2^n` normalize (bool): whether to automatically normalize the features - pad (float or complex): same as `pad`, to be deprecated Example: @@ -126,18 +125,9 @@ def circuit(f=None): grad_method = None def __init__( - self, features, wires, pad_with=None, normalize=False, pad=None, do_queue=True, id=None + self, features, wires, pad_with=None, normalize=False, do_queue=True, id=None ): - # pad is replaced with the more verbose pad_with - if pad is not None: - warnings.warn( - "The pad argument will be replaced by the pad_with option in future versions of PennyLane.", - UserWarning, - ) - if pad_with is None: - pad_with = pad - wires = Wires(wires) self.pad_with = pad_with self.normalize = normalize From 4459c155ff9879595ed2bc44e6cf5ed26f2d5d89 Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Mon, 25 Oct 2021 16:05:25 -0400 Subject: [PATCH 2/9] removed the test which checks for deprecation warning --- .../test_embeddings/test_amplitude.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tests/templates/test_embeddings/test_amplitude.py b/tests/templates/test_embeddings/test_amplitude.py index bf6612c5593..9f47df53b59 100644 --- a/tests/templates/test_embeddings/test_amplitude.py +++ b/tests/templates/test_embeddings/test_amplitude.py @@ -220,24 +220,6 @@ def circuit(x=None): # No normalization error is raised circuit(x=inputs) - def test_deprecated_pad_arg(self): - """Test that the pad argument raises a deprecation warning""" - - num_qubits = 2 - dev = qml.device("default.qubit", wires=num_qubits) - inputs = np.array([1.0, 0.0, 0.0, 0.0]) - - @qml.qnode(dev) - def circuit(x=None): - qml.AmplitudeEmbedding(x, list(range(num_qubits)), pad=0.0, normalize=True) - return qml.expval(qml.PauliZ(0)) - - with pytest.warns( - UserWarning, - match="will be replaced by the pad_with option in future versions", - ): - circuit(x=inputs) - def test_id(self): """Tests that the id attribute can be set.""" template = qml.AmplitudeEmbedding(np.array([1, 0]), wires=[0], id="a") From 1f432656c1a89db2f273e594077854c3def1640c Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Mon, 25 Oct 2021 16:08:51 -0400 Subject: [PATCH 3/9] removed import warnings --- pennylane/templates/embeddings/amplitude.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pennylane/templates/embeddings/amplitude.py b/pennylane/templates/embeddings/amplitude.py index b8e3f31a0d9..30765ddd779 100644 --- a/pennylane/templates/embeddings/amplitude.py +++ b/pennylane/templates/embeddings/amplitude.py @@ -15,7 +15,6 @@ Contains the AmplitudeEmbedding template. """ # pylint: disable-msg=too-many-branches,too-many-arguments,protected-access -import warnings import numpy as np import pennylane as qml From f5c8d26cd77a096fbf9765de6fa7e34623ee6db5 Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Mon, 25 Oct 2021 16:15:39 -0400 Subject: [PATCH 4/9] lint --- pennylane/templates/embeddings/amplitude.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pennylane/templates/embeddings/amplitude.py b/pennylane/templates/embeddings/amplitude.py index 30765ddd779..4e74e5c42d0 100644 --- a/pennylane/templates/embeddings/amplitude.py +++ b/pennylane/templates/embeddings/amplitude.py @@ -123,9 +123,7 @@ def circuit(f=None): par_domain = "A" grad_method = None - def __init__( - self, features, wires, pad_with=None, normalize=False, do_queue=True, id=None - ): + def __init__(self, features, wires, pad_with=None, normalize=False, do_queue=True, id=None): wires = Wires(wires) self.pad_with = pad_with From 64e9716b9c9bd6b58bd98d6ed922daac1552dfb1 Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Mon, 25 Oct 2021 18:06:02 -0400 Subject: [PATCH 5/9] added to changelog --- doc/releases/changelog-dev.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 41422e81356..d1d9e0759d1 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -662,6 +662,10 @@ Please use the `qml.metric_tensor` transform instead. [(#1638)](https://github.com/PennyLaneAI/pennylane/pull/1638) +* The `pad` parameter of the `qml.AmplitudeEmbedding` template has been removed. + It has instead been renamed to the `pad_with` parameter. + [(#1805)](https://github.com/PennyLaneAI/pennylane/pull/1805) +

Bug fixes

* Fixes a bug where the GPU cannot be used with `qml.qnn.TorchLayer`. @@ -716,5 +720,5 @@ This release contains contributions from (in alphabetical order): Utkarsh Azad, Akash Narayanan B, Olivia Di Matteo, Andrew Gardhouse, David Ittah, Josh Izaac, Christina Lee, -Romain Moyard, Carrie-Anne Rubidge, Maria Schuld, Rishabh Singh, Ingrid Strandberg, Antal Száva, Cody Wang, +Romain Moyard, Carrie-Anne Rubidge, Maria Schuld, Rishabh Singh, Jay Soni, Ingrid Strandberg, Antal Száva, Cody Wang, David Wierichs, Moritz Willmann. From 2f0c61b9412fcff089fb1eda6fdd5fd70c5a6e67 Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Wed, 27 Oct 2021 13:51:46 -0400 Subject: [PATCH 6/9] updated comment to say pad_with --- pennylane/templates/embeddings/amplitude.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pennylane/templates/embeddings/amplitude.py b/pennylane/templates/embeddings/amplitude.py index 4e74e5c42d0..e0200cf8556 100644 --- a/pennylane/templates/embeddings/amplitude.py +++ b/pennylane/templates/embeddings/amplitude.py @@ -150,7 +150,8 @@ def _preprocess(features, wires, pad_with, normalize): * Check that the features tensor is one-dimensional. * If pad_with is None, check that the first dimension of the features tensor has length :math:`2^n` where :math:`n` is the number of qubits. Else check that the - first dimension of the features tensor is not larger than :math:`2^n` and pad features with value if necessary. + first dimension of the features tensor is not larger than :math:`2^n` and pad features + with value if necessary. * If normalize is false, check that first dimension of features is normalised to one. Else, normalise the features tensor. """ @@ -172,7 +173,7 @@ def _preprocess(features, wires, pad_with, normalize): if pad_with is None and n_features != 2 ** len(wires): raise ValueError( f"Features must be of length {2 ** len(wires)}; got length {n_features}. " - f"Use the 'pad' argument for automated padding." + f"Use the 'pad_with' argument for automated padding." ) if pad_with is not None and n_features > 2 ** len(wires): From 532a080adcfb061d8e3f55698e15ef98e48e4975 Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Wed, 27 Oct 2021 13:55:14 -0400 Subject: [PATCH 7/9] remove extra import from a different file (probably due to a different merge on master) --- pennylane/transforms/qfunc_transforms.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pennylane/transforms/qfunc_transforms.py b/pennylane/transforms/qfunc_transforms.py index 0013bd31bdc..d8398ff4f44 100644 --- a/pennylane/transforms/qfunc_transforms.py +++ b/pennylane/transforms/qfunc_transforms.py @@ -16,7 +16,6 @@ from copy import deepcopy import functools import inspect -import types import pennylane as qml From 24422a620c3fbb18762b3670ee148dd1f49c3bd0 Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Wed, 27 Oct 2021 14:23:01 -0400 Subject: [PATCH 8/9] minor formatting --- tests/templates/test_embeddings/test_amplitude.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/templates/test_embeddings/test_amplitude.py b/tests/templates/test_embeddings/test_amplitude.py index 9f47df53b59..d08ed91e831 100644 --- a/tests/templates/test_embeddings/test_amplitude.py +++ b/tests/templates/test_embeddings/test_amplitude.py @@ -81,7 +81,7 @@ def circuit(x=None): circuit(x=inpt) state = circuit.device.state.ravel() - assert len(set(state[len(inpt) :])) == 1 + assert len(set(state[len(inpt):])) == 1 def test_custom_wire_labels(self, tol): """Test that template can deal with non-numeric, nonconsecutive wire labels.""" From 90e9ceb1e14332eb70057d20ef83e66b6e09dc01 Mon Sep 17 00:00:00 2001 From: Jay Soni Date: Wed, 27 Oct 2021 14:26:12 -0400 Subject: [PATCH 9/9] Update tests/templates/test_embeddings/test_amplitude.py --- tests/templates/test_embeddings/test_amplitude.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/templates/test_embeddings/test_amplitude.py b/tests/templates/test_embeddings/test_amplitude.py index d08ed91e831..9f47df53b59 100644 --- a/tests/templates/test_embeddings/test_amplitude.py +++ b/tests/templates/test_embeddings/test_amplitude.py @@ -81,7 +81,7 @@ def circuit(x=None): circuit(x=inpt) state = circuit.device.state.ravel() - assert len(set(state[len(inpt):])) == 1 + assert len(set(state[len(inpt) :])) == 1 def test_custom_wire_labels(self, tol): """Test that template can deal with non-numeric, nonconsecutive wire labels."""