Skip to content

Commit 2b281e0

Browse files
authored
4 Ts per CSwap (#1642)
Fixes #1463 - change default ts per cswap to 4 - leaves it as inconsistently 7 in `to_legacy_t_complexity` with a note
1 parent ddaa7ea commit 2b281e0

7 files changed

Lines changed: 13 additions & 8 deletions

File tree

qualtran/bloqs/chemistry/df/double_factorization_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def test_compare_cost_to_openfermion():
8080
inner_prep_qrom_diff = 8
8181
prog_rot_qrom_diff = 60
8282
missing_toffoli = 4 # need one more toffoli for second application of CZ
83-
swap_cost = 4 * (7 - 4) * num_spin_orb // 2
84-
qual_cost = t_counts - inner_prep_qrom_diff - prog_rot_qrom_diff + missing_toffoli - swap_cost
83+
qual_cost = t_counts - inner_prep_qrom_diff - prog_rot_qrom_diff + missing_toffoli
8584
# correct the expected cost by using a different uniform superposition algorithm
8685
# see: https://github.com/quantumlib/Qualtran/issues/611
8786
eta = power_two(num_aux + 1)

qualtran/bloqs/chemistry/hubbard_model/qubitization/select_hubbard_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_select_t_complexity(dim):
3535
assert cost == GateCounts(
3636
cswap=2 * logN, and_bloq=5 * (N // 2) - 2, measurement=5 * (N // 2) - 2, clifford=ANY
3737
)
38-
assert cost.total_t_count() == 10 * N + 14 * logN - 8
38+
assert cost.total_t_count() == 10 * N + 8 * logN - 8
3939

4040

4141
def test_adjoint_controlled():

qualtran/bloqs/chemistry/pbc/first_quantization/projectile/select_and_prepare_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_select_t_costs():
5353
cost = get_cost_value(sel_first_quant, QECGatesCost()).total_t_count()
5454

5555
# Swaps
56-
expected_cost = 7 * (12 * eta * num_bits_p + 6 * num_bits_n) + 4 * (4 * eta - 6) #
56+
expected_cost = 4 * (12 * eta * num_bits_p + 6 * num_bits_n) + 4 * (4 * eta - 6) #
5757
# SELT
5858
expected_cost += 4 * (5 * (num_bits_n - 1) + 2 + 1)
5959
# SELUV

qualtran/bloqs/chemistry/pbc/first_quantization/select_and_prepare_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_select_t_costs():
5151
)
5252
cost += get_cost_value(sel_first_quant, QECGatesCost()).total_t_count()
5353

54-
expected_cost = 7 * (12 * eta * num_bits_p) + 4 * (4 * eta - 8)
54+
expected_cost = 4 * (12 * eta * num_bits_p) + 4 * (4 * eta - 8)
5555
expected_cost += 4 * (5 * (num_bits_p - 1) + 2)
5656
expected_cost += 4 * (24 * num_bits_p)
5757
expected_cost += 4 * (

qualtran/resource_counting/_bloq_counts.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def _is_nonzero(v):
186186
def total_t_count(
187187
self,
188188
ts_per_toffoli: int = 4,
189-
ts_per_cswap: int = 7,
189+
ts_per_cswap: int = 4,
190190
ts_per_and_bloq: int = 4,
191191
ts_per_rotation: int = 11,
192192
) -> int:
@@ -236,6 +236,12 @@ def to_legacy_t_complexity(
236236
add per `self.and_bloq`. To fully match the exact legacy `t_complexity` numbers, you
237237
must enable `QECGatesCost(legacy_shims=True)`, which will enable a shim that directly
238238
adds on clifford counts for the X-gates used to invert the And control lines.
239+
240+
**Warning:** The number of Ts per Toffoli defaults to 4, whereas the
241+
number of Ts per CSwap defaults to 7. This preserves a legacy inconsistency. Really,
242+
these numbers should either both be 7 or both be 4 for a proper accounting.
243+
In `total_t_count`, we default to 4 T gates per CSwap or Toffoli. See
244+
https://github.com/quantumlib/Qualtran/issues/1463 for more discussion.
239245
"""
240246
from qualtran.cirq_interop.t_complexity_protocol import TComplexity
241247

qualtran/resource_counting/_bloq_counts_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_gate_counts():
6161
assert GateCounts(t=10) * 2 == GateCounts(t=20)
6262
assert 2 * GateCounts(t=10) == GateCounts(t=20)
6363

64-
assert GateCounts(toffoli=1, cswap=1, and_bloq=1).total_t_count() == 4 + 7 + 4
64+
assert GateCounts(toffoli=1, cswap=1, and_bloq=1).total_t_count() == 4 + 4 + 4
6565

6666
gc2 = GateCounts(t=sympy.Symbol('n'), toffoli=sympy.sympify('0'), cswap=2)
6767
assert str(gc2) == 't: n, cswap: 2'

qualtran/resource_counting/classify_bloqs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_classify_bloq_counts_with_custom_bloq_classification():
113113
classified_bloqs = classify_t_count_by_bloq_type(
114114
test_bloq, bloq_classification=bloq_classification
115115
)
116-
assert classified_bloqs == {'swaps': 42 * 10 * 7, 'other': 3 * 4 * (4 - 1)}
116+
assert classified_bloqs == {'swaps': 42 * 10 * 4, 'other': 3 * 4 * (4 - 1)}
117117
assert get_cost_value(test_bloq, QECGatesCost()).total_t_count() == sum(
118118
classified_bloqs.values()
119119
)

0 commit comments

Comments
 (0)