Default qubit plugin¶

Module name: pennylane.plugins.default_qubit

Short name: "default.qubit"

The default plugin is meant to be used as a template for writing PennyLane device plugins for new qubit-based backends.

It implements the necessary Device methods as well as some built-in qubit operations and expectations, and provides a very simple pure state simulation of a qubit-based quantum circuit architecture.

The following is the technical documentation of the implementation of the plugin. You will not need to read and understand this to use this plugin.

Auxillary functions¶

 spectral_decomposition_qubit(A) Spectral decomposition of a $$2\times 2$$ Hermitian matrix. unitary(*args) Input validation for an arbitary unitary operation. hermitian(*args) Input validation for an arbitary Hermitian expectation.

Gates and operations¶

 Rphi(phi) One-qubit phase shift. Rotx(theta) One-qubit rotation about the x axis. Roty(theta) One-qubit rotation about the y axis. Rotz(theta) One-qubit rotation about the z axis. Rot3(a, b, c) Arbitrary one-qubit rotation using three Euler angles. X Pauli-X matrix Y Pauli-Y matrix Z Pauli-Z matrix H Hadamard gate CNOT CNOT gate SWAP SWAP gate CZ CZ gate

Expectations¶

 X Pauli-X matrix Y Pauli-Y matrix Z Pauli-Z matrix

Classes¶

 DefaultQubit(wires, *[, shots]) Default qubit device for PennyLane.

Code details¶

spectral_decomposition_qubit(A)[source]

Spectral decomposition of a $$2\times 2$$ Hermitian matrix.

Parameters: A (array) – $$2\times 2$$ Hermitian matrix (a, P): eigenvalues and hermitian projectors such that $$A = \sum_k a_k P_k$$. (vector[float], list[array[complex]])
X = array([[0, 1], [1, 0]])

Pauli-X matrix

Y = array([[ 0.+0.j, -0.-1.j], [ 0.+1.j, 0.+0.j]])

Pauli-Y matrix

Z = array([[ 1, 0], [ 0, -1]])

Pauli-Z matrix

H = array([[ 0.70710678, 0.70710678], [ 0.70710678, -0.70710678]])

CNOT = array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])

CNOT gate

SWAP = array([[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])

SWAP gate

CZ = array([[ 1, 0, 0, 0], [ 0, 1, 0, 0], [ 0, 0, 1, 0], [ 0, 0, 0, -1]])

CZ gate

Rphi(phi)[source]

One-qubit phase shift.

Parameters: phi (float) – phase shift angle unitary 2x2 phase shift matrix array
Rotx(theta)[source]

One-qubit rotation about the x axis.

Parameters: theta (float) – rotation angle unitary 2x2 rotation matrix $$e^{-i \sigma_x \theta/2}$$ array
Roty(theta)[source]

One-qubit rotation about the y axis.

Parameters: theta (float) – rotation angle unitary 2x2 rotation matrix $$e^{-i \sigma_y \theta/2}$$ array
Rotz(theta)[source]

One-qubit rotation about the z axis.

Parameters: theta (float) – rotation angle unitary 2x2 rotation matrix $$e^{-i \sigma_z \theta/2}$$ array
Rot3(a, b, c)[source]

Arbitrary one-qubit rotation using three Euler angles.

Parameters: a,b,c (float) – rotation angles unitary 2x2 rotation matrix rz(c) @ ry(b) @ rz(a) array
unitary(*args)[source]

Input validation for an arbitary unitary operation.

Parameters: args (array) – square unitary matrix square unitary matrix array
hermitian(*args)[source]

Input validation for an arbitary Hermitian expectation.

Parameters: args (array) – square hermitian matrix square hermitian matrix array
identity(*_)[source]

Identity matrix for expectations.

Returns: 2x2 identity matrix array
class DefaultQubit(wires, *, shots=0)[source]

Default qubit device for PennyLane.

Parameters: wires (int) – the number of modes to initialize the device in shots (int) – How many times the circuit should be evaluated (or sampled) to estimate the expectation values. A value of 0 yields the exact result.
pre_apply()[source]

Called during execute() before the individual operations are executed.

apply(operation, wires, par)[source]

Apply a quantum operation.

For plugin developers: this function should apply the operation on the device.

Parameters: operation (str) – name of the operation wires (Sequence[int]) – subsystems the operation is applied on par (tuple) – parameters for the operation
expval(expectation, wires, par)[source]

Return the expectation value of an expectation.

For plugin developers: this function should return the expectation value of the given expectation on the device.

Parameters: expectation (str) – name of the expectation wires (Sequence[int]) – subsystems the expectation value is to be measured on par (tuple) – parameters for the observable expectation value float
_get_operator_matrix(operation, par)[source]

Get the operator matrix for a given operation or expectation.

Parameters: operation (str) – name of the operation/expectation par (tuple[float]) – parameter values matrix representation. array
ev(A, wires)[source]

Evaluates a one-qubit expectation in the current state.

Parameters: A (array) – $$2\times 2$$ Hermitian matrix corresponding to the expectation wires (Sequence[int]) – target subsystem expectation value $$\expect{A} = \bra{\psi}A\ket{\psi}$$ float
reset()[source]

Reset the device

expand_one(U, wires)[source]

Expand a one-qubit operator into a full system operator.

Parameters: U (array) – $$2\times 2$$ matrix wires (Sequence[int]) – target subsystem $$2^n\times 2^n$$ matrix array
expand_two(U, wires)[source]

Expand a two-qubit operator into a full system operator.

Parameters: U (array) – $$4\times 4$$ matrix wires (Sequence[int]) – two target subsystems (order matters!) $$2^n\times 2^n$$ matrix array
operations

Get the supported set of operations.

Returns: the set of PennyLane operation names the device supports set[str]
expectations

Get the supported set of expectations.

Returns: the set of PennyLane expectation names the device supports set[str]