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
4 changes: 4 additions & 0 deletions qiskit/result/distributions/quasi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, data, shots=None, stddev_upper_bound=None):
self.shots = shots
self._stddev_upper_bound = stddev_upper_bound
self._num_bits = 0
self.decimal = 15
Copy link
Member

@t-imamichi t-imamichi Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to set the decimal with a class variable __decimal__ or __ndigits__ (instead of instance variable self.decimal) similar to Pauli.__repr__.

Using ``str`` to convert a ``Pauli`` to a string will truncate the
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
value. If set to ``0`` no truncation will be performed.

Do you have any suggestion, @ikkoham?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @t-imamichi. Class variable is better than instance variable. Variable names can be something like dunder/magic (__decimal__), or they can be normal (decimal).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! done in d2866a3

Thanks!

if data:
first_key = next(iter(data.keys()))
if isinstance(first_key, int):
Expand Down Expand Up @@ -141,3 +142,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.decimal) for key, value in self.items()})