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 decomp_depth from qml.device constructor #6234

Merged
merged 17 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
10 changes: 5 additions & 5 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ Pending deprecations
- Deprecated in v0.38
- Will be removed in v0.39

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

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

* The functions ``qml.qinfo.classical_fisher`` and ``qml.qinfo.quantum_fisher`` are deprecated since they are being migrated
to the ``qml.gradients`` module. Therefore, ``qml.gradients.classical_fisher`` and ``qml.gradients.quantum_fisher`` should be used instead.

Expand Down Expand Up @@ -82,6 +77,11 @@ Other deprecations
Completed deprecation cycles
----------------------------

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

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

* The ``expansion_strategy`` attribute of ``qml.QNode`` is removed.
Users should make use of ``qml.workflow.construct_batch``, should they require fine control over the output tape(s).

Expand Down
2 changes: 2 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
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.
albi3ro marked this conversation as resolved.
Show resolved Hide resolved

<h3>Deprecations 👋</h3>

<h3>Documentation 📝</h3>
Expand Down
63 changes: 23 additions & 40 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,37 +56,36 @@ 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.

PennyLane comes with support for the following devices:

* :mod:`'default.qubit' <pennylane.devices.default_qubit>`: a simple
state simulator of qubit-based quantum circuit architectures.
state simulator of qubit-based quantum circuit architectures.

* :mod:`'default.mixed' <pennylane.devices.default_mixed>`: a mixed-state
simulator of qubit-based quantum circuit architectures.
simulator of qubit-based quantum circuit architectures.

* ``'lightning.qubit'``: a more performant state simulator of qubit-based
quantum circuit architectures written in C++.
quantum circuit architectures written in C++.

* :mod:`'default.qutrit' <pennylane.devices.default_qutrit>`: a simple
state simulator of qutrit-based quantum circuit architectures.
state simulator of qutrit-based quantum circuit architectures.

* :mod:`'default.qutrit.mixed' <pennylane.devices.default_qutrit_mixed>`: a
mixed-state simulator of qutrit-based quantum circuit architectures.
mixed-state simulator of qutrit-based quantum circuit architectures.

* :mod:`'default.gaussian' <pennylane.devices.default_gaussian>`: a simple simulator
of Gaussian states and operations on continuous-variable circuit architectures.
of Gaussian states and operations on continuous-variable circuit architectures.

* :mod:`'default.clifford' <pennylane.devices.default_clifford>`: an efficient
simulator of Clifford circuits.
simulator of Clifford circuits.

* :mod:`'default.tensor' <pennylane.devices.default_tensor>`: a simulator
of quantum circuits based on tensor networks.
of quantum circuits based on tensor networks.

Additional devices are supported through plugins — see
the `available plugins <https://pennylane.ai/plugins.html>`_ for more
Expand All @@ -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 @@ -203,12 +195,12 @@ def ion_trap_cnot(wires, **_):
'default.qubit', wires=2, custom_decomps={"CNOT" : ion_trap_cnot}
)

@qml.qnode(dev)
@qml.qnode(dev, expansion_strategy="device")
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
def run_cnot():
qml.CNOT(wires=[0, 1])
return qml.expval(qml.X(1))

>>> print(qml.draw(run_cnot, level="device")())
>>> print(qml.draw(run_cnot)())
albi3ro marked this conversation as resolved.
Show resolved Hide resolved
0: ──RY(1.57)─╭IsingXX(1.57)──RX(-1.57)──RY(-1.57)─┤
1: ───────────╰IsingXX(1.57)──RY(-1.57)────────────┤ <X>

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
Loading