-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 5822445480
💛 - Coveralls |
Since this seems to be mainly a visualization issue, would it be better to change the printed values instead of the actual values? Otherwise, as you noted, this small changes can add up 🤔 |
Is there a way to "parametrize" the visualisation of a result? |
Yeah e.g. via |
I mean, to tell how many decimals I want. |
NumPy allows to set the precision of printed numbers, but I think this is only a global setting. With # in QuasiDist.__str__
truncated = {key: np.round(value, decimals=10) for key, value in self.items}
return str(truncated) |
Co-authored-by: Julien Gacon <[email protected]>
qiskit/result/distributions/quasi.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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__
.
qiskit/qiskit/quantum_info/operators/symplectic/pauli.py
Lines 96 to 101 in 55d4e98
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?
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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!
Pull Request Test Coverage Report for Build 6334811226
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too
* reduce decimal for probabilities_dict in Sampler * adjust qaoa tests * adjust qaoa tests * reno * Rolling everything back and just hook __repr__ Co-authored-by: Julien Gacon <[email protected]> * remove reno * QuasiDistribution.__repr__ --------- Co-authored-by: Julien Gacon <[email protected]> Co-authored-by: Takashi Imamichi <[email protected]>
The example in #10584 is:
The rounding error is coming from slightly high
np.round(..., decimals=16)
, original introduced in #9248. Moving that to 15 solved the issue.Not sure if reno-worthyActually, it might change the output of QAOA, so adding a update note.