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 the pad argument from amplitude embedding template #1805

Merged
merged 13 commits into from
Oct 28, 2021
Merged
10 changes: 7 additions & 3 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,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)

<h3>Bug fixes</h3>

* Fixes a bug where the GPU cannot be used with `qml.qnn.TorchLayer`.
Expand Down Expand Up @@ -901,6 +905,6 @@

This release contains contributions from (in alphabetical order):

Utkarsh Azad, Akash Narayanan B, Sam Banning, Thomas Bromley, 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,
David Wierichs, Moritz Willmann.
Utkarsh Azad, Akash Narayanan B, Sam Banning, Thomas Bromley, Olivia Di Matteo, Andrew Gardhouse, David Ittah,
Josh Izaac, Christina Lee, Romain Moyard, Carrie-Anne Rubidge, Maria Schuld, Rishabh Singh, Jay Soni, Ingrid Strandberg,
Antal Száva, Cody Wang, David Wierichs, Moritz Willmann.
20 changes: 4 additions & 16 deletions pennylane/templates/embeddings/amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,7 +51,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:

Expand Down Expand Up @@ -125,18 +123,7 @@ def circuit(f=None):
par_domain = "A"
grad_method = None

def __init__(
self, features, wires, pad_with=None, normalize=False, pad=None, 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
def __init__(self, features, wires, pad_with=None, normalize=False, do_queue=True, id=None):
Jaybsoni marked this conversation as resolved.
Show resolved Hide resolved

wires = Wires(wires)
self.pad_with = pad_with
Expand All @@ -163,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.
"""
Expand All @@ -185,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):
Expand Down
1 change: 0 additions & 1 deletion pennylane/transforms/qfunc_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from copy import deepcopy
import functools
import inspect
import types

import pennylane as qml

Expand Down
18 changes: 0 additions & 18 deletions tests/templates/test_embeddings/test_amplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down