Skip to content

Commit

Permalink
Merge branch 'master' into fermi-commute
Browse files Browse the repository at this point in the history
  • Loading branch information
willjmax committed Sep 18, 2024
2 parents 6bdf667 + 68fd307 commit 1aa1f56
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 366 deletions.
22 changes: 11 additions & 11 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ 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 ``QubitStateVector`` template is deprecated.
Instead, use ``StatePrep``.

Expand Down Expand Up @@ -106,6 +95,17 @@ Other deprecations
Completed deprecation cycles
----------------------------

* The ``simplify`` argument in ``qml.Hamiltonian`` and ``qml.ops.LinearCombination`` has been removed.
Instead, ``qml.simplify()`` can be called on the constructed operator.

- Deprecated in v0.37
- Removed in v0.39

* The ``decomp_depth`` argument in ``qml.device`` is removed.

- Deprecated in v0.38
- Removed in v0.39

* The functions ``qml.qinfo.classical_fisher`` and ``qml.qinfo.quantum_fisher`` have been removed and migrated to the ``qml.gradients``
module. Therefore, ``qml.gradients.classical_fisher`` and ``qml.gradients.quantum_fisher`` should be used instead.

Expand Down
6 changes: 3 additions & 3 deletions doc/news/new_opmath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ To help identify a fix, select the option below that describes your situation.
>>> qml.Hamiltonian([0.5], [X(0) @ X(1)])
0.5 * (X(0) @ X(1))

The API of :class:`~.ops.op_math.LinearCombination` is identical to that of :class:`~.Hamiltonian`. We can group observables or simplify upon initialization.
The API of :class:`~.ops.op_math.LinearCombination` is identical to that of :class:`~.Hamiltonian`. We can group observables upon initialization.

>>> H1 = qml.Hamiltonian([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc", simplify=True)
>>> H2 = qml.ops.LinearCombination([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc", simplify=True)
>>> H1 = qml.Hamiltonian([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc")
>>> H2 = qml.ops.LinearCombination([0.5, 0.5, 0.5], [X(0) @ X(1), X(0), Y(0)], grouping_type="qwc")
>>> H1 == H2
True

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

<h3>Breaking changes 💔</h3>

* The `simplify` argument in `qml.Hamiltonian` and `qml.ops.LinearCombination` has been removed.
Instead, `qml.simplify()` can be called on the constructed operator.
[(#6279)](https://github.com/PennyLaneAI/pennylane/pull/6279)

* The functions `qml.qinfo.classical_fisher` and `qml.qinfo.quantum_fisher` have been removed and migrated to the `qml.gradients`
module. Therefore, `qml.gradients.classical_fisher` and `qml.gradients.quantum_fisher` should be used instead.
[(#5911)](https://github.com/PennyLaneAI/pennylane/pull/5911)
Expand Down Expand Up @@ -94,6 +98,9 @@
Please use `qml.transforms.split_non_commuting` instead.
[(#6204)](https://github.com/PennyLaneAI/pennylane/pull/6204)

* The `decomp_depth` keyword argument to `qml.device` is removed.
[(#6234)](https://github.com/PennyLaneAI/pennylane/pull/6234)

* `Operator.expand` is now removed. Use `qml.tape.QuantumScript(op.deocomposition())` instead.
[(#6227)](https://github.com/PennyLaneAI/pennylane/pull/6227)

Expand Down
2 changes: 1 addition & 1 deletion pennylane/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.39.0-dev16"
__version__ = "0.39.0-dev17"
43 changes: 13 additions & 30 deletions pennylane/devices/device_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""
This module contains code for the main device construction delegation logic.
"""
import warnings
from importlib import metadata
from sys import version_info

Expand Down Expand Up @@ -57,8 +56,7 @@ def refresh_devices():

# pylint: disable=protected-access
def device(name, *args, **kwargs):
r"""
Load a device and return the instance.
r"""Load a device and return the instance.
This function is used to load a particular quantum device,
which can then be used to construct QNodes.
Expand Down Expand Up @@ -105,12 +103,6 @@ def device(name, *args, **kwargs):
that contains global and/or device specific configurations.
custom_decomps (Dict[Union(str, Operator), Callable]): Custom
decompositions to be applied by the device at runtime.
decomp_depth (int): For when custom decompositions are specified,
the maximum expansion depth used by the expansion function.
.. warning::
The ``decomp_depth`` argument is deprecated and will be removed in version 0.39.
All devices must be loaded by specifying their **short-name** as listed above,
followed by the **wires** (subsystems) you wish to initialize. The ``wires``
Expand All @@ -122,10 +114,10 @@ def device(name, *args, **kwargs):
dev = qml.device('default.qubit', wires=5)
def circuit():
qml.Hadamard(wires=1)
qml.Hadamard(wires=[0])
qml.CNOT(wires=[3, 4])
...
qml.Hadamard(wires=1)
qml.Hadamard(wires=[0])
qml.CNOT(wires=[3, 4])
...
The ``wires`` argument can also be a sequence of unique numbers or strings, specifying custom wire labels
that the user employs to address the wires:
Expand All @@ -135,10 +127,10 @@ def circuit():
dev = qml.device('default.qubit', wires=['ancilla', 'q11', 'q12', -1, 1])
def circuit():
qml.Hadamard(wires='q11')
qml.Hadamard(wires=['ancilla'])
qml.CNOT(wires=['q12', -1])
...
qml.Hadamard(wires='q11')
qml.Hadamard(wires=['ancilla'])
qml.CNOT(wires=['q12', -1])
...
On some newer devices, such as ``default.qubit``, the ``wires`` argument can be omitted altogether,
and instead the wires will be computed when executing a circuit depending on its contents.
Expand All @@ -157,8 +149,8 @@ def circuit():
@qml.qnode(dev)
def circuit(a):
qml.RX(a, wires=0)
return qml.sample(qml.Z(0))
qml.RX(a, wires=0)
return qml.sample(qml.Z(0))
>>> circuit(0.8) # 10 samples are returned
array([ 1, 1, 1, 1, -1, 1, 1, -1, 1, 1])
Expand Down Expand Up @@ -243,15 +235,6 @@ def run_cnot():
# Pop the custom decomposition keyword argument; we will use it here
# only and not pass it to the device.
custom_decomps = kwargs.pop("custom_decomps", None)
decomp_depth = kwargs.pop("decomp_depth", None)

if decomp_depth is not None:
warnings.warn(
"The decomp_depth argument is deprecated and will be removed in version 0.39. ",
qml.PennyLaneDeprecationWarning,
)
else:
decomp_depth = 10

kwargs.pop("config", None)
options.update(kwargs)
Expand Down Expand Up @@ -284,12 +267,12 @@ def _safe_specifier_set(version_str):
if custom_decomps is not None:
if isinstance(dev, qml.devices.LegacyDevice):
custom_decomp_expand_fn = qml.transforms.create_decomp_expand_fn(
custom_decomps, dev, decomp_depth=decomp_depth
custom_decomps, dev, decomp_depth=10
)
dev.custom_expand(custom_decomp_expand_fn)
else:
custom_decomp_preprocess = qml.transforms.tape_expand._create_decomp_preprocessing(
custom_decomps, dev, decomp_depth=decomp_depth
custom_decomps, dev, decomp_depth=10
)
dev.preprocess = custom_decomp_preprocess

Expand Down
25 changes: 0 additions & 25 deletions pennylane/ops/op_math/linear_combination.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class LinearCombination(Sum):
Args:
coeffs (tensor_like): coefficients of the ``LinearCombination`` expression
observables (Iterable[Observable]): observables in the ``LinearCombination`` expression, of same length as ``coeffs``
simplify (bool): Specifies whether the ``LinearCombination`` is simplified upon initialization
(like-terms are combined). The default value is `False`. Note that ``coeffs`` cannot
be differentiated when using the ``'torch'`` interface and ``simplify=True``. Use of this argument is deprecated.
grouping_type (str): If not ``None``, compute and store information on how to group commuting
observables upon initialization. This information may be accessed when a :class:`~.QNode` containing this
``LinearCombination`` is executed on devices. The string refers to the type of binary relation between Pauli words.
Expand All @@ -52,10 +49,6 @@ class LinearCombination(Sum):
.. seealso:: `rustworkx.ColoringStrategy <https://www.rustworkx.org/apiref/rustworkx.ColoringStrategy.html#coloringstrategy>`_
for more information on the ``('lf', 'dsatur', 'gis')`` strategies.
.. warning::
The ``simplify`` argument is deprecated and will be removed in a future release.
Instead, you can call ``qml.simplify`` on the constructed operator.
**Example:**
A ``LinearCombination`` can be created by simply passing the list of coefficients
Expand Down Expand Up @@ -124,7 +117,6 @@ def __init__(
self,
coeffs,
observables: list[Operator],
simplify=False,
grouping_type=None,
method="lf",
_grouping_indices=None,
Expand All @@ -143,23 +135,6 @@ def __init__(
if _pauli_rep is None:
_pauli_rep = self._build_pauli_rep_static(coeffs, observables)

if simplify:

warnings.warn(
"The simplify argument in qml.Hamiltonian and qml.ops.LinearCombination is deprecated. "
"Instead, you can call qml.simplify on the constructed operator.",
qml.PennyLaneDeprecationWarning,
)

# simplify upon initialization changes ops such that they wouldnt be removed in self.queue() anymore
if qml.QueuingManager.recording():
for o in observables:
qml.QueuingManager.remove(o)

coeffs, observables, _pauli_rep = self._simplify_coeffs_ops(
coeffs, observables, _pauli_rep
)

self._coeffs = coeffs

self._ops = [convert_to_opmath(op) for op in observables]
Expand Down
24 changes: 0 additions & 24 deletions pennylane/ops/qubit/hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class Hamiltonian(Observable):
Args:
coeffs (tensor_like): coefficients of the Hamiltonian expression
observables (Iterable[Observable]): observables in the Hamiltonian expression, of same length as coeffs
simplify (bool): Specifies whether the Hamiltonian is simplified upon initialization
(like-terms are combined). The default value is `False`. Use of this argument is deprecated.
grouping_type (str): If not None, compute and store information on how to group commuting
observables upon initialization. This information may be accessed when QNodes containing this
Hamiltonian are executed on devices. The string refers to the type of binary relation between Pauli words.
Expand All @@ -91,10 +89,6 @@ class Hamiltonian(Observable):
can be ``'lf'`` (Largest First) or ``'rlf'`` (Recursive Largest First). Ignored if ``grouping_type=None``.
id (str): name to be assigned to this Hamiltonian instance
.. warning::
The ``simplify`` argument is deprecated and will be removed in a future release.
Instead, you can call ``qml.simplify`` on the constructed operator.
**Example:**
.. note::
Expand Down Expand Up @@ -254,7 +248,6 @@ def __init__(
self,
coeffs: TensorLike,
observables: Iterable[Observable],
simplify: bool = False,
grouping_type: Literal[None, "qwc", "commuting", "anticommuting"] = None,
_grouping_indices: Optional[list[list[int]]] = None,
method: Literal["lf", "rlf"] = "rlf",
Expand Down Expand Up @@ -293,23 +286,6 @@ def __init__(
# commuting observables, since recomputation is costly
self._grouping_indices = _grouping_indices

if simplify:

warn(
"The simplify argument in qml.Hamiltonian and qml.ops.LinearCombination is deprecated. "
"Instead, you can call qml.simplify on the constructed operator.",
qml.PennyLaneDeprecationWarning,
)

# simplify upon initialization changes ops such that they wouldnt be
# removed in self.queue() anymore, removing them here manually.
if qml.QueuingManager.recording():
for o in observables:
qml.QueuingManager.remove(o)

with qml.QueuingManager.stop_recording():
self.simplify()

if grouping_type is not None:
with qml.QueuingManager.stop_recording():
self._grouping_indices = _compute_grouping_indices(
Expand Down
9 changes: 0 additions & 9 deletions tests/devices/test_legacy_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,15 +1074,6 @@ def test_shot_vector_property(self):

assert dev.shots.total_shots == 22

def test_decomp_depth_is_deprecated(self):
"""Test that a warning is raised when using the deprecated decomp_depth argument"""

with pytest.warns(
qml.PennyLaneDeprecationWarning,
match="The decomp_depth argument is deprecated",
):
qml.device("default.qubit", decomp_depth=1)


class TestBatchExecution:
"""Tests for the batch_execute method."""
Expand Down
Loading

0 comments on commit 1aa1f56

Please sign in to comment.