After executing a job on qiskit, the typically procedure to get the measurement data from the quantum computer is to call get_counts() like so...

job = execute(qc, backend, shots=100)
result = job.result()
counts = result.get_counts()

If the final state is, for example, $|01\rangle$ then '01' would be the only key in counts. Does Qiskit currently have a way to pad the returned counts dictionary with 0s for all other states? So, it'd return something like counts = results.get_counts(pad=True), and counts would then be counts = {'00':0, '01':100, '10':0, '11':0}?

It'd be great if this was a native option.

  • 2
    $\begingroup$ Such a feature would probably confuse many users when get_counts runs out of memory on their 30+ qubit experiments. $\endgroup$ Commented Aug 23, 2021 at 17:30

1 Answer 1


Looking at the documentation for qiskit.result.Result.get_counts(), this doesn't seem to be a native option. A good alternative to this is the following:

counts.get('1', 0)

Which will return 0 if the key '1' is not present in the counts dictionary. You can loop through all possible $\{0, 1\}^n$ states and create a new dictionary with all the padded counts or just call the .get() function when you need it.

However, I do think this may be a useful feature to have natively, so I recommend opening an issue on the Qiskit Terra repo. But some aspects such as running out of memory for experiments with a large amount of qubits (as noted by @Adam Zalcman) need to be discussed.

  • 1
    $\begingroup$ Thanks, I submitted a feature enhancement. $\endgroup$ Commented Aug 23, 2021 at 17:31
  • 3
    $\begingroup$ +1 We can identify here a simple and general principle for the design of systems consisting of both a classical and a quantum computer. Namely, we should avoid situations where the classical resources scale with the dimension of the Hilbert space of the quantum processor. The proposed "enhancement" violates this principle. Moreover, it does it for little gain because the behavior it achieves is already efficiently implemented by the standard python dict type, as explained by @epelaaez. $\endgroup$ Commented Aug 23, 2021 at 20:06
  • 1
    $\begingroup$ 100% agree with Adam. $\endgroup$
    – jecado
    Commented Aug 24, 2021 at 13:19

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.