Skip to content

Commit

Permalink
Deprecation QubitStateVector (#6172)
Browse files Browse the repository at this point in the history
  • Loading branch information
KetpuntoG authored and mudit2812 committed Sep 23, 2024
1 parent 9a02bea commit 0b01495
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 @@ -90,6 +90,10 @@

<h3>Deprecations 👋</h3>

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

* `Device`, `QubitDevice`, and `QutritDevice` will no longer be accessible via top-level import in v0.40.
They will still be accessible as `qml.devices.LegacyDevice`, `qml.devices.QubitDevice`, and `qml.devices.QutritDevice`
respectively.
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
2 changes: 1 addition & 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 Expand Up @@ -137,6 +136,7 @@
PowOpObs,
PowOperation,
PowObs,
qml.QubitStateVector,
}
"""Types that should not have actual instances created."""

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

0 comments on commit 0b01495

Please sign in to comment.