# qcircuits.operators module¶

The operators module contains the Operator class, instances of which represent Operators on vector spaces for multi-qubit systems, and factory functions for creating specific operators.

Each of the factory functions (but not the Operator class) is aliased at the top-level module, so that, for example, one can call qcircuits.Hadamard() instead of qcircuits.state.Hadamard().

qcircuits.operators.CNOT()

Produce the two-qubit CNOT operator, which flips the second bit if the first bit is set. Maps |00⟩ -> |00⟩, |01⟩ -> |01⟩, |10⟩ -> |01⟩, |11⟩ -> |10⟩.

Returns: A rank 4 tensor describing the operator. Operator
qcircuits.operators.ControlledU(U)

Produce a Controlled-U operator, an operator for a d + 1 qubit system where the supplied U is an operator for a d qubit system. If the first bit is set, apply U to the state for the remaining bits.

Parameters: U (Operator) – The operator to be conditionally applied. A tensor whose rank is the rank of U plus 2, describing the operator. Operator
qcircuits.operators.Hadamard(d=1)

Produce the d-qubit Hadamard operator $$H^{\otimes d}$$. Maps: |0⟩ -> $$\frac{1}{\sqrt{2}}$$ (|0⟩+|1⟩) = |+⟩, |1⟩ -> $$\frac{1}{\sqrt{2}}$$ (|0⟩-|1⟩) = |-⟩.

Parameters: d (int) – The number of qubits described by the state vector on which the produced operator will act. A rank 2d tensor describing the operator. Operator
qcircuits.operators.Identity(d=1)

Produce the d-qubit identity operator $$I^{\otimes d}$$.

Parameters: d (int) – The number of qubits described by the state vector on which the produced operator will act. A rank 2d tensor describing the operator. Operator
class qcircuits.operators.Operator(tensor)

A container class for a tensor representing an operator on a vector space for a quantum system, and associated methods.

Parameters: tensor (numpy complex128 multidimensional array) – The tensor representing the operator.
__call__(arg, qubit_indices=None)

Applies this Operator to another Operator, as in operator composition A(B), or to a State, as in A(v). This means that if two operators A and B will be applied to state v in sequence, either B(A(v)) or (B(A))(v) are valid.

This operator may be applied to state vectors of higher rank if the qubits to which it is to be applied are specified in the qubit_indices parameter.

Parameters: arg (State or Operator) – The state that the operator is applied to, or the operator with which the operator is composed. qubit_indices (list of int) – If the operator is applied to a state vector for a larger quantum system, the user must supply a list of the indices of the qubits to which the operator is to be applied. These can also be used to apply the operator to the qubits in arbitrary order. The state vector or operator resulting in applying the operator to the argument.
adj

Get the adjoint/inverse of this operator, $$A^{\dagger} = (A^{*})^{T}$$. As the operator is unitary, $$A A^{\dagger} = I$$.

qcircuits.operators.PauliX(d=1)

Produce the d-qubit Pauli X operator $$X^{\otimes d}$$, or not gate. Maps: |0⟩ -> |1⟩, |1⟩ -> |0⟩.

Parameters: d (int) – The number of qubits described by the state vector on which the produced operator will act. A rank 2d tensor describing the operator. Operator
qcircuits.operators.PauliY(d=1)

Produce the d-qubit Pauli Y operator $$Y^{\otimes d}$$. Maps: |0⟩ -> i |1⟩, |1⟩ -> -i |0⟩.

Parameters: d (int) – The number of qubits described by the state vector on which the produced operator will act. A rank 2d tensor describing the operator. Operator
qcircuits.operators.PauliZ(d=1)

Produce the d-qubit Pauli Z operator $$Z^{\otimes d}$$, or phase inverter. Maps: |0⟩ -> |0⟩, |1⟩ -> -|1⟩.

Parameters: d (int) – The number of qubits described by the state vector on which the produced operator will act. A rank 2d tensor describing the operator. Operator
qcircuits.operators.Phase(phi=1.5707963267948966, d=1)

Produce the d-qubit Phase change operator. Maps: |0⟩ -> |0⟩, |1⟩ -> $$e^{i\phi}$$ |1⟩.

Parameters: d (int) – The number of qubits described by the state vector on which the produced operator will act. A rank 2d tensor describing the operator. Operator
qcircuits.operators.SqrtNot(d=1)

Produce the d-qubit operator that is the square root of the d-qubit NOT or PauliX() operator, i.e., $$\sqrt{\texttt{NOT}}(\sqrt{\texttt{NOT}}) = X$$.

Parameters: d (int) – The number of qubits described by the state vector on which the produced operator will act. A rank 2d tensor describing the operator. Operator
qcircuits.operators.SqrtSwap()

Produce the two-qubit operator that is the square root of the Swap() operator, i.e., $$\sqrt{\texttt{SWAP}}(\sqrt{\texttt{SWAP}}) = \texttt{SWAP}$$.

Returns: A rank 4 tensor describing the operator. Operator
qcircuits.operators.Swap()

Produce the two-qubit SWAP operator, which swaps two bits. Maps |00⟩ -> |00⟩, |01⟩ -> |10⟩, |10⟩ -> |01⟩, |11⟩ -> |11⟩.

Returns: A rank 4 tensor describing the operator. Operator
qcircuits.operators.Toffoli()

Produce the three-qubit Toffoli operator, which flips the third bit if the first two bits are set. Maps |110⟩ -> |111⟩, |111⟩ -> |110⟩, and otherwise acts as the identity.

Returns: A rank 6 tensor describing the operator. Operator
qcircuits.operators.U_f(f, d)

Produce a U_f operator, an operator for a d qubit system that flips the last bit based on the outcome of a supplied boolean function $$f: [0, 1]^{d-1} \to [0, 1]$$ applied to the first d - 1 bits.

Parameters: f (function) – The boolean function used to conditionally flip the last bit. A rank 2d tensor describing the operator. Operator