Copied from qBraid/qBraid #785
The GateModelResultData.get_probabilities() method currently computes a probability distribution based on the measurement counts:
https://github.com/qBraid/qBraid/blob/03aa38b89081a3e6fc6890ac4e785eba96769847/qbraid/runtime/result.py#L163-L164
This works well for QPUs and for simulators that return raw measurement counts. However, many ideal quantum simulators compute the exact quantum state, providing deterministic results. These simulators do not involve probabilistic sampling, and the concept of shots does not apply. Consequently, these simulators do not return raw measurements or measurement counts, but instead provide direct probability data (histogram).
To better support these simulators, the GateModelResultData class should be updated to optionally accept pre-computed probabilities. This would allow get_probabilities() to return these probabilities directly, without needing to calculate them from counts.
TODO
- Add an optional argument to the
GateModelResultData class to accept pre-computed probabilities.
- If probabilities are provided,
get_probabilities() should return them directly.
- If probabilities are not provided,
get_probabilities() should maintain its current behavior of calculating probabilities based on get_counts().
- Regardless of whether probabilities are computed from counts or provided directly,
get_probabilities() should continue to respect the decimal=True/False option for formatting keys.
- Since the function for normalizing data will now apply to both counts and direct probability histograms, consider renaming
normalize_counts() to something more general, like normalize_histogram_data().
Copied from qBraid/qBraid #785
The
GateModelResultData.get_probabilities()method currently computes a probability distribution based on the measurement counts:https://github.com/qBraid/qBraid/blob/03aa38b89081a3e6fc6890ac4e785eba96769847/qbraid/runtime/result.py#L163-L164
This works well for QPUs and for simulators that return raw measurement counts. However, many ideal quantum simulators compute the exact quantum state, providing deterministic results. These simulators do not involve probabilistic sampling, and the concept of
shotsdoes not apply. Consequently, these simulators do not return raw measurements or measurement counts, but instead provide direct probability data (histogram).To better support these simulators, the
GateModelResultDataclass should be updated to optionally accept pre-computed probabilities. This would allowget_probabilities()to return these probabilities directly, without needing to calculate them from counts.TODO
GateModelResultDataclass to accept pre-computed probabilities.get_probabilities()should return them directly.get_probabilities()should maintain its current behavior of calculating probabilities based onget_counts().get_probabilities()should continue to respect thedecimal=True/Falseoption for formatting keys.normalize_counts()to something more general, likenormalize_histogram_data().