qml.devices¶
Warning
Unless you are a PennyLane or plugin developer, you likely do not need to use these classes directly.
See the main plugins page for more details on available plugins.
Modules
This subpackage provides default devices for PennyLane, which do not need external plugins to be installed. The default devices provide basic built-in qubit and CV circuit simulators that can be used with PennyLane without the need for additional dependencies. They may also be used in the PennyLane test suite in order to verify and test quantum gradient computations.
The default.qubit device is PennyLane’s standard qubit-based device. |
|
This module contains the legacy implementation of default.qubit. |
|
This module contains a jax implementation of the |
|
This module contains a PyTorch implementation of the |
|
This module contains a TensorFlow implementation of the |
|
This module contains an autograd implementation of the |
|
The |
|
The default.mixed device is PennyLane’s standard qubit simulator for mixed-state computations. |
|
The default.qutrit device is PennyLane’s standard qutrit-based device. |
|
The default.qutrit.mixed device is PennyLane’s standard qutrit simulator for mixed-state computations. |
|
This module contains the Clifford simulator using |
|
This module contains the default.tensor device to perform tensor network simulations of quantum circuits using |
|
This module contains the |
|
This module contains the |
|
This module contains the |
|
The null.qubit device is a no-op device, useful for resource estimation, and for benchmarking PennyLane’s auxiliary functionality outside direct circuit evaluations. |
|
This subpackage provides integration tests for the devices with PennyLane’s core functionalities. |
Next generation devices¶
pennylane.devices.Device
is the latest interface for the next generation of devices that
replaces pennylane.Device
and pennylane.QubitDevice
.
While the previous interface pennylane.Device
is imported top level, the new pennylane.devices.Device
is
accessible from the pennylane.devices
submodule.
|
A class to configure the execution of a quantum circuit on a device. |
|
A class to store mid-circuit measurement configurations. |
|
A device driver that can control one or more backends. |
|
A PennyLane device written in Python and capable of backpropagation derivatives. |
|
A PennyLane device to perform tensor network simulations of quantum circuits using quimb. |
|
Null qubit device for PennyLane. |
|
A PennyLane Python-based device for mixed-state qutrit simulation. |
|
A Facade that converts a device from the old |
Preprocessing Transforms¶
The preprocess
module offers several transforms that can be used in constructing the preprocess()
method for devices.
|
Decompose operations until the stopping condition is met. |
|
Validates the observables and measurements for a circuit. |
|
Validates the supported state and sample based measurement processes. |
|
Validates that all wires present in the tape are in the set of provided wires. |
|
Validates the number of workers for multiprocessing. |
Raises a warning if any of the observables is trainable, and raises an error if any trainable parameters belong to state-prep operations. |
|
|
Raises an error if the tape has finite shots. |
Other transforms that may be relevant to device preprocessing include:
|
Quantum function transform that substitutes operations conditioned on measurement outcomes to controlled operations. |
Expand a broadcasted tape into multiple tapes and a function that stacks and squeezes the results. |
|
|
Splits a quantum tape measuring a Sum expectation into multiple tapes of summand expectations, and provides a function to recombine the results. |
|
Splits a circuit into tapes measuring groups of commuting observables. |
|
Splits a tape measuring a Hamiltonian expectation into mutliple tapes of Pauli expectations, and provides a function to recombine the results. |
Modifiers¶
The modifiers
allow for the easy addition of default behaviour to a device.
|
Modifies all functions to accept single tapes in addition to batches. |
|
Modifies all methods to add default simulator style tracking. |
For example with a custom device we can add simulator-style tracking and the ability to handle a single circuit. See the documentation for each modifier for more details.
@simulator_tracking
@single_tape_support
class MyDevice(qml.devices.Device):
def execute(self, circuits, execution_config = qml.devices.DefaultExecutionConfig):
return tuple(0.0 for _ in circuits)
>>> dev = MyDevice()
>>> tape = qml.tape.QuantumTape([qml.S(0)], [qml.expval(qml.X(0))])
>>> with dev.tracker:
... out = dev.execute(tape)
>>> out
0.0
>>> dev.tracker.history
{'batches': [1],
'simulations': [1],
'executions': [1],
'results': [0.0],
'resources': [Resources(num_wires=1, num_gates=1,
gate_types=defaultdict(<class 'int'>, {'S': 1}),
gate_sizes=defaultdict(<class 'int'>, {1: 1}), depth=1,
shots=Shots(total_shots=None, shot_vector=()))]}
Qubit Simulation Tools¶
Submodule for performing qubit-based simulations of quantum circuits.
This submodule is internal and subject to change without a deprecation cycle. Use at your own discretion.
|
Returns an initial state, defaulting to \(\ket{0}\) if no state-prep operator is provided. |
Apply and operator to a given state. |
|
|
Apply a measurement process to a state. |
|
Returns the samples of the measurement process performed on the given state. |
|
Returns a series of samples of a state. |
|
Simulate a single quantum script. |
|
Implements the adjoint method outlined in Jones and Gacon to differentiate an input tape. |
|
The jacobian vector product used in forward mode calculation of derivatives. |
|
The vector jacobian product used in reverse-mode differentiation. |
Qutrit Mixed-State Simulation Tools¶
Submodule for performing mixed state simulations of qutrit-based quantum circuits.
This submodule is internal and subject to change without a deprecation cycle. Use at your own discretion.
|
Returns an initial state, defaulting to \(\ket{0}\bra{0}\) if no state-prep operator is provided. |
Apply an operation to a given state. |
|
|
Apply a measurement process to a state. |
|
Returns the samples of the measurement process performed on the given state. |
|
Returns a series of computational basis samples of a state. |
|
Simulate a single quantum script. |