How to create qudit, not qubit (which is a special case of qudit with $d = 2$) in qiskit of any dimension $d$?

Actually, I searched this on chatgpt, but not-so-helpful info was found. It just uses qubits and tries to simulate it to behave like qudits, but it is not properly done. Also, it uses the QuantumCircuit function, which generates qubits only, not qudits, with some classical registers.


2 Answers 2


In order to do that on a real hardware you will need to create your own discriminator for classifying higher energy states. An old example can be found in here for the case of qutrits (d=3). However, the notebook in the example is using an old version of Qiskit, so you would probably need to change a few lines here and there in order to make that work.


Qiskit has some support for qudits via the dims parameter in Statevector as described here https://docs.quantum.ibm.com/api/qiskit/qiskit.quantum_info.Statevector#to_dict

For example if $d = 3$, you can create the ket vector $|2\rangle$ like this:

from qiskit.quantum_info import Statevector

ket_2 = Statevector.from_int(2, dims=(3,))
Statevector([0.+0.j, 0.+0.j, 1.+0.j],
{'2': (1+0j)}

You can also create more complicated qudit ket vectors such as $$\frac{1}{\sqrt{2}}|012\rangle + \frac{1}{\sqrt{2}}|210\rangle$$ like this:

import numpy as np

u = (1 / np.sqrt(2)) * Statevector.from_int(int('012', 3), dims=(3, 3, 3))
v = (1 / np.sqrt(2)) * Statevector.from_int(int('210', 3), dims=(3, 3, 3))
w = u + v
Statevector([0.        +0.j, 0.        +0.j, 0.        +0.j,
             0.        +0.j, 0.        +0.j, 0.70710678+0.j,
             0.        +0.j, 0.        +0.j, 0.        +0.j,
             0.        +0.j, 0.        +0.j, 0.        +0.j,
             0.        +0.j, 0.        +0.j, 0.        +0.j,
             0.        +0.j, 0.        +0.j, 0.        +0.j,
             0.        +0.j, 0.        +0.j, 0.        +0.j,
             0.70710678+0.j, 0.        +0.j, 0.        +0.j,
             0.        +0.j, 0.        +0.j, 0.        +0.j],
            dims=(3, 3, 3))
{'012': (0.7071067811865475+0j), '210': (0.7071067811865475+0j)}

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.