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=ΣNj=0Oj, the product formula is constructed using symmetrized products of the terms in the Hamiltonian. The symmetrized products of order m∈[1,2,4,...,2k] with k∈N are given by:
S1(t)=ΠNj=0 eitOjS2(t)=ΠNj=0 eit2Oj⋅Π0j=N eit2Oj⋮Sm(t)=Sm−2(pmt)2⋅Sm−2((1−4pm)t)⋅Sm−2(pmt)2,where the coefficient is pm=1/(4−m−1√4). The m-step Suzuki-Trotter approximation is then defined as:
eiHt≈[Sm(t/n)]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:
{ˆUj=eitOj,j∈[1,N]}.Given a quantum circuit which uses these ˆUj operators to represent the first order expansion S1(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