4
$\begingroup$

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')

My output: print(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: nice_tutorial_circuit

My questions:

  1. Is PauliTrotterEvolution the right tool in the first place?
  2. 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')

hamiltonian=X^X^Z

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')

hamiltonian = (X^X^Z) + (Z^X^Z)

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')
$\endgroup$

1 Answer 1

4
$\begingroup$

You have to decompose the circuit produced by the PauliTrotterEvolution to see what gates are applied inside

# your code from above
circuit = trotterized_op.to_circuit()
decomposed = circuit.decompose()
decomposed.draw('mpl')

In Qiskit we often wrap subcircuits into a block so that you can see what's going on on a higher level of abstraction. But you can still have a look inside those blocks by decomposing :)

$\endgroup$
2
  • $\begingroup$ Wow, thanks! Makes total sense as a feature. Decompose works like a charm for single-term-hamiltonians. Somehow not for multiple-term-hamiltonians. Do you know if I can force qiskit to dempose it further? $\endgroup$ Feb 13 at 2:22
  • 1
    $\begingroup$ Nevermind. In the documentition it states: 'to decompose one level (shallow decompose)'. Decomposing multiple times fixes it :) $\endgroup$ Feb 13 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.