# Pad get_counts() with zeros for unmeasured states? (Qiskit)

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.

• Such a feature would probably confuse many users when get_counts runs out of memory on their 30+ qubit experiments. Aug 23 '21 at 17:30

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.
• +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. Aug 23 '21 at 20:06