Skip to content

Commit

Permalink
deprecating basisstateprep
Browse files Browse the repository at this point in the history
  • Loading branch information
KetpuntoG committed Jul 24, 2024
1 parent fe36eb2 commit 5f8ba56
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 6 deletions.
6 changes: 6 additions & 0 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Pending deprecations
- Deprecated in v0.37
- Will be removed in v0.39

* The ``BasisStatePreparation`` template is deprecated.
Instead, ``BasisState`` can be called on the constructed operator.

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

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

Expand Down
14 changes: 13 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
Instead, use `pennylane.gradients.classical_fisher` and `pennylane.gradients.quantum_fisher`.
[(#5985)](https://github.com/PennyLaneAI/pennylane/pull/5985)

* The ``BasisStatePreparation`` template is deprecated.
Instead, ``BasisState`` can be called on the constructed operator.
[(#6021)](https://github.com/PennyLaneAI/pennylane/pull/6021)

<h3>Documentation 📝</h3>

* Improves the docstring for `QuantumScript.expand` and `qml.tape.tape.expand_tape`.
Expand All @@ -146,8 +150,16 @@
[(#5978)](https://github.com/PennyLaneAI/pennylane/pull/5978)

* `qml.AmplitudeEmbedding` has better support for features using low precision integer data types.
[(#5969)](https://github.com/PennyLaneAI/pennylane/pull/5969)
[(#5969)](https://github.com/PennyLaneAI/pennylane/pull/5969)

* `qml.BasisState` now works with jax.jit.
[(#6021)](https://github.com/PennyLaneAI/pennylane/pull/6021)

* `qml.BasisEmbedding` now gives the correct decomposition.
[(#6021)](https://github.com/PennyLaneAI/pennylane/pull/6021)

* `qml.BasisEmbedding` now works with lightning.qubit and jax.jit.
[(#6021)](https://github.com/PennyLaneAI/pennylane/pull/6021)

<h3>Contributors ✍️</h3>

Expand Down
2 changes: 1 addition & 1 deletion pennylane/ops/qubit/state_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def compute_decomposition(features, wires):
**Example:**
>>> qml.BasisState.compute_decomposition([1,0], wires=(0,1))
[BasisStatePreparation([1, 0], wires=[0, 1])]
[X(0)]
"""

Expand Down
10 changes: 10 additions & 0 deletions pennylane/templates/state_preparations/basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import numpy as np
import warnings

Check notice on line 19 in pennylane/templates/state_preparations/basis.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane/templates/state_preparations/basis.py#L19

standard import "import warnings" should be placed before "import numpy as np" (wrong-import-order)

import pennylane as qml
from pennylane.operation import AnyWires, Operation
Expand All @@ -30,6 +31,8 @@ class BasisStatePreparation(Operation):
``basis_state`` influences the circuit architecture and is therefore incompatible with
gradient computations.
``BasisStatePreparation`` is deprecated and will be removed in version 0.39. Instead, please use ``BasisState``."
Args:
basis_state (array): Input array of shape ``(n,)``, where n is the number of wires
the state preparation acts on.
Expand Down Expand Up @@ -59,6 +62,13 @@ def circuit(basis_state):
ndim_params = (1,)

def __init__(self, basis_state, wires, id=None):

warnings.warn(
"BasisStatePreparation is deprecated and will be removed in version 0.39. "
"Instead, please use BasisState.",
qml.PennyLaneDeprecationWarning,
)

basis_state = qml.math.stack(basis_state)

# check if the `basis_state` param is batched
Expand Down
4 changes: 4 additions & 0 deletions tests/ops/qubit/test_state_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def test_adjoint_error_exception(op):
with pytest.raises(qml.operation.AdjointUndefinedError):
op.adjoint()

def test_BasisStatePreparation_is_deprecated():
"""Test that my_feature is deprecated."""
with pytest.warns(qml.PennyLaneDeprecationWarning, match="BasisStatePreparation is deprecated"):
_ = qml.BasisStatePreparation()

@pytest.mark.parametrize(
"op, mat, base",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_qnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,15 +958,15 @@ def test_sampling_with_mcm(self, basis_state, mocker):
@qml.qnode(dev)
def cry_qnode(x):
"""QNode where we apply a controlled Y-rotation."""
qml.BasisStatePreparation(basis_state, wires=[0, 1])
qml.BasisState(basis_state, wires=[0, 1])
qml.CRY(x, wires=[0, 1])
return qml.sample(qml.PauliZ(1))

@qml.qnode(dev)
def conditional_ry_qnode(x):
"""QNode where the defer measurements transform is applied by
default under the hood."""
qml.BasisStatePreparation(basis_state, wires=[0, 1])
qml.BasisState(basis_state, wires=[0, 1])
m_0 = qml.measure(0)
qml.cond(m_0, qml.RY)(x, wires=1)
return qml.sample(qml.PauliZ(1))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_qnode_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,15 +1149,15 @@ def test_sampling_with_mcm(self, basis_state, mocker):
@qml.qnode(dev)
def cry_qnode(x):
"""QNode where we apply a controlled Y-rotation."""
qml.BasisStatePreparation(basis_state, wires=[0, 1])
qml.BasisState(basis_state, wires=[0, 1])
qml.CRY(x, wires=[0, 1])
return qml.sample(qml.PauliZ(1))

@qml.qnode(dev)
def conditional_ry_qnode(x):
"""QNode where the defer measurements transform is applied by
default under the hood."""
qml.BasisStatePreparation(basis_state, wires=[0, 1])
qml.BasisState(basis_state, wires=[0, 1])
m_0 = qml.measure(0)
qml.cond(m_0, qml.RY)(x, wires=1)
return qml.sample(qml.PauliZ(1))
Expand Down

0 comments on commit 5f8ba56

Please sign in to comment.