Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce decimal for probabilities_dict in Sampler #10596

Merged
merged 11 commits into from
Sep 28, 2023
2 changes: 1 addition & 1 deletion qiskit/quantum_info/operators/symplectic/pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class initialization (``Pauli('-iXYZ')``). A ``Pauli`` object can be
returned string for large numbers of qubits while :meth:`to_label`
will return the full string with no truncation. The default
truncation length is 50 characters. The default value can be
changed by setting the class `__truncate__` attribute to an integer
changed by setting the class ``__truncate__`` attribute to an integer
value. If set to ``0`` no truncation will be performed.

**Array Representation**
Expand Down
11 changes: 11 additions & 0 deletions qiskit/result/distributions/quasi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ class QuasiDistribution(dict):
"""A dict-like class for representing quasi-probabilities."""

_bitstring_regex = re.compile(r"^[01]+$")
__ndigits__ = 15

def __init__(self, data, shots=None, stddev_upper_bound=None):
"""Builds a quasiprobability distribution object.

.. note::

The quasiprobability values might include floating-point errors.
``QuasiDistribution.__repr__`` rounds using :meth:`numpy.round`
and the parameter ``ndigits`` can be manipulated with the
class attribute ``__ndigits__``. The default is ``15``.

Parameters:
data (dict): Input quasiprobability data. Where the keys
represent a measured classical value and the value is a
Expand Down Expand Up @@ -141,3 +149,6 @@ def hex_probabilities(self):
def stddev_upper_bound(self):
"""Return an upper bound on standard deviation of expval estimator."""
return self._stddev_upper_bound

def __repr__(self):
return str({key: round(value, ndigits=self.__ndigits__) for key, value in self.items()})
7 changes: 7 additions & 0 deletions releasenotes/notes/decimals_for_sampler-5aaa56642cce23e0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
upgrade:
- |
The :class:`~.QuasiDistribution` values might include floating-point errors.
``QuasiDistribution.__repr__`` rounds using :meth:`numpy.round`
and the parameter ``ndigits`` can be manipulated with the
class attribute ``__ndigits__``. The default is ``15``.