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¶
The controlledNOT operator 

The controlledRot operator 

The controlledRX operator 

The controlledRY operator 

The controlledRZ operator 

The controlledswap operator 

The controlledZ operator 

The Hadamard operator 

The Pauli X operator 

The Pauli Y operator 

The Pauli Z operator 

Arbitrary single qubit local phase shift 

Apply an arbitrary fixed unitary matrix. 

Arbitrary single qubit rotation 

The single qubit X rotation 

The single qubit Y rotation 

The single qubit Z rotation 

The singlequbit phase gate 

The swap operator 

The singlequbit T gate 
Qubit state preparation¶
Prepares a single computational basis state. 

Prepare subsystems using the given ket vector in the computational basis. 
Continuousvariable (CV) operations¶
CV Gates¶
Beamsplitter interaction. 

Controlled addition operation. 

Controlled phase operation. 

CrossKerr interaction. 

Cubic phase shift. 

Phase space displacement. 

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

Kerr interaction. 

Quadratic phase shift. 

Phase space rotation. 

Phase space squeezing. 

Phase space twomode squeezing. 
CV state preparation¶
Prepares a cat state. 

Prepares a coherent state. 

Prepares a displaced squeezed vacuum state. 

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

Prepares a single Fock state. 

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

Prepare subsystems in a given Gaussian state. 

Prepares a squeezed vacuum state. 

Prepares a thermal state. 
CV observables¶
The number state observable \(\ket{n}\bra{n}\). 

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

The tensor product of the 

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

An arbitrary secondorder polynomial observable. 

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

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