Skip to content

Fix #637: Fix global phase of J-∧z decompositions - #643

Merged
thierry-martinez merged 4 commits into
TeamGraphix:masterfrom
thierry-martinez:fix-637
Nov 11, 2026
Merged

thierry-martinez merged 4 commits into
TeamGraphix:masterfrom
thierry-martinez:fix-637

Conversation

@thierry-martinez

Copy link
Copy Markdown
Collaborator

Several decompositions were only correct up to a global phase. This is harmless at top level, but insert_control controls these decompositions, which turns the missing global phase into a relative phase and makes the resulting controlled gate wrong.

  • instruction_to_jcz now keeps the global phase of S, SDG, T, TDG, SX, SXDG, X and Z (and therefore Y).
  • decompose_ccx now uses T, TDG and S gates as in Nielsen & Chuang instead of RZ rotations, which fixes controlled CCX and CSWAP.

The statevector simulator ignores top-level GPHASE instructions, so the tests control each decomposition and compare it with Ops.controlled, for every instruction kind.

Also fix the PR number of the CH gate entry in CHANGELOG (#624, not #694).

Several decompositions were only correct up to a global phase. This is
harmless at top level, but `insert_control` controls these
decompositions, which turns the missing global phase into a relative
phase and makes the resulting controlled gate wrong.

- `instruction_to_jcz` now keeps the global phase of `S`, `SDG`, `T`,
  `TDG`, `SX`, `SXDG`, `X` and `Z` (and therefore `Y`).
- `decompose_ccx` now uses `T`, `TDG` and `S` gates as in Nielsen &
  Chuang instead of `RZ` rotations, which fixes controlled `CCX` and
  `CSWAP`.

The statevector simulator ignores top-level `GPHASE` instructions, so
the tests control each decomposition and compare it with
`Ops.controlled`, for every instruction kind.

Also fix the PR number of the CH gate entry in CHANGELOG
(TeamGraphix#624, not #694)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.97%. Comparing base (095ee8a) to head (e9af7be).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #643   +/-   ##
=======================================
  Coverage   89.96%   89.97%           
=======================================
  Files          49       49           
  Lines        8462     8466    +4     
=======================================
+ Hits         7613     7617    +4     
  Misses        849      849           

☔ 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.

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

Comment thread tests/test_transpiler.py Resolved
Co-authored-by: Mateo Uldemolins <m.uldemolins@gmail.com>
@matulni matulni linked an issue Nov 3, 2026 that may be closed by this pull request
thierry-martinez and others added 2 commits November 5, 2026 19:42
`Statevector.flatten` returns `Matrix`, i.e. `NDArray[object_ | complex128]`,
which pyright rejects as an operand of `@`. Convert it to `complex128`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pranav97nair pranav97nair 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.

Very nice work, thanks Thierry!

@thierry-martinez
thierry-martinez merged commit 01ccb7e into TeamGraphix:master Nov 11, 2026
38 of 39 checks passed
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.

[Bug]: Decompositions drop global phases, making controlled gates wrong

4 participants