diff --git a/doc/development/deprecations.rst b/doc/development/deprecations.rst index 05abd31e808..b7e58cb2279 100644 --- a/doc/development/deprecations.rst +++ b/doc/development/deprecations.rst @@ -45,6 +45,20 @@ Pending deprecations - Deprecated in v0.39 - Will be removed in v0.40 +* The ``decomp_depth`` argument in ``qml.device`` is deprecated. + + - Deprecated in v0.38 + - Will be removed in v0.39 + +* The ``simplify`` argument in ``qml.Hamiltonian`` and ``qml.ops.LinearCombination`` is deprecated. + Instead, ``qml.simplify()`` can be called on the constructed operator. + + - Deprecated in v0.37 + - Will be removed in v0.39 + +* The :class:`~pennylane.BasisStatePreparation` template is deprecated. + Instead, use :class:`~pennylane.BasisState`. + * The ``QubitStateVector`` template is deprecated. Instead, use ``StatePrep``. diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index cc1be8d6f1b..dcb051a1ef4 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -104,6 +104,10 @@

Deprecations 👋

+* The `qml.BasisStatePreparation` template is deprecated. + Instead, use `qml.BasisState`. + [(#6021)](https://github.com/PennyLaneAI/pennylane/pull/6021) + * The `'ancilla'` argument for `qml.iterative_qpe` has been deprecated. Instead, use the `'aux_wire'` argument. [(#6277)](https://github.com/PennyLaneAI/pennylane/pull/6277) diff --git a/pennylane/devices/tests/test_templates.py b/pennylane/devices/tests/test_templates.py index 86e1101340a..c91304488ef 100644 --- a/pennylane/devices/tests/test_templates.py +++ b/pennylane/devices/tests/test_templates.py @@ -225,6 +225,9 @@ def circuit(): [math.fidelity_statevector(circuit(), exp_state)], [1.0], atol=tol(dev.shots) ) + @pytest.mark.filterwarnings( + "ignore:BasisStatePreparation is deprecated:pennylane.PennyLaneDeprecationWarning" + ) def test_BasisStatePreparation(self, device, tol): """Test the BasisStatePreparation template.""" dev = device(4) diff --git a/pennylane/templates/state_preparations/basis.py b/pennylane/templates/state_preparations/basis.py index 48211a6d1e8..d63fa0f1b32 100644 --- a/pennylane/templates/state_preparations/basis.py +++ b/pennylane/templates/state_preparations/basis.py @@ -15,6 +15,8 @@ Contains the BasisStatePreparation template. """ +import warnings + import numpy as np import pennylane as qml @@ -30,6 +32,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.40. 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. @@ -59,6 +63,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.40. " + "Instead, please use BasisState.", + qml.PennyLaneDeprecationWarning, + ) + basis_state = qml.math.stack(basis_state) # check if the `basis_state` param is batched diff --git a/tests/capture/test_templates.py b/tests/capture/test_templates.py index d04990b2971..619723a9b02 100644 --- a/tests/capture/test_templates.py +++ b/tests/capture/test_templates.py @@ -27,8 +27,12 @@ jax = pytest.importorskip("jax") jnp = jax.numpy -pytestmark = pytest.mark.jax - +pytestmark = [ + pytest.mark.jax, + pytest.mark.filterwarnings( + "ignore:BasisStatePreparation is deprecated:pennylane.PennyLaneDeprecationWarning" + ), +] original_op_bind_code = qml.operation.Operator._primitive_bind_call.__code__ diff --git a/tests/templates/test_state_preparations/test_basis_state_prep.py b/tests/templates/test_state_preparations/test_basis_state_prep.py index 90b88463a05..441af8e007d 100644 --- a/tests/templates/test_state_preparations/test_basis_state_prep.py +++ b/tests/templates/test_state_preparations/test_basis_state_prep.py @@ -21,6 +21,10 @@ import pennylane as qml +pytestmark = pytest.mark.filterwarnings( + "ignore:BasisStatePreparation is deprecated:pennylane.PennyLaneDeprecationWarning" +) + def test_standard_validity(): """Check the operation using the assert_valid function.""" @@ -33,6 +37,12 @@ def test_standard_validity(): qml.ops.functions.assert_valid(op) +def test_BasisStatePreparation_is_deprecated(): + """Test that BasisStatePreparation is deprecated.""" + with pytest.warns(qml.PennyLaneDeprecationWarning, match="BasisStatePreparation is deprecated"): + _ = qml.BasisStatePreparation([1, 0], wires=[0, 1]) + + class TestDecomposition: """Tests that the template defines the correct decomposition.""" diff --git a/tests/test_qnode.py b/tests/test_qnode.py index 1322ca62c16..19ce1b067a6 100644 --- a/tests/test_qnode.py +++ b/tests/test_qnode.py @@ -975,7 +975,7 @@ 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)) @@ -983,7 +983,7 @@ def cry_qnode(x): 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)) diff --git a/tests/test_qnode_legacy.py b/tests/test_qnode_legacy.py index 73eaf29b302..681be8161fe 100644 --- a/tests/test_qnode_legacy.py +++ b/tests/test_qnode_legacy.py @@ -890,7 +890,7 @@ 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)) @@ -898,7 +898,7 @@ def cry_qnode(x): 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)) diff --git a/tests/transforms/test_batch_input.py b/tests/transforms/test_batch_input.py index 3d97e981ed2..2499aafdcdd 100644 --- a/tests/transforms/test_batch_input.py +++ b/tests/transforms/test_batch_input.py @@ -200,6 +200,9 @@ def circuit2(data, weights): assert np.allclose(res, indiv_res) +@pytest.mark.filterwarnings( + "ignore:BasisStatePreparation is deprecated:pennylane.PennyLaneDeprecationWarning" +) def test_basis_state_preparation(mocker): """Test that batching works for BasisStatePreparation""" dev = qml.device("default.qubit", wires=3) diff --git a/tests/transforms/test_batch_params.py b/tests/transforms/test_batch_params.py index ad4daddeb69..29b89ebda4a 100644 --- a/tests/transforms/test_batch_params.py +++ b/tests/transforms/test_batch_params.py @@ -174,6 +174,9 @@ def circuit2(data, weights): assert np.allclose(res, indiv_res) +@pytest.mark.filterwarnings( + "ignore:BasisStatePreparation is deprecated:pennylane.PennyLaneDeprecationWarning" +) def test_basis_state_preparation(mocker): """Test that batching works for BasisStatePreparation""" dev = qml.device("default.qubit", wires=4) diff --git a/tests/transforms/test_defer_measurements.py b/tests/transforms/test_defer_measurements.py index 3d5e98791ea..52a65f924a5 100644 --- a/tests/transforms/test_defer_measurements.py +++ b/tests/transforms/test_defer_measurements.py @@ -1347,6 +1347,9 @@ def quantum_control_circuit(rads): class TestTemplates: """Tests templates being conditioned on mid-circuit measurement outcomes.""" + @pytest.mark.filterwarnings( + "ignore:BasisStatePreparation is deprecated:pennylane.PennyLaneDeprecationWarning" + ) def test_basis_state_prep(self): """Test the basis state prep template conditioned on mid-circuit measurement outcomes."""