diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index 737f658bd24..10b43749d35 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -6,6 +6,10 @@
Improvements 🛠
+* `qml.devices.LegacyDevice` is now an alias for `qml.Device`, so it is easier to distinguish it from
+ `qml.devices.Device`, which follows the new device API.
+ [(#5581)](https://github.com/PennyLaneAI/pennylane/pull/5581)
+
Breaking changes 💔
Deprecations 👋
@@ -17,3 +21,5 @@
Contributors ✍️
This release contains contributions from (in alphabetical order):
+
+Pietropaolo Frisoni
diff --git a/pennylane/__init__.py b/pennylane/__init__.py
index 07aa57f556d..304ac4408f8 100644
--- a/pennylane/__init__.py
+++ b/pennylane/__init__.py
@@ -395,7 +395,7 @@ def run_cnot():
# Once the device is constructed, we set its custom expansion function if
# any custom decompositions were specified.
if custom_decomps is not None:
- if isinstance(dev, pennylane.Device):
+ if isinstance(dev, pennylane.devices.LegacyDevice):
custom_decomp_expand_fn = pennylane.transforms.create_decomp_expand_fn(
custom_decomps, dev, decomp_depth=decomp_depth
)
diff --git a/pennylane/debugging.py b/pennylane/debugging.py
index f6ab56c13b6..abfb4c5d24b 100644
--- a/pennylane/debugging.py
+++ b/pennylane/debugging.py
@@ -30,7 +30,7 @@ class _Debugger:
def __init__(self, dev):
# old device API: check if Snapshot is supported
- if isinstance(dev, qml.Device) and "Snapshot" not in dev.operations:
+ if isinstance(dev, qml.devices.LegacyDevice) and "Snapshot" not in dev.operations:
raise DeviceError("Device does not support snapshots.")
# new device API: check if it's the simulator device
diff --git a/pennylane/devices/__init__.py b/pennylane/devices/__init__.py
index c3de122219d..ecbb9ef5fe7 100644
--- a/pennylane/devices/__init__.py
+++ b/pennylane/devices/__init__.py
@@ -158,3 +158,4 @@ def execute(self, circuits, execution_config = qml.devices.DefaultExecutionConfi
from .default_clifford import DefaultClifford
from .null_qubit import NullQubit
from .default_qutrit_mixed import DefaultQutritMixed
+from .._device import Device as LegacyDevice
diff --git a/pennylane/qcut/cutstrategy.py b/pennylane/qcut/cutstrategy.py
index cf054bd03d4..c0dea3e6ba0 100644
--- a/pennylane/qcut/cutstrategy.py
+++ b/pennylane/qcut/cutstrategy.py
@@ -125,16 +125,16 @@ def __post_init__(
if devices is None and self.max_free_wires is None:
raise ValueError("One of arguments `devices` and max_free_wires` must be provided.")
- if isinstance(devices, (qml.Device, qml.devices.Device)):
+ if isinstance(devices, (qml.devices.LegacyDevice, qml.devices.Device)):
devices = (devices,)
if devices is not None:
if not isinstance(devices, SequenceType) or any(
- (not isinstance(d, (qml.Device, qml.devices.Device)) for d in devices)
+ (not isinstance(d, (qml.devices.LegacyDevice, qml.devices.Device)) for d in devices)
):
raise ValueError(
"Argument `devices` must be a list or tuple containing elements of type "
- "`qml.Device` or `qml.devices.Device`"
+ "`qml.devices.LegacyDevice` or `qml.devices.Device`"
)
device_wire_sizes = [len(d.wires) for d in devices]
diff --git a/pennylane/transforms/core/transform_dispatcher.py b/pennylane/transforms/core/transform_dispatcher.py
index 873449d6f8d..2802ef35122 100644
--- a/pennylane/transforms/core/transform_dispatcher.py
+++ b/pennylane/transforms/core/transform_dispatcher.py
@@ -120,7 +120,7 @@ def processing_fn(results):
if isinstance(obj, qml.QNode):
return self._qnode_transform(obj, targs, tkwargs)
# TODO: Remove with the previous device generation
- if isinstance(obj, qml.Device):
+ if isinstance(obj, qml.devices.LegacyDevice):
return self._old_device_transform(obj, targs, tkwargs)
if isinstance(obj, qml.devices.Device):
return self._device_transform(obj, targs, tkwargs)
diff --git a/pennylane/transforms/tape_expand.py b/pennylane/transforms/tape_expand.py
index ede35d355c2..fae205a90a1 100644
--- a/pennylane/transforms/tape_expand.py
+++ b/pennylane/transforms/tape_expand.py
@@ -502,7 +502,7 @@ def circuit():
1: ──H─╰Z──H─┤
"""
- if isinstance(dev, qml.Device):
+ if isinstance(dev, qml.devices.LegacyDevice):
original_custom_expand_fn = dev.custom_expand_fn
# Create a new expansion function; stop at things that do not have
diff --git a/pennylane/workflow/execution.py b/pennylane/workflow/execution.py
index 7febd4e60d3..5f77ba530a0 100644
--- a/pennylane/workflow/execution.py
+++ b/pennylane/workflow/execution.py
@@ -266,7 +266,7 @@ def _make_inner_execute(
For higher order derivatives, the "inner execute" will be another ml framework execute.
"""
- if isinstance(device, qml.Device):
+ if isinstance(device, qml.devices.LegacyDevice):
device_execution = set_shots(device, override_shots)(device.batch_execute)
else:
device_execution = partial(device.execute, execution_config=execution_config)
@@ -534,7 +534,7 @@ def cost_fn(params, x):
if (
device_vjp
- and isinstance(device, qml.Device)
+ and isinstance(device, qml.devices.LegacyDevice)
and "lightning" not in getattr(device, "short_name", "").lower()
):
raise qml.QuantumFunctionError(
diff --git a/pennylane/workflow/jacobian_products.py b/pennylane/workflow/jacobian_products.py
index 4d5e2ea2f76..cb982fd8220 100644
--- a/pennylane/workflow/jacobian_products.py
+++ b/pennylane/workflow/jacobian_products.py
@@ -414,7 +414,7 @@ def __init__(
self._execution_config = execution_config
self._gradient_kwargs = gradient_kwargs
- self._uses_new_device = not isinstance(device, qml.Device)
+ self._uses_new_device = not isinstance(device, qml.devices.LegacyDevice)
# only really need to keep most recent entry, but keeping 10 around just in case
self._results_cache = LRUCache(maxsize=10)
diff --git a/pennylane/workflow/qnode.py b/pennylane/workflow/qnode.py
index 7941fa89fe3..e0ee8c696b8 100644
--- a/pennylane/workflow/qnode.py
+++ b/pennylane/workflow/qnode.py
@@ -54,7 +54,7 @@ def _convert_to_interface(res, interface):
# pylint: disable=protected-access
def _get_device_shots(device) -> Shots:
- if isinstance(device, Device):
+ if isinstance(device, qml.devices.LegacyDevice):
if device._shot_vector:
return Shots(device._raw_shot_sequence)
return Shots(device.shots)
@@ -467,7 +467,7 @@ def __init__(
f"one of {SUPPORTED_INTERFACES}."
)
- if not isinstance(device, (Device, qml.devices.Device)):
+ if not isinstance(device, (qml.devices.LegacyDevice, qml.devices.Device)):
raise qml.QuantumFunctionError(
"Invalid device. Device must be a valid PennyLane device."
)
@@ -649,7 +649,7 @@ def get_gradient_fn(
if diff_method == "best":
return QNode.get_best_method(device, interface, tape=tape)
- if isinstance(device, qml.Device):
+ if isinstance(device, qml.devices.LegacyDevice):
# handled by device.supports_derivatives with new device interface
if diff_method == "backprop":
return QNode._validate_backprop_method(device, interface, tape=tape)