Skip to content

Commit 9b45a0b

Browse files
committed
symbolic
1 parent 35a1b4a commit 9b45a0b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

qualtran/resource_counting/_bloq_counts.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import sympy
2222
from 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

2626
from ._call_graph import get_bloq_callee_counts
2727
from ._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,10 @@ 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."""
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)
262260
for eps, n_rotations in self.iter_rotations_with_epsilon()
263261
)
264262

@@ -286,9 +284,9 @@ def total_t_and_ccz_count(self) -> Dict[str, SymbolicInt]:
286284
n_t = self.t + self.rotation_to_t
287285
return {'n_t': n_t, 'n_ccz': n_ccz}
288286

289-
def n_rotation_ignoring_eps(self) -> int:
287+
def n_rotation_ignoring_eps(self) -> SymbolicInt:
290288
"""Total number of rotations, ignoring the individual precisions."""
291-
return sum(self.binned_rotation_epsilons.values())
289+
return ssum(self.binned_rotation_epsilons.values())
292290

293291
def total_beverland_count(self) -> Dict[str, SymbolicInt]:
294292
r"""Counts used by Beverland. et. al. using notation from the reference.

0 commit comments

Comments
 (0)