qml.trotterize¶
- trotterize(qfunc, n=1, order=2, reverse=False)[source]¶
Generates higher order Suzuki-Trotter product formulas from a set of operations defined in a function.
The Suzuki-Trotter product formula provides a method to approximate the matrix exponential of a Hamiltonian expressed as a linear combination of terms which in general do not commute. Consider the Hamiltonian \(H = \Sigma^{N}_{j=0} O_{j}\), the product formula is constructed using symmetrized products of the terms in the Hamiltonian. The symmetrized products of order \(m \in [1, 2, 4, ..., 2k]\) with \(k \in \mathbb{N}\) are given by:
\[\begin{split}\begin{align} S_{1}(t) &= \Pi_{j=0}^{N} \ e^{i t O_{j}} \\ S_{2}(t) &= \Pi_{j=0}^{N} \ e^{i \frac{t}{2} O_{j}} \cdot \Pi_{j=N}^{0} \ e^{i \frac{t}{2} O_{j}} \\ &\vdots \\ S_{m}(t) &= S_{m-2}(p_{m}t)^{2} \cdot S_{m-2}((1-4p_{m})t) \cdot S_{m-2}(p_{m}t)^{2}, \end{align}\end{split}\]where the coefficient is \(p_{m} = 1 / (4 - \sqrt[m - 1]{4})\). The \(m\)-step Suzuki-Trotter approximation is then defined as:
\[e^{iHt} \approx \left [S_{m}(t / n) \right ]^{n}.\]For more details see J. Math. Phys. 32, 400 (1991).
Suppose we have direct access to the operators which represent the exponentiated terms of a Hamiltonian:
\[\{ \hat{U}_{j} = e^{i t O_{j}}, j \in [1, N] \}.\]Given a quantum circuit which uses these \(\hat{U}_{j}\) operators to represent the first order expansion \(S_{1}(t)\), this function expands it to any higher order Suzuki-Trotter product.
Warning
trotterize()
requires theqfunc
argument to be a function with a specific call signature. The first argument of theqfunc
function should be a time parameter which will be modified according to the Suzuki-Trotter product formula. The wires required by the circuit should be either the last positional argument or the first keyword argument:qfunc((time, arg1, ..., arg_n, wires=[...], kwarg_1, ..., kwarg_n))
- Parameters
qfunc (Callable) – the first-order expansion given as a callable function which queues operations
n (int) – an integer representing the number of Trotter steps to perform
order (int) – an integer (\(m\)) representing the order of the approximation (must be 1 or even)
reverse (bool) – if true, reverse the order of the operations queued by
qfunc
name (str) – an optional name for the instance
- Returns
- a function with the same signature as
qfunc
, when called it queues an instance of
- a function with the same signature as
- Return type
(Callable)
Example
def first_order_expansion(time, theta, phi, wires, flip=False): "This is the first order expansion (U_1)." qml.RX(time*theta, wires[0]) qml.RY(time*phi, wires[1]) if flip: qml.CNOT(wires=wires[:2]) @qml.qnode(qml.device("default.qubit")) def my_circuit(time, theta, phi, num_trotter_steps): qml.trotterize( first_order_expansion, n=num_trotter_steps, order=2, )(time, theta, phi, wires=['a', 'b'], flip=True) return qml.state()
We can visualize the circuit to see the Suzuki-Trotter product formula being applied:
>>> time = 0.1 >>> theta, phi = (0.12, -3.45) >>> >>> print(qml.draw(my_circuit, level="device")(time, theta, phi, num_trotter_steps=1)) a: ──RX(0.01)──╭●─╭●──RX(0.01)──┤ State b: ──RY(-0.17)─╰X─╰X──RY(-0.17)─┤ State >>> >>> print(qml.draw(my_circuit, level="device")(time, theta, phi, num_trotter_steps=3)) a: ──RX(0.00)──╭●─╭●──RX(0.00)───RX(0.00)──╭●─╭●──RX(0.00)───RX(0.00)──╭●─╭●──RX(0.00)──┤ State b: ──RY(-0.06)─╰X─╰X──RY(-0.06)──RY(-0.06)─╰X─╰X──RY(-0.06)──RY(-0.06)─╰X─╰X──RY(-0.06)─┤ State