QubitOperator#
- class QubitOperator(terms_dict={})[source]#
This class provides an efficient implementation of QubitOperators, i.e. Operators, that act on a qubit space \((\mathbb{C}^2)^{\otimes n}\). Supported are operators of the following form:
\[O=\sum\limits_{j}\alpha_j O_j \]where \(O_j=\bigotimes_i m_i^j\) is a product of the following operators:
Operator
Ket-Bra Realization
Description
\(X\)
\(\ket{0}\bra{1} + \ket{1}\bra{0}\)
Pauli-X operator (bit flip)
\(Y\)
\(-i\ket{0}\bra{1} + i\ket{1}\bra{0}\)
Pauli-Y operator (bit flip with phase)
\(Z\)
\(\ket{0}\bra{0} - \ket{1}\bra{1}\)
Pauli-Z operator (phase flip)
\(A\)
\(\ket{0}\bra{1}\)
Annihilation operator
\(C\)
\(\ket{1}\bra{0}\)
Creation operator
\(P_0\)
\(\ket{0}\bra{0}\)
Projector onto the \(\ket{0}\) state
\(P_1\)
\(\ket{1}\bra{1}\)
Projector onto the \(\ket{1}\) state
\(I\)
\(\ket{1}\bra{1} + \ket{0}\bra{0}\)
Identity operator
If you already have some experience you might wonder why to include the non-Pauli operators - after all they can be represented as a linear combination of
X
,Y
andZ
.\[\begin{split}\begin{align} A_0 C_1 &= (X_0 - i Y_0)(X_1 + Y_1)/4 \\ & = (X_0X_1 + X_0Y_1 - Y_0X_1 + Y_0Y_1)/4 \end{align}\end{split}\]Recently a much more efficient method of simulating
A
andC
has been proposed by Kornell and Selinger, which avoids decomposing these Operators into Paulis strings but instead simulates\[H = A_0C_1 + h.c. \]within a single step. This idea is deeply integrated into the Operators module of Qrisp. For an example circuit see below.
Examples
A QubitOperator can be specified conveniently in terms of arithmetic combinations of the mentioned operators:
from qrisp.operators.qubit import X,Y,Z,A,C,P0,P1 H = 1+2*X(0)+3*X(0)*Y(1)*A(2)+C(4)*P1(0) H
Yields \(1 + P^1_0C_4 + 2X_0 + 3X_0Y_1A_2\).
We create a QubitOperator and perform Hamiltonian simulation via
trotterization
:from sympy import Symbol from qrisp.operators import A,C,Z,Y from qrisp import QuantumVariable O = A(0)*C(1)*Z(2)*A(3) + Y(3) U = O.trotterization() qv = QuantumVariable(4) t = Symbol("t") U(qv, t = t)
>>> print(qv.qs) QuantumCircuit: --------------- ┌───┐ » qv.0: ┤ X ├────────────o──────────────────────────────────────o────────────» └─┬─┘┌───┐ │ │ ┌───┐» qv.1: ──┼──┤ X ├───────■──────────────────────────────────────■───────┤ X ├» │ └─┬─┘ │ │ └─┬─┘» qv.2: ──┼────┼─────────┼────■────────────────────────────■────┼─────────┼──» │ │ ┌───┐ │ ┌─┴─┐ ┌────────────┐ ┌─┴─┐ │ ┌───┐ │ » qv.3: ──■────■──┤ H ├──┼──┤ X ├──■──┤ Rz(-0.5*t) ├──■──┤ X ├──┼──┤ H ├──■──» └───┘┌─┴─┐└───┘┌─┴─┐├───────────┬┘┌─┴─┐└───┘┌─┴─┐└───┘ » hs_anc.0: ───────────────┤ X ├─────┤ X ├┤ Rz(0.5*t) ├─┤ X ├─────┤ X ├──────────» └───┘ └───┘└───────────┘ └───┘ └───┘ » « ┌───┐ « qv.0: ┤ X ├──────────────────────────── « └─┬─┘ « qv.1: ──┼────────────────────────────── « │ « qv.2: ──┼────────────────────────────── « │ ┌────┐┌────────────┐┌──────┐ « qv.3: ──■──┤ √X ├┤ Rz(-2.0*t) ├┤ √Xdg ├ « └────┘└────────────┘└──────┘ «hs_anc.0: ───────────────────────────────── « Live QuantumVariables: ---------------------- QuantumVariable qv
Call the simulator:
>>> print(qv.get_measurement(subs_dic = {t : 0.5})) {'0000': 0.77015, '0001': 0.22985}
Methods#
Returns an the adjoint operator. |
|
Returns the hermitian part of self. |
|
|
Computes the commutator. |
Calculates the ground state energy (i.e., the minimum eigenvalue) of the operator classically. |
|
|
This method returns the expected value of a Hamiltonian for the state of a quantum argument. |
Returns an equivalent operator, which however only contains Pauli factors. |
|
|