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 13, 2024
2 parents 58809e1 + 08961dd commit ddde204
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 7,577 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ clean-docs:

test:
$(PYTHON) $(TESTRUNNER)
$(PYTHON) $(PLUGIN_TESTRUNNER) --device=default.qubit.autograd

coverage:
@echo "Generating coverage report..."
$(PYTHON) $(TESTRUNNER) $(COVERAGE)
$(PYTHON) $(PLUGIN_TESTRUNNER) --device=default.qubit.autograd $(COVERAGE) --cov-append

.PHONY:format
format:
Expand Down
24 changes: 12 additions & 12 deletions doc/development/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ Pending deprecations
- Deprecated in v0.39
- Will be removed in v0.40

* All of the legacy devices (any with the name ``default.qubit.{autograd,torch,tf,jax,legacy}``) are deprecated. Use ``default.qubit`` instead,
as it supports backpropagation for the many backends the legacy devices support.

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

* The logic for internally switching a device for a different backpropagation
compatible device is now deprecated, as it was in place for the deprecated ``default.qubit.legacy``.

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

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

- Deprecated in v0.38
Expand Down Expand Up @@ -88,6 +76,18 @@ Other deprecations
Completed deprecation cycles
----------------------------

* All of the legacy devices (any with the name ``default.qubit.{autograd,torch,tf,jax,legacy}``) are removed. Use ``default.qubit`` instead,
as it supports backpropagation for the many backends the legacy devices support.

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

* The logic for internally switching a device for a different backpropagation
compatible device is removed, as it was in place for removed ``default.qubit.legacy``.

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

* `Operator.expand` is now removed. Use `qml.tape.QuantumScript(op.deocomposition())` instead.

- Deprecated in v0.38
Expand Down
5 changes: 4 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@
* Remove support for Python 3.9.
[(#6223)](https://github.com/PennyLaneAI/pennylane/pull/6223)

* `DefaultQubitTF`, `DefaultQubitTorch`, and `DefaultQubitJax` are removed. Please use `default.qubit` for all interfaces.
* `DefaultQubitTF`, `DefaultQubitTorch`, `DefaultQubitJax`, and `DefaultQubitAutograd` are removed.
Please use `default.qubit` for all interfaces.
[(#6207)](https://github.com/PennyLaneAI/pennylane/pull/6207)
[(#6208)](https://github.com/PennyLaneAI/pennylane/pull/6208)
[(#6209)](https://github.com/PennyLaneAI/pennylane/pull/6209)
[(#6210)](https://github.com/PennyLaneAI/pennylane/pull/6210)

* `expand_fn`, `max_expansion`, `override_shots`, and `device_batch_transform` are removed from the
signature of `qml.execute`.
Expand All @@ -84,6 +86,7 @@
* `Operator.expand` is now removed. Use `qml.tape.QuantumScript(op.deocomposition())` instead.
[(#6227)](https://github.com/PennyLaneAI/pennylane/pull/6227)


<h3>Deprecations 👋</h3>

* `QNode.gradient_fn` is deprecated. Please use `QNode.diff_method` and `QNode.get_gradient_fn` instead.
Expand Down
4 changes: 0 additions & 4 deletions pennylane/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
default_qubit
default_qubit_legacy
default_qubit_autograd
default_gaussian
default_mixed
default_qutrit
Expand Down Expand Up @@ -153,9 +152,6 @@ def execute(self, circuits, execution_config = qml.devices.DefaultExecutionConfi
from .default_qubit import DefaultQubit
from .legacy_facade import LegacyDeviceFacade

# DefaultQubitTF and DefaultQubitAutograd not imported here since this
# would lead to an automatic import of tensorflow and autograd, which are
# not PennyLane core dependencies.
# DefaultTensor is not imported here to avoid warnings
# from quimb in case it is installed on the system.
from .default_qubit_legacy import DefaultQubitLegacy
Expand Down
141 changes: 0 additions & 141 deletions pennylane/devices/default_qubit_autograd.py

This file was deleted.

4 changes: 1 addition & 3 deletions pennylane/devices/default_qubit_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,7 @@ def capabilities(cls):
supports_analytic_computation=True,
supports_broadcasting=True,
returns_state=True,
passthru_devices={
"autograd": "default.qubit.autograd",
},
passthru_devices={},
)
return capabilities

Expand Down
94 changes: 5 additions & 89 deletions pennylane/devices/legacy_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Defines a LegacyDeviceFacade class for converting legacy devices to the
new interface.
"""
import warnings

# pylint: disable=not-callable, unused-argument
from contextlib import contextmanager
Expand Down Expand Up @@ -318,79 +317,6 @@ def supports_derivatives(self, execution_config=None, circuit=None) -> bool:

return False

# pylint: disable=protected-access
def _create_temp_device(self, batch):
"""Create a temporary device for use in a backprop execution."""
params = []
for t in batch:
params.extend(t.get_parameters(trainable_only=False))
interface = qml.math.get_interface(*params)
if interface == "numpy":
return self._device

mapped_interface = qml.workflow.execution.INTERFACE_MAP.get(interface, interface)

backprop_interface = self._device.capabilities().get("passthru_interface", None)
if mapped_interface == backprop_interface:
return self._device

backprop_devices = self._device.capabilities().get("passthru_devices", None)

if backprop_devices is None:
raise qml.DeviceError(f"Device {self} does not support backpropagation.")

if backprop_devices[mapped_interface] == self._device.short_name:
return self._device

if self.target_device.short_name != "default.qubit.legacy":
warnings.warn(
"The switching of devices for backpropagation is now deprecated in v0.38 and "
"will be removed in v0.39, as this behavior was developed purely for the "
"deprecated default.qubit.legacy.",
qml.PennyLaneDeprecationWarning,
)

# create new backprop device
expand_fn = self._device.expand_fn
batch_transform = self._device.batch_transform
if hasattr(self._device, "_debugger"):
debugger = self._device._debugger
else:
debugger = "No debugger"
tracker = self._device.tracker

with warnings.catch_warnings():
warnings.filterwarnings(
action="ignore",
category=qml.PennyLaneDeprecationWarning,
message=r"use 'default.qubit'",
)
# we already warned about backprop device switching
new_device = qml.device(
backprop_devices[mapped_interface],
wires=self._device.wires,
shots=self._device.shots,
).target_device

new_device.expand_fn = expand_fn
new_device.batch_transform = batch_transform
if debugger != "No debugger":
new_device._debugger = debugger
new_device.tracker = tracker

return new_device

# pylint: disable=protected-access
def _update_original_device(self, temp_device):
"""After performing an execution with a backprop device, update the state of the original device."""
# Update for state vector simulators that have the _pre_rotated_state attribute
if hasattr(self._device, "_pre_rotated_state"):
self._device._pre_rotated_state = temp_device._pre_rotated_state

# Update for state vector simulators that have the _state attribute
if hasattr(self._device, "_state"):
self._device._state = temp_device._state

def _validate_backprop_method(self, tape):
if tape.shots:
return False
Expand Down Expand Up @@ -441,28 +367,18 @@ def _validate_device_method(self, _):
return self._device.capabilities().get("provides_jacobian", False)

def execute(self, circuits, execution_config=DefaultExecutionConfig):
dev = (
self._create_temp_device(circuits)
if execution_config.gradient_method == "backprop"
else self._device
)
dev = self.target_device

kwargs = {}
if dev.capabilities().get("supports_mid_measure", False):
kwargs["postselect_mode"] = execution_config.mcm_config.postselect_mode

first_shot = circuits[0].shots
if all(t.shots == first_shot for t in circuits):
results = _set_shots(dev, first_shot)(dev.batch_execute)(circuits, **kwargs)
else:
results = tuple(
_set_shots(dev, t.shots)(dev.batch_execute)((t,), **kwargs)[0] for t in circuits
)

if dev is not self._device:
self._update_original_device(dev)

return results
return _set_shots(dev, first_shot)(dev.batch_execute)(circuits, **kwargs)
return tuple(
_set_shots(dev, t.shots)(dev.batch_execute)((t,), **kwargs)[0] for t in circuits
)

def execute_and_compute_derivatives(self, circuits, execution_config=DefaultExecutionConfig):
first_shot = circuits[0].shots
Expand Down
1 change: 0 additions & 1 deletion pennylane/devices/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
# List of all devices that are included in PennyLane
LIST_CORE_DEVICES = {
"default.qubit",
"default.qubit.autograd",
}


Expand Down
2 changes: 1 addition & 1 deletion pennylane/tape/qscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def trainable_params(self) -> list[int]:
.. note::
For devices that support native backpropagation (such as
``default.qubit.tf`` and ``default.qubit.autograd``), this
``default.qubit`` and ``default.mixed``), this
property contains no relevant information when using
backpropagation to compute gradients.
Expand Down
2 changes: 1 addition & 1 deletion pennylane/workflow/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _get_ml_boundary_execute(
else:
from .interfaces.jax import jax_jvp_execute as ml_boundary

except ImportError as e: # pragma: no-cover
except ImportError as e: # pragma: no cover
raise qml.QuantumFunctionError(
f"{mapped_interface} not found. Please install the latest "
f"version of {mapped_interface} to enable the '{mapped_interface}' interface."
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"default.qubit = pennylane.devices:DefaultQubit",
"default.qubit.legacy = pennylane.devices:DefaultQubitLegacy",
"default.gaussian = pennylane.devices:DefaultGaussian",
"default.qubit.autograd = pennylane.devices.default_qubit_autograd:DefaultQubitAutograd",
"default.mixed = pennylane.devices.default_mixed:DefaultMixed",
"null.qubit = pennylane.devices.null_qubit:NullQubit",
"default.qutrit = pennylane.devices.default_qutrit:DefaultQutrit",
Expand Down
Loading

0 comments on commit ddde204

Please sign in to comment.