2121import sympy
2222from attrs import field , frozen
2323
24- from qualtran .symbolics import ceil , log2 , SymbolicFloat , SymbolicInt
24+ from qualtran .symbolics import ceil , log2 , ssum , SymbolicFloat , SymbolicInt
2525
2626from ._call_graph import get_bloq_callee_counts
2727from ._costing import CostKey
@@ -176,7 +176,7 @@ def _get_new_eps_bin(eps_bin):
176176 eps_bin_prec = new_eps_bin_prec ,
177177 )
178178
179- def iter_rotations_with_epsilon (self ) -> Iterator [tuple [float , int ]]:
179+ def iter_rotations_with_epsilon (self ) -> Iterator [tuple [float , SymbolicInt ]]:
180180 """Iterate through the rotation precisions (epsilon) and their frequency."""
181181 for eps_bin , n_rot in self .binned_rotation_epsilons .items ():
182182 yield eps_bin / 2 ** self .eps_bin_prec , n_rot
@@ -243,7 +243,7 @@ def _keep(key, value) -> bool:
243243 return {k : v for k , v in d .items () if _keep (k , v )}
244244
245245 @staticmethod
246- def rotation_t_cost (eps : SymbolicFloat ) -> SymbolicFloat :
246+ def rotation_t_cost (eps : SymbolicFloat ) -> SymbolicInt :
247247 """T-cost of a single Z rotation with precision `eps`.
248248
249249 References:
@@ -253,12 +253,12 @@ def rotation_t_cost(eps: SymbolicFloat) -> SymbolicFloat:
253253 return ceil (1.149 * log2 (1.0 / eps ) + 9.2 )
254254
255255 @property
256- def rotation_to_t (self ) -> int :
256+ def rotation_to_t (self ) -> SymbolicInt :
257257 """Total number of T Gates for the rotations."""
258258 from qualtran .cirq_interop .t_complexity_protocol import TComplexity
259259
260- return sum (
261- n_rotations * int ( TComplexity . rotation_cost (eps ) )
260+ return ssum (
261+ n_rotations * self . rotation_t_cost (eps )
262262 for eps , n_rotations in self .iter_rotations_with_epsilon ()
263263 )
264264
@@ -286,9 +286,9 @@ def total_t_and_ccz_count(self) -> Dict[str, SymbolicInt]:
286286 n_t = self .t + self .rotation_to_t
287287 return {'n_t' : n_t , 'n_ccz' : n_ccz }
288288
289- def n_rotation_ignoring_eps (self ) -> int :
289+ def n_rotation_ignoring_eps (self ) -> SymbolicInt :
290290 """Total number of rotations, ignoring the individual precisions."""
291- return sum (self .binned_rotation_epsilons .values ())
291+ return ssum (self .binned_rotation_epsilons .values ())
292292
293293 def total_beverland_count (self ) -> Dict [str , SymbolicInt ]:
294294 r"""Counts used by Beverland. et. al. using notation from the reference.
0 commit comments