Skip to content

Fix pretty-printing of Clifford gates - #576

Merged
thierry-martinez merged 5 commits into
TeamGraphix:masterfrom
thierry-martinez:clifford-names
Aug 18, 2026
Merged

Fix pretty-printing of Clifford gates#576
thierry-martinez merged 5 commits into
TeamGraphix:masterfrom
thierry-martinez:clifford-names

Conversation

@thierry-martinez

Copy link
Copy Markdown
Collaborator

This commit implements clifford_to_str, which relies on the QASM3 decomposition (into I, X, Y, Z, S, S†, and H), since it is more compact than the HSZ decomposition.

CLIFFORD_LABEL is removed from _db as names were ambiguous. The QASM3 decomposition has been made optimal and is now tested.

All members of the Clifford class now appear in the documentation and docstrings are fixed.

This commit implements `clifford_to_str`, which relies on the QASM3
decomposition (into `I`, `X`, `Y`, `Z`, `S`, `S†`, and `H`), since
it is more compact than the HSZ decomposition.
`CLIFFORD_LABEL` is removed from `_db` as names were ambiguous.
The QASM3 decomposition has been made optimal and is now tested.
All members of the `Clifford` class now appear in the documentation
and docstrings are fixed.
@codecov

codecovBot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.27%. Comparing base (ac53e88) to head (8a1f04f).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #576 +/- ##
=======================================
Coverage 89.26% 89.27% =======================================
Files 49 49 Lines 7791 7798 +7 =======================================
+ Hits 6955 6962 +7 
Misses 836 836 

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment threadtests/test_db.py
Comment on lines +158 to +177
def generate_qasm3_decomposition() -> tuple[tuple[str, ...], ...]:
decompositions: list[tuple[str, ...] | None] = [None] * len(Clifford)
new_decompositions: dict[Clifford, tuple[str, ...]] = {
clifford: (instr,) for clifford, instr in QASM3_BASIS.items()
}
while new_decompositions:
current_decompositions = new_decompositions
new_decompositions = {}
for clifford, decomposition in current_decompositions.items():
decompositions[clifford.value] = decomposition
for clifford, decomposition in current_decompositions.items():
for instr_clifford, instr in QASM3_BASIS.items():
result = instr_clifford @ clifford
if decompositions[result.value] is not None:
continue
result_decomposition = (*decomposition, instr)
decompositions[result.value] = result_decomposition
new_decompositions[result] = result_decomposition
assert all(decomposition is not None for decomposition in decompositions)
return tuple(map(unwrap, decompositions))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very nice!

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Seeing the code again, I realized that lines 167 and 174 are making the job twice. Fixed in 21590b2. Thanks for the compliment!

@matulnimatulni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@pranav97nairpranav97nair left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice work, thanks Thierry!

@thierry-martinez
thierry-martinez merged commit f01b407 into TeamGraphix:masterAug 18, 2026
22 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@thierry-martinez@pranav97nair@matulni