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 QuantumScript.is_sampled and QuantumScript.all_sampled #5072

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 14 additions & 14 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ Pending deprecations
- Deprecated in v0.34
- Will be removed in v0.36

* ``QuantumScript.is_sampled`` and ``QuantumScript.all_sampled`` are deprecated. Users should now validate
these properties manually.

.. code-block:: python

from pennylane.measurements import *
sample_types = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)
is_sample_type = [isinstance(m, sample_types) for m in tape.measurements]
is_sampled = any(is_sample_type)
all_sampled = all(is_sample_type)

- Deprecated in v0.34
- Will be removed in v0.35

* ``qml.ExpvalCost`` has been deprecated, and usage will now raise a warning.

- Deprecated in v0.24
Expand Down Expand Up @@ -161,6 +147,20 @@ Completed deprecation cycles
- Deprecated in v0.34
- Removed in v0.35

* ``QuantumScript.is_sampled`` and ``QuantumScript.all_sampled`` have been removed. Users should now validate
these properties manually.

.. code-block:: python

from pennylane.measurements import *
sample_types = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)
is_sample_type = [isinstance(m, sample_types) for m in tape.measurements]
is_sampled = any(is_sample_type)
all_sampled = all(is_sample_type)

- Deprecated in v0.34
- Removed in v0.35

* Specifying ``control_values`` passed to ``qml.ctrl`` as a string is no longer supported.

- Deprecated in v0.25
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 @@ -73,6 +73,10 @@
(with potentially negative eigenvalues) has been implemented.
[(#5048)](https://github.com/PennyLaneAI/pennylane/pull/5048)

* `QuantumScript.is_sampled` and `QuantumScript.all_sampled` have been removed. Users should now
validate these properties manually.
Alex-Preciado marked this conversation as resolved.
Show resolved Hide resolved
[(#5072)](https://github.com/PennyLaneAI/pennylane/pull/5072)

<h3>Deprecations 👋</h3>

* `Operator.validate_subspace(subspace)` has been relocated to the `qml.ops.qutrit.parametric_ops`
Expand Down
33 changes: 0 additions & 33 deletions pennylane/tape/qscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@
import copy
from collections import Counter
from typing import List, Union, Optional, Sequence
from warnings import warn

import pennylane as qml
from pennylane.measurements import (
ClassicalShadowMP,
CountsMP,
MeasurementProcess,
ProbabilityMP,
SampleMP,
ShadowExpvalMP,
StateMP,
Shots,
)
Expand Down Expand Up @@ -399,34 +394,6 @@ def op_wires(self) -> Wires:
"""Returns the wires that the tape operations act on."""
return Wires.all_wires(op.wires for op in self.operations)

@property
def is_sampled(self) -> bool:
"""Whether any measurements are of a type that requires samples."""
warn(
"QuantumScript.is_sampled is deprecated. This property should now be "
"validated manually:\n\n"
">>> from pennylane.measurements import *\n"
">>> sample_types = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)\n"
">>> is_sampled = any(isinstance(m, sample_types) for m in tape.measurements)\n",
qml.PennyLaneDeprecationWarning,
)
sample_type = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)
return any(isinstance(m, sample_type) for m in self.measurements)

@property
def all_sampled(self) -> bool:
"""Whether all measurements are of a type that requires samples."""
warn(
"QuantumScript.all_sampled is deprecated. This property should now be "
"validated manually:\n\n"
">>> from pennylane.measurements import *\n"
">>> sample_types = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)\n"
">>> all_sampled = all(isinstance(m, sample_types) for m in tape.measurements)\n",
qml.PennyLaneDeprecationWarning,
)
sample_type = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)
return all(isinstance(m, sample_type) for m in self.measurements)

##### Update METHODS ###############

def _update(self):
Expand Down
13 changes: 0 additions & 13 deletions tests/tape/test_qscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,19 @@ def test_update_circuit_info_wires(self):
@pytest.mark.parametrize("sample_ms", sample_measurements)
def test_update_circuit_info_sampling(self, sample_ms):
qs = QuantumScript(measurements=[qml.expval(qml.PauliZ(0)), sample_ms])
with pytest.warns(UserWarning, match="QuantumScript.is_sampled is deprecated"):
assert qs.is_sampled is True
with pytest.warns(UserWarning, match="QuantumScript.all_sampled is deprecated"):
assert qs.all_sampled is False

shadow_mp = sample_ms.return_type not in (
qml.measurements.Shadow,
qml.measurements.ShadowExpval,
)
assert qs.samples_computational_basis is shadow_mp

qs = QuantumScript(measurements=[sample_ms, sample_ms, qml.sample()])
with pytest.warns(UserWarning, match="QuantumScript.is_sampled is deprecated"):
assert qs.is_sampled is True
with pytest.warns(UserWarning, match="QuantumScript.all_sampled is deprecated"):
assert qs.all_sampled is True
assert qs.samples_computational_basis is True

def test_update_circuit_info_no_sampling(self):
"""Test that all_sampled, is_sampled and samples_computational_basis properties are set to False if no sampling
measurement process exists."""
qs = QuantumScript(measurements=[qml.expval(qml.PauliZ(0))])
with pytest.warns(UserWarning, match="QuantumScript.is_sampled is deprecated"):
assert qs.is_sampled is False
with pytest.warns(UserWarning, match="QuantumScript.all_sampled is deprecated"):
assert qs.all_sampled is False
assert qs.samples_computational_basis is False

def test_samples_computational_basis_correctly(self):
Expand Down
Loading