I was recently trying to use Qiskit's inbuilt QDRIFT to construct a circuit for a simple Hamiltonian $H = XX + YY$. but I'm having an issue converting the result of QDrift.convert into a circuit. I get the constructor first by doing:

>>> from qiskit.opflow.evolutions.trotterizations.qdrift import QDrift
>>> sim = QDrift(1)

Then I construct my Hamiltonian by doing:

>>> from qiskit.opflow import X, Y
>>> pauli = (X ^ X) + (Y ^ Y)

I checked the type of pauli, it is <class 'qiskit.opflow.primitive_ops.pauli_sum_op.PauliSumOp'> which should not be an issue for my qdrift. I then get my new op by doing:

>>> com_op = sim.convert(pauli)

The type of com_op is <class 'qiskit.opflow.list_ops.composed_op.ComposedOp'>. This class's documentation exists here and it has a method to_circuit defined for it. But when I run it I get error:

qiskit.extensions.exceptions.ExtensionError: 'Input matrix is not unitary.'

Any way I can get my circuit? I do not see why it can't construct a circuit for this.


1 Answer 1


An easy way to use QDrift in Qiskit is to pass it as a synthesis method to PauliEvolutionGate

from qiskit.circuit.library import PauliEvolutionGate
from qiskit.opflow import X, Y
from qiskit.synthesis import QDrift

op = (X^X) + (Y^Y)
time = 1
reps = 1

evo_gate = PauliEvolutionGate(op, time, synthesis=QDrift(reps = reps))

circ = QuantumCircuit(2)
circ.append(evo_gate, [0, 1])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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