qml

Module: qml

This module allows the direct import of all basic functions and classes of PennyLane.

As a convention, pennylane is imported via:

import pennylane as qml

The top-level module contains the following sub-modules:

  • init - This module contains functions that generate initial parameters, for example to use in templates.
  • templates -This module provides a growing library of templates of common variational circuit architectures that can be used to easily build, evaluate, and train quantum nodes.

About

about() Prints the information for pennylane installation.
version() Returns the PennyLane version number.

Configuration

Configuration(name) Configuration class.

Device

Device([wires, shots]) Abstract base class for PennyLane devices.
device(name[, wires]) Load a plugin Device and return the instance.

Gradients

grad(func, argnum) Returns the gradient as a callable function of (functions of) QNodes.
jacobian(func, argnum) Returns the Jacobian as a callable function of vector-valued (functions of) QNodes.

Measurements

expval(op) Expectation value of the supplied observable.
sample(op) Sample from the supplied observable, with the number of shots determined from the dev.shots attribute of the corresponding device.
var(op) Variance of the supplied observable.

Operations base class

CVObservable(*args[, wires, do_queue]) Base class for continuous-variable observables.
CVOperation(*args[, wires, do_queue]) Base class for continuous-variable quantum operations.
Observable(*args[, wires, do_queue]) Base class for observables supported by a device.
Operation(*args[, wires, do_queue]) Base class for quantum operations supported by a device.

Operations - CV

Beamsplitter(theta, phi, wires) Beamsplitter interaction.
CatState(a, phi, p, wires) Prepares a cat state.
CoherentState(a, phi, wires) Prepares a coherent state.
ControlledAddition(s, wires) Controlled addition operation.
ControlledPhase(s, wires) Controlled phase operation.
CrossKerr(kappa, wires) Cross-Kerr interaction.
CubicPhase(gamma, wires) Cubic phase shift.
DisplacedSqueezedState(a, phi_a, r, phi_r, wires) Prepares a displaced squeezed vacuum state.
Displacement(a, phi, wires) Phase space displacement.
FockDensityMatrix(state, wires) Prepare subsystems using the given density matrix in the Fock basis.
FockState(n, wires) Prepares a single Fock state.
FockStateProjector(n, wires) The number state observable \(\ket{n}\bra{n}\).
FockStateVector(state, wires) Prepare subsystems using the given ket vector in the Fock basis.
GaussianState(r, V, wires) Prepare subsystems in a given Gaussian state.
Interferometer(U, wires) A linear interferometer transforming the bosonic operators according to the unitary matrix \(U\).
Kerr(kappa, wires) Kerr interaction.
NumberOperator(wires) The photon number observable \(\langle \hat{n}\rangle\).
P(wires) The momentum quadrature observable \(\hat{p}\).
PolyXP(q, wires) An arbitrary second-order polynomial observable.
QuadOperator(phi, wires) The generalized quadrature observable \(\x_\phi = \x cos\phi+\p\sin\phi\).
QuadraticPhase(s, wires) Quadratic phase shift.
Rotation(phi, wires) Phase space rotation.
SqueezedState(r, phi, wires) Prepares a squeezed vacuum state.
Squeezing(r, phi, wires) Phase space squeezing.
ThermalState(nbar, wires) Prepares a thermal state.
TwoModeSqueezing(r, phi, wires) Phase space two-mode squeezing.
X(wires) The position quadrature observable \(\hat{x}\).

Operations - Qubits

BasisState(n, wires) Prepares a single computational basis state.
CNOT(wires) The controlled-NOT operator
CRot(phi, theta, omega, wires) The controlled-Rot operator
CRX(phi, wires) The controlled-RX operator
CRY(phi, wires) The controlled-RY operator
CRZ(phi, wires) The controlled-RZ operator
CSWAP(wires) The controlled-swap operator
CZ(wires) The controlled-Z operator
Hadamard(wires) The Hadamard operator
Hermitian(A, wires) An arbitrary Hermitian observable.
PauliX(wires) The Pauli X operator
PauliY(wires) The Pauli Y operator
PauliZ(wires) The Pauli Z operator
PhaseShift(phi, wires) Arbitrary single qubit local phase shift
QubitStateVector(state, wires) Prepare subsystems using the given ket vector in the computational basis.
QubitUnitary(U, wires) Apply an arbitrary fixed unitary matrix.
Rot(phi, theta, omega, wires) Arbitrary single qubit rotation
RX(phi, wires) The single qubit X rotation
RY(phi, wires) The single qubit Y rotation
RZ(phi, wires) The single qubit Z rotation
S(wires) The single-qubit phase gate
SWAP(wires) The swap operator
T(wires) The single-qubit T gate

Operations - Shared

Identity(wires) The identity observable \(\I\).

Optimizers

AdagradOptimizer([stepsize, eps]) Gradient-descent optimizer with past-gradient-dependent learning rate in each dimension.
AdamOptimizer([stepsize, beta1, beta2, eps]) Gradient-descent optimizer with adaptive learning rate, first and second moment.
GradientDescentOptimizer([stepsize]) Basic gradient-descent optimizer.
MomentumOptimizer([stepsize, momentum]) Gradient-descent optimizer with momentum.
NesterovMomentumOptimizer([stepsize, momentum]) Gradient-descent optimizer with Nesterov momentum.
QNGOptimizer([stepsize, diag_approx]) Optimizer with adaptive learning rate, via calculation of the diagonal or block-diagonal approximation to the Fubini-Study metric tensor.
RMSPropOptimizer([stepsize, decay, eps]) Root mean squared propagation optimizer.

QNode

QNode(func, device[, cache]) Quantum node in the hybrid computational graph.
qnode(device[, interface, cache]) QNode decorator.