2
$\begingroup$

I have a unitary gate $U$, which is applied on some $n$-qubit quantum circuit ($n=7$ for my scenario). I wish to find the $n$-qubit state, which is the eigenvector (and possibly eigenvalues) of this unitary in Qiskit's latest version. How do I do that?

$\endgroup$

1 Answer 1

3
$\begingroup$

You can simply use numpy:

from qiskit.circuit.library import XGate

gate = XGate()

# Get the underlying array
unitary_matrix = gate.to_matrix()
# Or you can get it like this
from qiskit.quantum_info import Operator
unitary_matrix = Operator(gate).data

# Now you can compute the eigenvalues and eigenvectors using numpy
import numpy as np
eigenvalues, eigenvectors = np.linalg.eig(unitary_matrix)

print(eigenvalues)
# [ 1.+0.j -1.+0.j]

print(eigenvectors)
# [[ 0.70710678-0.j  0.70710678+0.j]
#  [ 0.70710678+0.j -0.70710678-0.j]]

This process generalizes for any gate: simply apply Operator on them and query their data attribute to get a numpy array, and let numpy handle the eigendecomposition.

$\endgroup$

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.