Skip to content

Add support for the Matsumoto-Amano normal form.#1801

Merged
NoureldinYosri merged 9 commits intoquantumlib:mainfrom
codrut3:issue-1762
Feb 25, 2026
Merged

Add support for the Matsumoto-Amano normal form.#1801
NoureldinYosri merged 9 commits intoquantumlib:mainfrom
codrut3:issue-1762

Conversation

@codrut3
Copy link
Copy Markdown
Contributor

@codrut3 codrut3 commented Feb 4, 2026

Fixes #1762

@codrut3
Copy link
Copy Markdown
Contributor Author

codrut3 commented Feb 5, 2026

@NoureldinYosri please have a look when you have time!

Copy link
Copy Markdown
Contributor

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

overall looks good, but $T == T_z$, so you can update the representation of T to just be the same as Tz, thanks for the contribution @codrut3

@codrut3
Copy link
Copy Markdown
Contributor Author

codrut3 commented Feb 6, 2026

Thank you a lot for your review, Noureldine! Do you mean set TSqrt2 = Tz in _su2_ct.py?

For me it wasn't obvious that T can be scaled to be a member of SU2CliffordT, and it took me a bit to work out the constant $c$ so that c / (2(2+\sqrt{2})) T is in SU2CliffordT :) That's why I defined TSqrt2 in addition to Tz. But I can set TSqrt2 = Tz and put the other definition in a comment above, would this work?

@NoureldinYosri
Copy link
Copy Markdown
Contributor

yes, there is no need to define a TSqrt2, the normal T becomes Tz in SU2. Given any 1Q unitary gate $U$ you can get its SU2 version by dividing by $\sqrt{det|U|}$ since the determinant is a on the unit circle and dividing by its square root cancels the global phase.

Tx and Ty are the X and Y axis version of the T gate ($\frac{\pi}{4}$ rotations around their axes)

@codrut3
Copy link
Copy Markdown
Contributor Author

codrut3 commented Feb 7, 2026

Actually now I realize that if I set TSqrt2 = Tz then the gates property in SU2CliffordT is Tz, and so everywhere instead of T it would print Tz. For example, the Matsumoto-Amano sequence would be Tz H Tz S H Tz .... Isn't this confusing for the user?

@NoureldinYosri
Copy link
Copy Markdown
Contributor

good point, @mpharrigan what do you think? should we create a separate T from Tz ?

@mpharrigan
Copy link
Copy Markdown
Collaborator

I don't have the full context, but if the issue is just how the same logical object gets formatted as a string, I'd recommend putting that logic with the string formatting

@codrut3
Copy link
Copy Markdown
Contributor Author

codrut3 commented Feb 11, 2026

Thank you for the comments! I removed the TSqrt2 matrix and I used Tz everywhere instead. The sequence element is printed as T.

to_cirq which converts the sequence to a Cirq representation still needs to handle the T character, and same for to_quirk.

Copy link
Copy Markdown
Contributor

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

thanks @codrut3 this looks really nice, just a few nits

Allowable format strings are
- 'xyz' uses Tx, Ty, Tz gates.
- 'xz' uses $Tx, Tz, Tx^\dagger, Tz^\dagger$
- 't' uses T gates, and returns the Matsumoto-Amano normal form.
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.

Suggested change
- 't' uses T gates, and returns the Matsumoto-Amano normal form.
- 't' uses only Tz gates, and returns the Matsumoto-Amano normal form.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

break
gates: tuple[str, ...] = ()
new: Union[_su2_ct.SU2CliffordT, None]
if np.array_equal(parity, np.array([[1, 1, 0], [1, 1, 0], [0, 0, 0]])):
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.

can you move this if/else block into a separate method and turn _matsumoto_amano_sequence into an iterative procedure rather than recursive?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Args:
matrix: The matrix to represent.
fmt: A string from the set {'xz', 'xyz'} representing the allowed T gates described above.
fmt: A string from the set {'xz', 'xyz', t'} representing the allowed T gates described above.
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.

typo:

Suggested change
fmt: A string from the set {'xz', 'xyz', t'} representing the allowed T gates described above.
fmt: A string from the set {'xz', 'xyz', 't'} representing the allowed T gates described above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@pytest.mark.parametrize("g", _make_random_su(50, 5, random_cliffords=True, seed=0))
def test_to_cirq(g):
circuit = cirq.Circuit(ctr.to_cirq(g, 'xyz'))
@pytest.mark.parametrize("fmt", ('xyz', 't'))
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.

lets add xz as well

Suggested change
@pytest.mark.parametrize("fmt", ('xyz', 't'))
@pytest.mark.parametrize("fmt", ('xyz', 'xz', 't'))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@NoureldinYosri NoureldinYosri enabled auto-merge (squash) February 17, 2026 16:02
Copy link
Copy Markdown
Contributor

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

thanks @codrut3

auto-merge was automatically disabled February 18, 2026 20:13

Head branch was pushed to by a user without write access

@codrut3
Copy link
Copy Markdown
Contributor Author

codrut3 commented Feb 18, 2026

I saw there was a pylint error and I fixed it.

@NoureldinYosri NoureldinYosri enabled auto-merge (squash) February 19, 2026 00:00
@codrut3
Copy link
Copy Markdown
Contributor Author

codrut3 commented Feb 25, 2026

@NoureldinYosri is there anything else I need to do here?

@NoureldinYosri NoureldinYosri merged commit e6dcafb into quantumlib:main Feb 25, 2026
9 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.

Add the ability to represent a clifford+T operation in Matsumoto-Amano normal form

3 participants