From 35d8d18b90b8fc347f18ad93c58d3f93e5621e3c Mon Sep 17 00:00:00 2001 From: antalszava Date: Tue, 9 Feb 2021 13:56:27 -0500 Subject: [PATCH] No backprop devices (#61) * Getting lighting * revert test hack * formatting * Revert "formatting" This reverts commit b2a082c2b4dd3da91cbbd35d74ec4d9351e14572. * formatting * Revert "revert test hack" This reverts commit e410e3b045b04b50968a890593ca85965e1758f1. * test no backprop * qfunc * Update tests/test_apply.py Co-authored-by: Josh Izaac * test best diff method * changelog Co-authored-by: Josh Izaac --- CHANGELOG.md | 7 +++++++ pennylane_lightning/lightning_qubit.py | 1 + tests/test_apply.py | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24ff2ca09..e6541a75c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,17 @@ ### Bug fixes +* Fixes a bug where the `QNode` would swap `LightningQubit` to + `DefaultQubitAutograd` on device execution due to the inherited + `passthru_devices` entry of the `capabilities` dictionary. + [(#61)](https://github.com/PennyLaneAI/pennylane-lightning/pull/61) + ### Contributors This release contains contributions from (in alphabetical order): +Josh Izaac, Antal Száva + --- # Release 0.14.0 diff --git a/pennylane_lightning/lightning_qubit.py b/pennylane_lightning/lightning_qubit.py index 52476aad9..b2c6b9d5f 100644 --- a/pennylane_lightning/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit.py @@ -107,6 +107,7 @@ def capabilities(cls): supports_analytic_computation=True, returns_state=True, ) + capabilities.pop("passthru_devices", None) return capabilities def apply(self, operations, rotations=None, **kwargs): diff --git a/tests/test_apply.py b/tests/test_apply.py index 28fa6a78c..57c2ea84d 100644 --- a/tests/test_apply.py +++ b/tests/test_apply.py @@ -454,6 +454,29 @@ def test_load_default_qubit_device(self): assert dev.analytic assert dev.short_name == "lightning.qubit" + def test_no_backprop(self): + """Test that lightning.qubit does not support the backprop + differentiation method.""" + + dev = qml.device("lightning.qubit", wires=2) + def circuit(): + """Simple quantum function.""" + return qml.expval(qml.PauliZ(0)) + + with pytest.raises(qml.QuantumFunctionError): + qml.QNode(circuit, dev, diff_method="backprop") + + def test_best_gets_lightning(self): + """Test that the best differentiation method returns lightning + qubit.""" + dev = qml.device("lightning.qubit", wires=2) + def circuit(): + """Simple quantum function.""" + return qml.expval(qml.PauliZ(0)) + + qnode = qml.QNode(circuit, dev, diff_method="best") + assert isinstance(qnode.device, LightningQubit) + def test_args(self): """Test that the plugin requires correct arguments"""