qrisp.operators.qubit.QubitOperator.trotterization#
- QubitOperator.trotterization(method='commuting_qw')[source]#
Returns a function for performing Hamiltonian simulation, i.e., approximately implementing the unitary operator \(e^{itH}\) via Trotterization. Note that this method will always simulate the hermitized operator, i.e.
\[H = (O + O^\dagger)/2\]- Parameters:
- methodstr, optional
The method for grouping the QubitTerms. Available are
commuting
(groups such that all QubitTerms mutually commute) andcommuting_qw
(groups such that all QubitTerms mutually commute qubit-wise). The default iscommuting_qw
.
- Returns:
- Ufunction
A Python function that implements the first order Suzuki-Trotter formula. Given a Hamiltonian \(H=H_1+\dotsb +H_m\) the unitary evolution \(e^{itH}\) is approximated by
\[e^{itH}\approx U_1(t,N)=\left(e^{iH_1t/N}\dotsb e^{iH_mt/N}\right)^N\]This function receives the following arguments:
- qargQuantumVariable
The quantum argument.
- tfloat, optional
The evolution time \(t\). The default is 1.
- stepsint, optional
The number of Trotter steps \(N\). The default is 1.
- iterint, optional
The number of iterations the unitary \(U_1(t,N)\) is applied. The default is 1.
Examples
We simulate a simple QubitOperator.
>>> from sympy import Symbol >>> from qrisp.operators import A,C,Z,Y >>> from qrisp import QuantumVariable >>> O = A(0)*C(1)*Z(2) + Y(3) >>> U = O.trotterization() >>> qv = QuantumVariable(4) >>> t = Symbol("t") >>> U(qv, t = t) >>> print(qv.qs) QuantumCircuit: --------------- ┌───┐ ┌───┐┌───────────┐ ┌───┐ ┌───┐ qv.0: ┤ X ├───────────────────────┤ X ├┤ Rz(0.5*t) ├─┤ X ├──────────┤ X ├ └─┬─┘ ┌───┐ ┌───┐ └─┬─┘├───────────┴┐└─┬─┘┌───┐┌───┐└─┬─┘ qv.1: ──■───────┤ H ├──────┤ X ├────■──┤ Rz(-0.5*t) ├──■──┤ X ├┤ H ├──■── └───┘ └─┬─┘ └────────────┘ └─┬─┘└───┘ qv.2: ───────────────────────■──────────────────────────────■──────────── ┌────┐┌────────────┐┌──────┐ qv.3: ┤ √X ├┤ Rz(-2.0*t) ├┤ √Xdg ├─────────────────────────────────────── └────┘└────────────┘└──────┘ Live QuantumVariables: ---------------------- QuantumVariable qv
Execute a simulation:
>>> print(qv.get_measurement(subs_dic = {t : 0.5})) {'0000': 0.77015, '0001': 0.22985}