ProjectQ-Framework / ProjectQ

ProjectQ: An open source software framework for quantum computing
https://projectq.ch
Apache License 2.0
874 stars 271 forks source link

Probability distribution of qubits' classical value #413

Closed LuigiGiuffrida98 closed 3 years ago

LuigiGiuffrida98 commented 3 years ago

Why in the simulator there isn't an equivalent to get_probabilities() (like in IBM backend)? Wouldn't it be great to have something like this?

Takishima commented 3 years ago

While there is indeed no functions that can give you the data you want immediately, the simulator does provide a get_probability() method to access the probability of a particular bit string.

If you want to have the complete set of probabilities, you can do something like this:

probabilities = {}
n_qubits = len(qureg)
for i in range(n_qubits):
    bit_string = '{0:b}'.format(i).zfill(n_qubits)
    probabilities[bit_string] = eng.backend.get_probability(bit_string, qureg)
LuigiGiuffrida98 commented 3 years ago

Thanks a lot for your disponibility! 😊