qml.devices.tests

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 pytest, pytest-mock, and flaky be installed. These can be installed using pip:

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.

Using pytest

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 get_device_tests() function:

>>> 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

Within Python

Finally, the tests can be invoked within a Python session via the test_device() function:

>>> from pennylane.devices.tests import test_device
>>> test_device("default.qubit")

For more details on the available arguments, see the test_device() documentation.

Functions

Functions

cli()

The PennyLane device test command line interface.

get_device_tests()

Returns the location of the device integration tests.

test_device(device_name[, shots, skip_ops, ...])

Run the device integration tests using an installed PennyLane device.