enter image description here

This is a simulation I did in my program. I'm hoping to print out the probability of the state $|0001\rangle$ (which is $0.052$), and store this number in a letter (a). How can I do this? Thanks!!


.get_counts() returns a dictionary with the keys being the measured state and their corresponding values being the number of times that result was measured. To get the number of times that state was measured you can do:


To get probability, you need to divide this by the total number of shots. If you're not sure of the number of shots, you can sum the total number of shots in the dictionary using:


and from this print the probability:

print(counts['0001'] / sum(counts.values()))
  • 1
    $\begingroup$ Thanks!! That helps:) $\endgroup$
    – ZR-
    Sep 3 '20 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.