Skip to content

Commit 8a45698

Browse files
committed
Remove TSqrt2 and use Tz instead.
1 parent 66f759c commit 8a45698

4 files changed

Lines changed: 13 additions & 19 deletions

File tree

qualtran/rotation_synthesis/matrix/_clifford_t_repr.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import math
16-
from typing import cast, Mapping, Optional
16+
from typing import cast, Mapping, Optional, Union
1717

1818
import cirq
1919
import numpy as np
@@ -103,27 +103,28 @@ def _matsumoto_amano_sequence(matrix: _su2_ct.SU2CliffordT) -> tuple[str, ...]:
103103
if np.all(parity[:, i] == 0):
104104
parity[:, [i, 2]] = parity[:, [2, i]]
105105
break
106-
gates : tuple[str, ...] = ()
106+
gates: tuple[str, ...] = ()
107+
new: Union[_su2_ct.SU2CliffordT, None]
107108
if np.array_equal(parity, np.array([[1, 1, 0], [1, 1, 0], [0, 0, 0]])):
108109
# Leftmost syllabe is T
109-
new = _su2_ct.TSqrt2.adjoint() @ matrix
110+
new = _su2_ct.Tz.adjoint() @ matrix
110111
gates = ('T',)
111112
elif np.array_equal(parity, np.array([[0, 0, 0], [1, 1, 0], [1, 1, 0]])):
112113
# Leftmost syllabe is HT
113114
new = _su2_ct.HSqrt2.adjoint() @ matrix
114-
new = _su2_ct.TSqrt2.adjoint() @ new
115+
new = _su2_ct.Tz.adjoint() @ new
115116
gates = ('T', 'H')
116117
elif np.array_equal(parity, np.array([[1, 1, 0], [0, 0, 0], [1, 1, 0]])):
117118
# Leftmost syllabe is SHT
118119
new = _su2_ct.SSqrt2.adjoint() @ matrix
119120
new = _su2_ct.HSqrt2.adjoint() @ new
120-
new = _su2_ct.TSqrt2.adjoint() @ new
121+
new = _su2_ct.Tz.adjoint() @ new
121122
gates = ('T', 'H', 'S')
122123
else:
123124
raise ValueError(f'Unexpected parity matrix:\n{parity}')
124125
new = new.scale_down()
125126
if new is None or not new.is_valid():
126-
raise ValueError(f'Invalid SU2CliffordT matrix\n{new.matrix}')
127+
raise ValueError('Invalid SU2CliffordT matrix')
127128
seq = _matsumoto_amano_sequence(new)
128129
return seq + gates
129130

qualtran/rotation_synthesis/matrix/_su2_ct.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,6 @@ def _key_map():
347347
* SU2CliffordT(np.array([[_zw.One, _zw.Zero], [_zw.Zero, _zw.J]]), ("S",))
348348
)
349349

350-
# T gate scaled by sqrt(2) * (1 + w^*) to make its determinant = 2(2+sqrt(2))
351-
# TSqrt2 is equal to Tz below
352-
TSqrt2 = (
353-
_zw.SQRT_2
354-
* (1 + _zw.Omega.conj())
355-
* SU2CliffordT(np.array([[_zw.One, _zw.Zero], [_zw.Zero, _zw.Omega]]), ("T",))
356-
)
357-
358350
# Paulis
359351
ISqrt2: SU2CliffordT = _zw.SQRT_2 * SU2CliffordT(
360352
np.array([[_zw.One, _zw.Zero], [_zw.Zero, _zw.One]]), ()
@@ -372,6 +364,7 @@ def _key_map():
372364
# Tx, Ty, Tz scaled by sqrt(2*(2+sqrt(2)))
373365
Tx = SU2CliffordT(_I * _zw.SQRT_2 + _I - _X * _zw.J, ("Tx",))
374366
Ty = SU2CliffordT(_I * _zw.SQRT_2 + _I - _Y * _zw.J, ("Ty",))
367+
# Tz = sqrt(2) * (1 + w^*) * T and has determinant = 2(2+sqrt(2))
375368
Tz = SU2CliffordT(_I * _zw.SQRT_2 + _I - _Z * _zw.J, ("Tz",))
376369
Ts = [Tx, Ty, Tz]
377370

qualtran/rotation_synthesis/matrix/clifford_t_repr_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_to_cirq(g: _su2_ct.SU2CliffordT, fmt: str):
7575
[
7676
[_su2_ct.HSqrt2, "t", ('"Z^½"', '"X"', '"Z^½"', '"X"', '"H"')],
7777
[_su2_ct.SSqrt2, "t", ('{"id":"Rzft","arg":"pi/2"}',)],
78-
[_su2_ct.TSqrt2, "t", ('{"id":"Rzft","arg":"pi/4"}',)],
78+
[_su2_ct.Tz, "t", ('{"id":"Rzft","arg":"pi/4"}',)],
7979
],
8080
)
8181
def test_to_quirk(g: _su2_ct.SU2CliffordT, fmt: str, expected: tuple[str, ...]):

qualtran/rotation_synthesis/matrix/su2_ct_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_num_t_gates():
125125
[
126126
[_su2_ct.HSqrt2, _H_bloch_form_numpy, 0],
127127
[_su2_ct.SSqrt2, _S_bloch_form_numpy, 0],
128-
[_su2_ct.TSqrt2, _T_bloch_form_numpy, 1],
128+
[_su2_ct.Tz, _T_bloch_form_numpy, 1],
129129
],
130130
)
131131
def test_bloch_sphere_form_generators(g: _su2_ct.SU2CliffordT, bloch_form: np.ndarray, n: int):
@@ -157,9 +157,9 @@ def test_bloch_sphere_form_random(g: _su2_ct.SU2CliffordT, vector: np.ndarray):
157157
@pytest.mark.parametrize(
158158
["g", "parity"],
159159
[
160-
[_su2_ct.TSqrt2, _T_parity_numpy],
161-
[_su2_ct.HSqrt2 @ _su2_ct.TSqrt2, _HT_parity_numpy],
162-
[_su2_ct.SSqrt2 @ _su2_ct.HSqrt2 @ _su2_ct.TSqrt2, _SHT_parity_numpy],
160+
[_su2_ct.Tz, _T_parity_numpy],
161+
[_su2_ct.HSqrt2 @ _su2_ct.Tz, _HT_parity_numpy],
162+
[_su2_ct.SSqrt2 @ _su2_ct.HSqrt2 @ _su2_ct.Tz, _SHT_parity_numpy],
163163
],
164164
)
165165
def test_bloch_form_parity(g: _su2_ct.SU2CliffordT, parity: np.ndarray):

0 commit comments

Comments
 (0)