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

Deprecation QubitStateVector #6172

Merged
merged 17 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
6 changes: 6 additions & 0 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ Pending deprecations
- Deprecated in v0.37
- Will be removed in v0.39

* The ``QubitStateVector`` template is deprecated.
Instead, use ``StatePrep``.

- Deprecated in v0.39
- Will be removed in v0.40

New operator arithmetic deprecations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@

<h3>Deprecations 👋</h3>

* The ``QubitStateVector`` template is deprecated.
Instead, use ``StatePrep``.
[(#6172)](https://github.com/PennyLaneAI/pennylane/pull/6172)

<h3>Documentation 📝</h3>

<h3>Bug fixes 🐛</h3>
Expand Down
16 changes: 14 additions & 2 deletions pennylane/ops/qubit/state_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
This submodule contains the discrete-variable quantum operations concerned
with preparing a certain state on the device.
"""
import warnings

# pylint:disable=too-many-branches,abstract-method,arguments-differ,protected-access,no-member
from typing import Optional

Expand Down Expand Up @@ -442,9 +444,19 @@ def _preprocess(state, wires, pad_with, normalize, validate_norm):
return state


# pylint: disable=missing-class-docstring
class QubitStateVector(StatePrep):
pass # QSV is still available
r"""
``QubitStateVector`` is deprecated and will be removed in version 0.40. Instead, please use ``StatePrep``.
"""

# pylint: disable=too-many-arguments
def __init__(self, state, wires, pad_with=None, normalize=False, validate_norm=True):
warnings.warn(
"QubitStateVector is deprecated and will be removed in version 0.40. "
"Instead, please use StatePrep.",
qml.PennyLaneDeprecationWarning,
)
super().__init__(state, wires, pad_with, normalize, validate_norm)


class QubitDensityMatrix(Operation):
Expand Down
2 changes: 1 addition & 1 deletion tests/drawer/test_drawable_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_mid_measure_custom_wires(self):
m1 = qml.measurements.MeasurementValue([mp1], lambda v: v)

def teleport(state):
qml.QubitStateVector(state, wires=["A"])
qml.StatePrep(state, wires=["A"])
qml.Hadamard(wires="a")
qml.CNOT(wires=["a", "B"])
qml.CNOT(wires=["A", "a"])
Expand Down
1 change: 0 additions & 1 deletion tests/ops/functions/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
qml.sum(qml.X(0), qml.X(0), qml.Z(0), qml.Z(0)),
qml.BasisState([1], wires=[0]),
qml.ControlledQubitUnitary(np.eye(2), control_wires=1, wires=0),
qml.QubitStateVector([0, 1], wires=0),
qml.QubitChannel([np.array([[1, 0], [0, 0.8]]), np.array([[0, 0.6], [0, 0]])], wires=0),
qml.MultiControlledX(wires=[0, 1]),
qml.Projector([1], 0), # the state-vector version is already tested
Expand Down
12 changes: 11 additions & 1 deletion tests/ops/functions/test_assert_valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@ def create_op_instance(c, str_wires=False):
if dim == 0:
params = [1] * len(ndim_params)
elif dim == 1:
params = [[1] * 2**n_wires] * len(ndim_params)

if c == qml.QubitStateVector:
params = [[1] + [0] * (2**n_wires - 1)] * len(ndim_params)
else:
params = [[1] * 2**n_wires] * len(ndim_params)
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
elif dim == 2:
params = [np.eye(2)] * len(ndim_params)
else:
Expand All @@ -352,6 +356,12 @@ def create_op_instance(c, str_wires=False):


@pytest.mark.jax
@pytest.fixture(scope="function", autouse=True)
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
def capture_warnings(recwarn):
"""Capture warnings."""
yield


KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.parametrize("str_wires", (True, False))
def test_generated_list_of_ops(class_to_validate, str_wires):
"""Test every auto-generated operator instance."""
Expand Down
9 changes: 9 additions & 0 deletions tests/ops/qubit/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ class TestSupportsBroadcasting:
"""Test that all operations in the ``supports_broadcasting`` attribute
actually support broadcasting."""

@pytest.fixture(scope="function", autouse=False)
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
def capture_warnings(self, recwarn):
"""Capture warnings."""
yield
if len(recwarn) > 0:
for w in recwarn:
assert isinstance(w.message, qml.PennyLaneDeprecationWarning)
assert "QubitStateVector is deprecated" in str(w.message)

KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
def test_all_marked_operations_are_tested(self):
"""Test that the subsets of the ``supports_broadcasting`` attribute
defined above cover the entire attribute."""
Expand Down
6 changes: 6 additions & 0 deletions tests/ops/qubit/test_state_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def test_adjoint_error_exception(op):
op.adjoint()


def test_QubitStateVector_is_deprecated():
"""Test that QubitStateVector is deprecated."""
with pytest.warns(qml.PennyLaneDeprecationWarning, match="QubitStateVector is deprecated"):
_ = qml.QubitStateVector([1, 0, 0, 0], wires=[0, 1])


@pytest.mark.parametrize(
"op, mat, base",
[
Expand Down
Loading