I need a way to implement exponential of a matrix so that I can create a gate that is analogous to rotation using that matrix, similar to how rotation in the $x$ axis uses the Pauli-$X$ gate. This is one of the matrices that I want to implement the exponential.

$A = \frac{1}{2\sqrt{2}}\begin{pmatrix} 0 & 1 & 1 & 0\\ 1 & 0 & 0 & 1\\ 1 & 0 & 0 & 1\\ 0 & 1 & 1 & 0 \end{pmatrix}$

I want to to make a circuit that computes $e^{i \phi A}$


2 Answers 2


Hamiltonian needs to be Hermitian not unitary. Matrix $A$ is Hermitian so it can be exponentiated using the classes in qiskit's opflow.

Note that, your matrix can be written as $A = \frac{1}{2\sqrt{2}}(I \otimes X + X \otimes I)$

So the following circuit computes $e^{-i \phi A}$

from qiskit.opflow import I, X
from qiskit.opflow import PauliTrotterEvolution, Suzuki
from qiskit.circuit import Parameter
from numpy import sqrt

_const = 1 / (2 * sqrt(2))
A = _const * (I ^ X) + _const * (X ^ I)

phi = Parameter('ϕ')

evolution_op = (phi * A).exp_i() # exp(-iϕA)

trotterized_op = PauliTrotterEvolution(trotter_mode = Suzuki(order = 1)).convert(evolution_op)
circ = trotterized_op.to_circuit()

enter image description here

  • $\begingroup$ Sorry, in the question I meant hermitian, not hamiltonian. I'll try this solution, it looks like it'll work. $\endgroup$
    – Nillmer
    Commented Feb 14, 2022 at 12:21

Or, if you have the actual matrix representation you can do

from qiskit.circuit import QuantumCircuit

phi = # some numerical value
A = # your matrix

circuit = QuantumCircuit(2)
circuit.hamiltonian(A, time=phi, qubits=range(2))

Though this will give an inefficient decomposition into gates as it takes the exact matrix exponential and synthesis that into a circuit. If you know the Pauli decomposition of your matrix and can use @Egretta.Thula's solution, that'll be much more efficient.


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.