Quantum operatorsÂķ
PennyLane supports a wide variety of quantum operatorsâsuch as gates, noisy channels, state preparations and measurements. These operators can be used in quantum functions, like shown in the following example:
import pennylane as qp
def my_quantum_function(x, y):
qp.RZ(x, wires=0)
qp.CNOT(wires=[0,1])
qp.RY(y, wires=1)
qp.AmplitudeDamping(0.1, wires=0)
return qp.expval(qp.PauliZ(1))
This quantum function uses the RZ,
CNOT,
RY gates, the
AmplitudeDamping
noisy channel as well as the
PauliZ observable.
Functions applied to operators extract information (such as the matrix representation) or transform operators (like turning a gate into a controlled gate).
PennyLane supports the following operators and operator functions:
Operator functionsÂķ
Various functions and transforms are available for manipulating operators, and extracting information. These can be broken down into two main categories:
Operator to Operator functionsÂķ
|
Create the adjoint of an Operator or a function that applies the adjoint of the provided function. |
|
Create a method that applies a controlled version of the provided op. |
|
Quantum-compatible if-else conditionals --- condition quantum operations on parameters such as the results of mid-circuit qubit measurements. |
|
Take the exponential of an Operator times a coefficient. |
|
Construct an operator which is the sum of the given operators. |
|
Raise an Operator to a power. |
|
Construct an operator which represents the generalized product of the operators provided. |
|
Construct an operator which is the scalar product of the given scalar and operator provided. |
|
Returns the generator of an operation. |
|
Changes the wires of an operator, tape, qnode or quantum function according to the given wire map. |
|
Returns the dot product between the |
|
This method is dispatched and its functionality depends on the type of the input |
|
Simplifies an operator, tape, qnode or quantum function by reducing its arithmetic depth or number of rotation parameters. |
These operator functions act on operators to produce new operators.
>>> op = qp.prod(qp.PauliX(0), qp.PauliZ(1))
>>> op = qp.sum(qp.Hadamard(0), op)
>>> op = qp.s_prod(1.2, op)
>>> op
1.2 * (H(0) + X(0) @ Z(1))
Operator to Other functionsÂķ
|
The dense matrix representation of an operation or quantum circuit. |
|
The eigenvalues of one or more operations. |
|
Check if two operations are commuting using a lookup table. |
|
Check if the operation is hermitian. |
|
Check if the operation is unitary. |
|
Performs the iterative quantum phase estimation circuit. |
These operator functions act on operators and return other data types. All operator functions can be used on instantiated operators.
>>> op = qp.RX(0.54, wires=0)
>>> qp.matrix(op)
array([[0.9637709+0.j , 0. -0.26673144j],
[0. -0.26673144j, 0.9637709+0.j ]])
Some operator functions can also be used in a functional form:
>>> x = torch.tensor(0.6, requires_grad=True)
>>> matrix_fn = qp.matrix(qp.RX)
>>> matrix_fn(x, wires=0)
tensor([[0.9553+0.0000j, 0.0000-0.2955j],
[0.0000-0.2955j, 0.9553+0.0000j]], grad_fn=<StackBackward0>)
In the functional form, they are usually differentiable with respect to gate arguments:
>>> loss = torch.real(torch.trace(matrix_fn(x, wires=0)))
>>> loss.backward()
>>> x.grad
tensor(-0.2955)
Some operator transforms can also act on multiple operators, by passing quantum functions, QNodes or tapes:
>>> def circuit(theta):
... qp.RX(theta, wires=1)
... qp.Z(wires=0)
>>> qp.matrix(circuit, wire_order=[0,1])(np.pi / 4)
array([[ 0.92387953+0.j , 0. -0.38268343j,
0. +0.j , 0. +0.j ],
[ 0. -0.38268343j, 0.92387953+0.j ,
0. +0.j , 0. +0.j ],
[ 0. +0.j , 0. +0.j ,
-0.92387953+0.j , 0. +0.38268343j],
[ 0. +0.j , 0. +0.j ,
0. +0.38268343j, -0.92387953+0.j ]])
Matrix to Operator functionsÂķ
|
Decomposes a Hermitian matrix into a linear combination of Pauli operators. |
|
Implements the Quantum Singular Value Transformation (QSVT) for a matrix or Hamiltonian |
These functions take a matrix and return an associated native PennyLane operator. For example:
>>> mat = np.array([[1, 1], [1, -1]])
>>> h = qp.pauli_decompose(mat)
>>> type(h)
<class 'pennylane.ops.op_math.linear_combination.LinearCombination'>
>>> print(h)
1.0 * X(0) + 1.0 * Z(0)
Qubit operatorsÂķ
Non-parametrized gatesÂķ
The Identity operator The Hadamard operator The Pauli X operator The Pauli Y operator The Pauli Z operator The single-qubit phase gate The single-qubit T gate The single-qubit Square-Root X operator. The controlled-NOT operator The controlled-Z operator The controlled-Y operator The controlled-Hadamard operator The swap operator The i-swap operator An echoed RZX(\(\pi/2\)) gate. The square root of i-swap operator. alias of The controlled-swap operator Toffoli (controlled-controlled-X) gate. Apply a The Barrier operator, used to separate the compilation process into blocks or as a visual tool. The wire cut operation, used to manually mark locations for wire cuts.
SISWAP
PauliX gate controlled on an arbitrary computational basis state.
Parametrized gatesÂķ
Arbitrary single qubit rotation The single qubit X rotation The single qubit Y rotation The single qubit Z rotation Arbitrary multi Z rotation. Arbitrary Pauli word rotation. Arbitrary single qubit local phase shift A qubit controlled phase shift. alias of A projector-controlled phase gate. A qubit controlled phase shift. A qubit controlled phase shift. A qubit controlled phase shift. The controlled-RX operator The controlled-RY operator The controlled-RZ operator The controlled-Rot operator U1 gate. U2 gate. Arbitrary single qubit unitary. Ising XX coupling gate Ising (XX + YY) coupling gate Ising YY coupling gate Ising ZZ coupling gate Phase SWAP gate A global phase operation that multiplies all components of the state by \(e^{-i \phi}\).
ControlledPhaseShift
Quantum chemistry gatesÂķ
Single excitation rotation. Single excitation rotation with positive phase-shift outside the rotation subspace. Single excitation rotation with negative phase-shift outside the rotation subspace. Double excitation rotation. Double excitation rotation with positive phase-shift outside the rotation subspace. Double excitation rotation with negative phase-shift outside the rotation subspace. Spin-adapted spatial orbital rotation. Fermionic SWAP rotation.
Electronic Hamiltonians built independently using
OpenFermion tools can be readily converted to a
PennyLane observable using the import_operator() function.
Gates constructed from a matrixÂķ
Apply an arbitrary unitary matrix with a dimension that is a power of two. Apply an arbitrary fixed unitary matrix Apply an arbitrary diagonal unitary matrix with a dimension that is a power of two. Gate from the group \(SU(N)\) with \(N=2^n\) for \(n\) qubits. Construct a unitary \(U(A)\) such that an arbitrary matrix \(A\) is encoded in the top-left block.
U to wires.
Gates performing arithmeticsÂķ
Apply the Apply a Apply a controlled Pauli X gate using integer comparison as the condition.
QubitCarry operation to four input wires.
QubitSum operation on three input wires.
State preparationÂķ
Prepares a single computational basis state. Prepare subsystems using a state vector in the computational basis. Prepare subsystems using the given density matrix.
Noisy channelsÂķ
Single-qubit amplitude damping error channel. Single-qubit generalized amplitude damping error channel. Single-qubit phase damping error channel. Single-qubit symmetrically depolarizing error channel. Single-qubit bit flip (Pauli \(X\)) error channel. Single-qubit bit flip (Pauli \(Z\)) error channel. Single-qubit Reset error channel. Pauli operator error channel for an arbitrary number of qubits. Apply an arbitrary fixed quantum channel. Thermal relaxation error channel.
ObservablesÂķ
The Hadamard operator An arbitrary Hermitian observable. The Identity operator The Pauli X operator The Pauli Y operator The Pauli Z operator Observable corresponding to the state projector \(P=\ket{\phi}\bra{\phi}\). alias of A Hamiltonian represented directly as a sparse matrix in Compressed Sparse Row (CSR) format.
LinearCombination
Continuous-Variable (CV) operatorsÂķ
If you would like to learn more about the CV model of quantum computing, check out the quantum photonics page of the Strawberry Fields documentation.
CV gatesÂķ
The Identity operator Beamsplitter interaction. Controlled addition operation. Controlled phase operation. Cross-Kerr 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 two-mode 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 Identity operator The photon number observable \(\langle \hat{n}\rangle\). The tensor product of the The momentum quadrature observable \(\hat{p}\). An arbitrary second-order polynomial observable. The generalized quadrature observable \(\x_\phi = \x cos\phi+\p\sin\phi\). The position quadrature observable \(\hat{x}\).
NumberOperator acting on different wires.
Qutrit operatorsÂķ
Qutrit non-parametrized gatesÂķ
Qutrit gates constructed from a matrixÂķ
Apply an arbitrary, fixed unitary matrix. Apply an arbitrary fixed unitary to
wires with control from the control_wires.
Qutrit parametrized gatesÂķ
Qutrit State preparationÂķ
Prepares a single computational basis state for a qutrit system.
Qutrit noisy channelsÂķ
Single-qutrit symmetrically depolarizing error channel. Single-qutrit amplitude damping error channel. Single-qutrit trit flip error channel, used for applying "bit flips" on each qutrit subspace. Apply an arbitrary fixed qutrit channel.
Qutrit ObservablesÂķ
An arbitrary Hermitian observable for qutrits. The Gell-Mann observables for qutrits
Pulse-level operatorsÂķ
If you would like to learn more about the implementation of pulse-level control in PennyLane, see the
pulse module documentation.
Pulse operatorÂķ
Parametrized evolution gate, created by passing a Callable object holding the information representing a parametrized Hamiltonian.
ParametrizedHamiltonian to the evolve() function