qcircuits.operators module¶
The operators module contains the Operator class, instances of which represent Operators on vector spaces for multiqubit systems, and factory functions for creating specific operators.
Each of the factory functions (but not the Operator class) is aliased
at the toplevel module, so that, for example, one can call
qcircuits.Hadamard()
instead of qcircuits.state.Hadamard()
.

qcircuits.operators.
CNOT
()¶ Produce the twoqubit 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. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,Toffoli()
,SqrtNot()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

qcircuits.operators.
ControlledU
(U)¶ Produce a ControlledU 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. Returns: A tensor whose rank is the rank of U plus 2, describing the operator. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,U_f()

qcircuits.operators.
Hadamard
(d=1)¶ Produce the dqubit 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. Returns: A rank 2d tensor describing the operator. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

qcircuits.operators.
Identity
(d=1)¶ Produce the dqubit identity operator \(I^{\otimes d}\).
Parameters: d (int) – The number of qubits described by the state vector on which the produced operator will act. Returns: A rank 2d tensor describing the operator. Return type: Operator See also
PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

class
qcircuits.operators.
Operator
(tensor)¶ Bases:
qcircuits.tensors.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.
Returns: The state vector or operator resulting in applying the operator to the argument.
Return type:


qcircuits.operators.
PauliX
(d=1)¶ Produce the dqubit 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. Returns: A rank 2d tensor describing the operator. Return type: Operator See also
Identity()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

qcircuits.operators.
PauliY
(d=1)¶ Produce the dqubit 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. Returns: A rank 2d tensor describing the operator. Return type: Operator See also
Identity()
,PauliX()
,PauliZ()
,Hadamard()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

qcircuits.operators.
PauliZ
(d=1)¶ Produce the dqubit 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. Returns: A rank 2d tensor describing the operator. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,Hadamard()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

qcircuits.operators.
Phase
(phi=1.5707963267948966, d=1)¶ Produce the dqubit 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. Returns: A rank 2d tensor describing the operator. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

qcircuits.operators.
SqrtNot
(d=1)¶ Produce the dqubit operator that is the square root of the dqubit 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. Returns: A rank 2d tensor describing the operator. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

qcircuits.operators.
SqrtSwap
()¶ Produce the twoqubit 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. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,ControlledU()
,U_f()

qcircuits.operators.
Swap
()¶ Produce the twoqubit SWAP operator, which swaps two bits. Maps 00⟩ > 00⟩, 01⟩ > 10⟩, 10⟩ > 01⟩, 11⟩ > 11⟩.
Returns: A rank 4 tensor describing the operator. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,SqrtSwap()
,ControlledU()
,U_f()

qcircuits.operators.
Toffoli
()¶ Produce the threequbit 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. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,CNOT()
,SqrtNot()
,Swap()
,SqrtSwap()
,ControlledU()
,U_f()

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]^{d1} \to [0, 1]\) applied to the first d  1 bits.
Parameters: f (function) – The boolean function used to conditionally flip the last bit. Returns: A rank 2d tensor describing the operator. Return type: Operator See also
Identity()
,PauliX()
,PauliY()
,PauliZ()
,Hadamard()
,Phase()
,SqrtNot()
,CNOT()
,Toffoli()
,Swap()
,SqrtSwap()
,ControlledU()