# Quantum operations¶

PennyLane supports a wide variety of quantum operations—such as gates, noisy channels, 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()
qml.AmplitudeDamping(0.1, wires=0)
return qml.expval(qml.PauliZ(1))


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

Note that PennyLane supports inverting quantum operations 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¶

### Non-parametric Ops¶

 Hadamard The Hadamard operator PauliX The Pauli X operator PauliY The Pauli Y operator PauliZ The Pauli Z operator S The single-qubit phase gate T The single-qubit T gate SX The single-qubit Square-Root X operator. CNOT The controlled-NOT operator CZ The controlled-Z operator CY The controlled-Y operator SWAP The swap operator ISWAP The i-swap operator SISWAP The square root of i-swap operator. SQISW alias of pennylane.ops.qubit.non_parametric_ops.SISWAP CSWAP The controlled-swap operator Toffoli Toffoli (controlled-controlled-X) gate. MultiControlledX Apply a Pauli X gate controlled on an arbitrary computational basis state.

### Parametric Ops¶

 Rot Arbitrary single qubit rotation RX The single qubit X rotation RY The single qubit Y rotation RZ The single qubit Z rotation MultiRZ Arbitrary multi Z rotation. PauliRot Arbitrary Pauli word rotation. PhaseShift Arbitrary single qubit local phase shift ControlledPhaseShift A qubit controlled phase shift. CPhase alias of pennylane.ops.qubit.parametric_ops.ControlledPhaseShift CRX The controlled-RX operator CRY The controlled-RY operator CRZ The controlled-RZ operator CRot The controlled-Rot operator U1 U1 gate. U2 U2 gate. U3 Arbitrary single qubit unitary. IsingXX Ising XX coupling gate IsingYY Ising YY coupling gate IsingZZ Ising ZZ coupling gate

### Quantum Chemistry Ops¶

 SingleExcitation Single excitation rotation. SingleExcitationPlus Single excitation rotation with positive phase-shift outside the rotation subspace. SingleExcitationMinus Single excitation rotation with negative phase-shift outside the rotation subspace. DoubleExcitation Double excitation rotation. DoubleExcitationPlus Double excitation rotation with positive phase-shift outside the rotation subspace. DoubleExcitationMinus Double excitation rotation with negative phase-shift outside the rotation subspace.

### Matrix Ops¶

 QubitUnitary Apply an arbitrary fixed unitary matrix. ControlledQubitUnitary Apply an arbitrary fixed unitary to wires with control from the control_wires. DiagonalQubitUnitary Apply an arbitrary fixed diagonal unitary matrix.

### Arithmetic Ops¶

 QubitCarry Apply the QubitCarry operation to four input wires. QubitSum Apply a QubitSum operation on three input wires.

### Qubit state preparation¶

 BasisState Prepares a single computational basis state. QubitStateVector Prepare subsystems using the given ket vector in the computational basis.

### Noisy channels¶

 AmplitudeDamping Single-qubit amplitude damping error channel. GeneralizedAmplitudeDamping Single-qubit generalized amplitude damping error channel. PhaseDamping Single-qubit phase damping error channel. DepolarizingChannel Single-qubit symmetrically depolarizing error channel. BitFlip Single-qubit bit flip (Pauli $$X$$) error channel. PhaseFlip Single-qubit bit flip (Pauli $$Z$$) error channel. ResetError Single-qubit Reset error channel. QubitChannel Apply an arbitrary fixed quantum channel.

### Qubit observables¶

 Hadamard The Hadamard operator Hermitian An arbitrary Hermitian observable. Identity The identity observable $$\I$$. PauliX The Pauli X operator PauliY The Pauli Y operator PauliZ The Pauli Z operator Projector Observable corresponding to the computational basis state projector $$P=\ket{i}\bra{i}$$. Hamiltonian Operator representing a Hamiltonian. SparseHamiltonian A Hamiltonian represented directly as a sparse matrix in coordinate list (COO) format.

### Grouping Pauli words¶

Grouping Pauli words can be used for the optimizing the measurement of qubit Hamiltonians. Along with groups of observables, post-measurement rotations can also be obtained using optimize_measurements():

>>> obs = [qml.PauliY(0), qml.PauliX(0) @ qml.PauliX(1), qml.PauliZ(1)]
>>> coeffs = [1.43, 4.21, 0.97]
>>> post_rotations, diagonalized_groupings, grouped_coeffs = optimize_measurements(obs, coeffs)
>>> post_rotations
[[RY(-1.5707963267948966, wires=), RY(-1.5707963267948966, wires=)],
[RX(1.5707963267948966, wires=)]]


The post-measurement rotations can be used to diagonalize the partitions of observables found.

For further details on measurement optimization, grouping observables through solving the minimum clique cover problem, and auxiliary functions, refer to the qml.grouping subpackage.

## 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}$$. Identity The identity observable $$\I$$. 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}$$.