Improve the readability of CliffordTableau _full_str_ function#7047
Improve the readability of CliffordTableau _full_str_ function#7047pavoljuhas merged 7 commits intoquantumlib:mainfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7047 +/- ##
==========================================
- Coverage 98.18% 98.17% -0.01%
==========================================
Files 1089 1089
Lines 95202 95201 -1
==========================================
- Hits 93473 93468 -5
- Misses 1729 1733 +4 ☔ View full report in Codecov by Sentry. |
| def test_str_full(): | ||
| t = cirq.CliffordTableau(num_qubits=1) | ||
| expected_str = r"""stable | destable | ||
| expected_str = r"""stable | destable |
There was a problem hiding this comment.
Please, do not introduce trailing blanks. The output is more usable without them.
| """ | ||
| + Z0 | + Y0 """ |
There was a problem hiding this comment.
Please keep the newline at the end of the string.
There might be a user code that relies on its presence.
| return { | ||
| (True, False): f'X{c}', |
There was a problem hiding this comment.
Please rewrite using match-case statement - https://docs.python.org/3/whatsnew/3.10.html#patterns-with-a-literal-and-variable. Should be more readable and avoid a temporary dictionary for each Pauli symbol resolution.
| fill_row( | ||
| left='{sign} {paulis}'.format( # from row i+n | ||
| sign='-' if self.rs[i + self.n] else '+', | ||
| paulis=''.join([pauli_from_matrix(i + self.n, j) for j in range(self.n)]), |
There was a problem hiding this comment.
no need for temporary list -
| paulis=''.join([pauli_from_matrix(i + self.n, j) for j in range(self.n)]), | |
| paulis=''.join(pauli_from_matrix(i + self.n, j) for j in range(self.n)), |
| ), | ||
| right=' {sign} {paulis}'.format( # from row i | ||
| sign='-' if self.rs[i] else '+', | ||
| paulis=''.join([pauli_from_matrix(i, j) for j in range(self.n)]), |
There was a problem hiding this comment.
| paulis=''.join([pauli_from_matrix(i, j) for j in range(self.n)]), | |
| paulis=''.join(pauli_from_matrix(i, j) for j in range(self.n)), |
pavoljuhas
left a comment
There was a problem hiding this comment.
Please see inline comments.
320b3f7 to
02437f2
Compare
|
Thanks for the comments, Pavol! done updating the pr with appended commits. |
25023ee to
7ccfd32
Compare
Avoid possibility of unmatched values, because bool can return only the `True` or `False` singletons.
We can appease pylint without line exception.
|
LGTM, thanks! |
…umlib#7047) * Improve the readability of Tableau str. * Apply comments. * Fix coverage * Nit - rename internal functions to start with underscore * Fix matching of np.bool values by converting them to stock bool Avoid possibility of unmatched values, because bool can return only the `True` or `False` singletons. * Rewrite string formatting with f-string We can appease pylint without line exception. --------- Co-authored-by: Pavol Juhas <juhas@google.com>
Came across this and figure improve the readability could potentially be helpful in future developments.