This subpackage provides integration tests for the devices with PennyLane’s core functionalities. At the moment, the tests only run on devices based on the ‘qubit’ model.
The tests require that
flaky be installed.
These can be installed using
pip install pytest pytest-mock flaky
The tests can also be run on an external device from a PennyLane plugin, such as
'qiskit.aer'. For this, make sure you have the correct dependencies installed.
Most tests query the device’s capabilities and only get executed if they apply to the device. Both analytic devices (producing an exact probability distribution) and non-analytic devices (producing an estimated probability distribution) are tested.
For non-analytic tests, the tolerance of the assert statements is set to a high enough value to account for stochastic fluctuations. Flaky is used to automatically repeat failed tests.
There are several methods for running the tests against a particular device (i.e., for
'default.qubit'), detailed below.
pytest path_to_pennylane_src/devices/tests --device=default.qubit --shots=10000
The location of your PennyLane installation may differ depending on installation method and
operating system. To find the location, you can use the
>>> from pennylane.devices.tests import get_device_tests >>> get_device_tests()
The pl-device-test CLI¶
Alternatively, PennyLane provides a command line interface for invoking the device tests.
pl-device-test --device default.qubit --shots 10000
Finally, the tests can be invoked within a Python session via the
>>> from pennylane.devices.tests import test_device >>> test_device("default.qubit")
For more details on the available arguments, see the