Skip to content

Fix pretty-printing of Clifford gates - #576

Open
thierry-martinez wants to merge 1 commit into
TeamGraphix:masterfrom
thierry-martinez:clifford-names
Open

Fix pretty-printing of Clifford gates#576
thierry-martinez wants to merge 1 commit 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

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.12%. Comparing base (0412960) to head (6cc5ca2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #576   +/-   ##
=======================================
  Coverage   89.11%   89.12%           
=======================================
  Files          49       49           
  Lines        7716     7723    +7     
=======================================
+ Hits         6876     6883    +7     
  Misses        840      840           

☔ 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 thread tests/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!

@matulni matulni 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!

Sign up for free to 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.

2 participants