Quantum operations

PennyLane supports a wide variety of quantum operations—such as gates, state preparations and measurements. These operations can be used exclusively in quantum functions, like shown in the following example:

import pennylane as qml

def my_quantum_function(x, y):
    qml.RZ(x, wires=0)
    qml.CNOT(wires=[0,1])
    qml.RY(y, wires=1)
    qml.T(wires=0).inv()
    return qml.expval(qml.PauliZ(1))

This quantum function uses the RZ, CNOT, RY gates as well as the PauliZ observable.

Note that PennyLane supports inverting quantum opperations via the Op(param, wires).inv() method. Additionally, PennyLane provides a function qml.inv that can be used to invert sequences of operations and Templates.

Below is a list of all quantum operations supported by PennyLane.

Qubit operations

Qubit gates

CNOT

The controlled-NOT operator

CRot

The controlled-Rot operator

CRX

The controlled-RX operator

CRY

The controlled-RY operator

CRZ

The controlled-RZ operator

CSWAP

The controlled-swap operator

CZ

The controlled-Z operator

Hadamard

The Hadamard operator

PauliX

The Pauli X operator

PauliY

The Pauli Y operator

PauliZ

The Pauli Z operator

PhaseShift

Arbitrary single qubit local phase shift

QubitUnitary

Apply an arbitrary fixed unitary matrix.

Rot

Arbitrary single qubit rotation

RX

The single qubit X rotation

RY

The single qubit Y rotation

RZ

The single qubit Z rotation

S

The single-qubit phase gate

SWAP

The swap operator

T

The single-qubit T gate

Qubit state preparation

BasisState

Prepares a single computational basis state.

QubitStateVector

Prepare subsystems using the given ket vector in the computational basis.

Qubit observables

Hadamard

The Hadamard operator

Hermitian

An arbitrary Hermitian observable.

PauliX

The Pauli X operator

PauliY

The Pauli Y operator

PauliZ

The Pauli Z operator

Continuous-variable (CV) operations

CV Gates

Beamsplitter

Beamsplitter interaction.

ControlledAddition

Controlled addition operation.

ControlledPhase

Controlled phase operation.

CrossKerr

Cross-Kerr interaction.

CubicPhase

Cubic phase shift.

Displacement

Phase space displacement.

Interferometer

A linear interferometer transforming the bosonic operators according to the unitary matrix \(U\).

Kerr

Kerr interaction.

QuadraticPhase

Quadratic phase shift.

Rotation

Phase space rotation.

Squeezing

Phase space squeezing.

TwoModeSqueezing

Phase space two-mode squeezing.

CV state preparation

CatState

Prepares a cat state.

CoherentState

Prepares a coherent state.

DisplacedSqueezedState

Prepares a displaced squeezed vacuum state.

FockDensityMatrix

Prepare subsystems using the given density matrix in the Fock basis.

FockState

Prepares a single Fock state.

FockStateVector

Prepare subsystems using the given ket vector in the Fock basis.

GaussianState

Prepare subsystems in a given Gaussian state.

SqueezedState

Prepares a squeezed vacuum state.

ThermalState

Prepares a thermal state.

CV observables

FockStateProjector

The number state observable \(\ket{n}\bra{n}\).

NumberOperator

The photon number observable \(\langle \hat{n}\rangle\).

TensorN

The tensor product of the NumberOperator acting on different wires.

P

The momentum quadrature observable \(\hat{p}\).

PolyXP

An arbitrary second-order polynomial observable.

QuadOperator

The generalized quadrature observable \(\x_\phi = \x cos\phi+\p\sin\phi\).

X

The position quadrature observable \(\hat{x}\).

Shared operations

The only operation shared by both qubit and continouous-variable architectures is the Identity.

Identity

The identity observable \(\I\).