21
21
import sympy
22
22
from attrs import field , frozen
23
23
24
- from qualtran .symbolics import ceil , log2 , SymbolicFloat , SymbolicInt
24
+ from qualtran .symbolics import ceil , log2 , ssum , SymbolicFloat , SymbolicInt
25
25
26
26
from ._call_graph import get_bloq_callee_counts
27
27
from ._costing import CostKey
@@ -176,7 +176,7 @@ def _get_new_eps_bin(eps_bin):
176
176
eps_bin_prec = new_eps_bin_prec ,
177
177
)
178
178
179
- def iter_rotations_with_epsilon (self ) -> Iterator [tuple [float , int ]]:
179
+ def iter_rotations_with_epsilon (self ) -> Iterator [tuple [float , SymbolicInt ]]:
180
180
"""Iterate through the rotation precisions (epsilon) and their frequency."""
181
181
for eps_bin , n_rot in self .binned_rotation_epsilons .items ():
182
182
yield eps_bin / 2 ** self .eps_bin_prec , n_rot
@@ -243,7 +243,7 @@ def _keep(key, value) -> bool:
243
243
return {k : v for k , v in d .items () if _keep (k , v )}
244
244
245
245
@staticmethod
246
- def rotation_t_cost (eps : SymbolicFloat ) -> SymbolicFloat :
246
+ def rotation_t_cost (eps : SymbolicFloat ) -> SymbolicInt :
247
247
"""T-cost of a single Z rotation with precision `eps`.
248
248
249
249
References:
@@ -253,12 +253,10 @@ def rotation_t_cost(eps: SymbolicFloat) -> SymbolicFloat:
253
253
return ceil (1.149 * log2 (1.0 / eps ) + 9.2 )
254
254
255
255
@property
256
- def rotation_to_t (self ) -> int :
256
+ def rotation_to_t (self ) -> SymbolicInt :
257
257
"""Total number of T Gates for the rotations."""
258
- from qualtran .cirq_interop .t_complexity_protocol import TComplexity
259
-
260
- return sum (
261
- n_rotations * int (TComplexity .rotation_cost (eps ))
258
+ return ssum (
259
+ n_rotations * self .rotation_t_cost (eps )
262
260
for eps , n_rotations in self .iter_rotations_with_epsilon ()
263
261
)
264
262
@@ -286,9 +284,9 @@ def total_t_and_ccz_count(self) -> Dict[str, SymbolicInt]:
286
284
n_t = self .t + self .rotation_to_t
287
285
return {'n_t' : n_t , 'n_ccz' : n_ccz }
288
286
289
- def n_rotation_ignoring_eps (self ) -> int :
287
+ def n_rotation_ignoring_eps (self ) -> SymbolicInt :
290
288
"""Total number of rotations, ignoring the individual precisions."""
291
- return sum (self .binned_rotation_epsilons .values ())
289
+ return ssum (self .binned_rotation_epsilons .values ())
292
290
293
291
def total_beverland_count (self ) -> Dict [str , SymbolicInt ]:
294
292
r"""Counts used by Beverland. et. al. using notation from the reference.
0 commit comments