Context:
I have H (in qiskit.opflow notation).
I want a circuit which does exp(-itH)
Solution attempt:
I think qiskit.opflow.evolutions.PauliTrotterEvolution should do the trick.
Also, I found this nice tutorial https://nahumsa.github.io/n-blog/2021-05-11-quantum_simulation/
Minimalistic example:
from qiskit.opflow import X, Y, Z, I, PauliTrotterEvolution
from qiskit.circuit import Parameter
hamiltonian = 3*(X^X^Z) - 1*(Z^X^Z)
# evolution operator
evo_time = Parameter('t')
evolution_op = (evo_time*hamiltonian).exp_i()
print(evolution_op)
# into circuit
num_time_slices = 1
trotterized_op = PauliTrotterEvolution(
trotter_mode='trotter',
reps=num_time_slices).convert(evolution_op)
trotterized_op.to_circuit().draw('mpl')
Problem:
(a) the Hamiltonian doesn't seem to get trotterized (split up)
(b) the circuit doesn't show the individual gates
Compare that to the nice output of the tutorial quoted above:
My questions:
- Is PauliTrotterEvolution the right tool in the first place?
- Why does the circuit look different for me than in the linked tutorial?
Solution
using decompose()
shows the gates for single-term-hamiltonians
hamiltonian = (X^X^Z)
evo_time = Parameter('t')
evolution_op = (evo_time*hamiltonian).exp_i()
num_time_slices = 1
trotterized_op = PauliTrotterEvolution(
trotter_mode='trotter',
reps=num_time_slices).convert(evolution_op)
trot_op_circ = trotterized_op.to_circuit()
trot_op_circ_decomp = trot_op_circ.decompose()
trot_op_circ_decomp.draw('mpl')
and multiple-term-hamiltonians are split up, but not decomposed into gates:
hamiltonian = (X^X^Z) + (Z^X^Z)
evo_time = Parameter('t')
evolution_op = (evo_time*hamiltonian).exp_i()
num_time_slices = 1
trotterized_op = PauliTrotterEvolution(
trotter_mode='trotter',
reps=num_time_slices).convert(evolution_op)
trot_op_circ = trotterized_op.to_circuit()
trot_op_circ_decomp = trot_op_circ.decompose()
trot_op_circ_decomp.draw('mpl')
To decompose multiple-term-hamiltonians into gates, decompose can be called repeatedly:
trot_op_circ_decomp = trot_op_circ.decompose()
trot_op_circ_decomp = trot_op_circ_decomp.decompose()
trot_op_circ_decomp.draw('mpl')