Skip to content

Commit 96cd9df

Browse files
committed
cleanup
1 parent ec326b8 commit 96cd9df

11 files changed

+25
-46
lines changed

qualtran/bloqs/block_encoding/sparse_matrix_hermitian.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,6 @@ def get_ctrl_system(self, ctrl_spec: 'CtrlSpec') -> tuple['Bloq', 'AddControlled
259259

260260
return get_ctrl_system_for_bloq_with_specialized_single_qubit_control(self, ctrl_spec)
261261

262-
@property
263-
def ctrl_reg_name(self) -> str:
264-
return 'ctrl'
265-
266262
def with_cv(self, cv: Optional[int]) -> 'SparseMatrixHermitian':
267263
return attrs.evolve(self, cv=cv)
268264

qualtran/bloqs/max_k_xor_sat/guided_hamiltonian/guided_hamiltonian.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
ceil,
6161
HasLength,
6262
is_symbolic,
63+
is_zero,
6364
ln,
6465
log2,
6566
pi,
@@ -124,10 +125,17 @@ def build_composite_bloq(
124125
phase_estimate: Soquet,
125126
system: Soquet,
126127
walk_ancilla: Soquet,
127-
guide_ancilla: Soquet,
128+
**soqs: SoquetT,
128129
) -> dict[str, 'SoquetT']:
130+
129131
# prepare the guiding state
130-
system, guide_ancilla = bb.add(self.guiding_state, selection=system, junk=guide_ancilla)
132+
if is_zero(self.guiding_state.junk_bitsize):
133+
system = bb.add(self.guiding_state, selection=system)
134+
else:
135+
system, guide_ancilla = bb.add(
136+
self.guiding_state, selection=system, junk=soqs.pop('guide_ancilla')
137+
)
138+
soqs['guide_ancilla'] = guide_ancilla
131139

132140
# apply QPE
133141
phase_estimate, system, walk_ancilla = bb.add(
@@ -138,8 +146,7 @@ def build_composite_bloq(
138146
'phase_estimate': phase_estimate,
139147
'system': system,
140148
'walk_ancilla': walk_ancilla,
141-
'guide_ancilla': guide_ancilla,
142-
}
149+
} | soqs
143150

144151

145152
@bloq_example

qualtran/bloqs/max_k_xor_sat/kikuchi_adjacency_list_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_cost_col_kth_nz():
4848
bloq = _col_kth_nz_symb()
4949
cost = get_cost_value(bloq, QECGatesCost())
5050
assert cost == GateCounts(
51-
toffoli=2 * m * logn,
51+
toffoli=(m + 1) * logn,
5252
cswap=4 * l * m * (logl + 1) * logn,
5353
and_bloq=(
5454
4 * m * (logn - 1)

qualtran/bloqs/max_k_xor_sat/kikuchi_adjacency_matrix.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ def get_ctrl_system(self, ctrl_spec: 'CtrlSpec') -> tuple['Bloq', 'AddControlled
145145
def with_cv(self, *, cv: Optional[int]) -> 'Bloq':
146146
return attrs.evolve(self, cv=cv)
147147

148-
@property
149-
def ctrl_reg_name(self) -> str:
150-
return 'ctrl'
151-
152148

153149
@bloq_example
154150
def _kikuchi_matrix_entry() -> KikuchiMatrixEntry:

qualtran/bloqs/max_k_xor_sat/kikuchi_adjacency_matrix_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import sympy
1818
from attrs import evolve
1919

20-
from qualtran.resource_counting import GateCounts, get_cost_value, QECGatesCost
20+
from qualtran.resource_counting import big_O, GateCounts, get_cost_value, QECGatesCost
21+
from qualtran.symbolics import ceil, log2
2122

22-
from ...symbolics import ceil, log2
2323
from .kikuchi_adjacency_matrix import _kikuchi_matrix_entry, _kikuchi_matrix_entry_symb
2424

2525

@@ -53,7 +53,7 @@ def test_cost():
5353

5454
gc = get_cost_value(bloq, QECGatesCost())
5555
assert gc == GateCounts(
56-
cswap=512, and_bloq=1121, clifford=11358, measurement=1121, rotation=ANY
56+
cswap=512, and_bloq=1301, clifford=11550, measurement=1301, rotation=ANY
5757
)
5858

5959

@@ -72,6 +72,7 @@ def test_cost_symb():
7272
and_bloq=(
7373
4 * l * ((2 * logn + 1) * (logl + 1))
7474
+ 4 * l
75+
+ 2 * m * (k * logn - 1)
7576
+ 2 * m
7677
+ 4 * ((2 * l - 1) * (logn - 1))
7778
+ logm
@@ -83,4 +84,4 @@ def test_cost_symb():
8384
measurement=ANY,
8485
)
8586

86-
# TODO check: soft_O(m logn)
87+
assert big_O(gc.total_t_count()) == big_O(l * logn * logl + k * m * logn)

qualtran/bloqs/max_k_xor_sat/load_kxor_instance.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,3 @@ def get_ctrl_system(self, ctrl_spec: 'CtrlSpec') -> tuple['Bloq', 'AddControlled
346346

347347
def with_cv(self, *, cv: Optional[int]) -> 'Bloq':
348348
return evolve(self, cv=cv)
349-
350-
@property
351-
def ctrl_reg_name(self) -> str:
352-
return 'ctrl'

qualtran/bloqs/max_k_xor_sat/planted_noisy_kxor_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def rng():
3434
return np.random.default_rng(42)
3535

3636

37+
@pytest.mark.xfail
3738
def test_alice_thm_symb():
3839
n, m = sympy.symbols("n m", positive=True, integer=True)
3940
k = sympy.symbols("k", positive=True, integer=True, even=True)

qualtran/bloqs/max_k_xor_sat/resource/phase_gradient.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import attrs
1717
import numpy as np
18-
import sympy
1918

2019
from qualtran import Bloq, ConnectionT, DecomposeTypeError, QDType, QFxp, Register, Side, Signature
2120
from qualtran.bloqs.bookkeeping._bookkeeping_bloq import _BookkeepingBloq

qualtran/bloqs/max_k_xor_sat/shims.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from typing import Optional
1515

1616
import attrs
17-
import sympy
1817
from attrs import frozen
1918

2019
from qualtran import (
@@ -98,18 +97,6 @@ def generalize_1_2_qubit_gates(b: Bloq) -> Optional[Bloq]:
9897
return b
9998

10099

101-
big_O = sympy.Function('O')
102-
"""Placeholder for big-O notation
103-
104-
sympy.Order is buggy:
105-
- for multivariate limits, it only allows all equal limit points.
106-
- breaks when new variables are introduced.
107-
"""
108-
109-
soft_O = sympy.Function(r'\tilde{O}')
110-
"""Placeholder for soft-O notation (big-O up to polylog factors)"""
111-
112-
113100
@frozen
114101
class ProbabilisticUncompute(Bloq):
115102
"""Probabilistically uncompute a register using hadamards, and mark success in a flag qubit

qualtran/bloqs/mcmt/bloq_with_specialized_single_qubit_control.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ def cv(self) -> Optional[int]:
3030
def with_cv(self, *, cv: Optional[int]) -> 'Bloq':
3131
...
3232

33-
@property
34-
def ctrl_reg_name(self) -> str:
35-
...
36-
3733

3834
def get_ctrl_system_for_bloq_with_specialized_single_qubit_control(
39-
bloq: 'BloqWithSpecializedControl', ctrl_spec: 'CtrlSpec'
35+
bloq: 'BloqWithSpecializedControl', ctrl_spec: 'CtrlSpec', *, ctrl_reg_name: str = 'ctrl'
4036
) -> tuple['Bloq', 'AddControlledT']:
4137
from qualtran import Bloq, CtrlSpec, Soquet
4238
from qualtran.bloqs.mcmt import ControlledViaAnd
@@ -57,8 +53,12 @@ def _adder(
5753
bb: 'BloqBuilder', ctrl_soqs: Sequence['SoquetT'], in_soqs: dict[str, 'SoquetT']
5854
) -> tuple[Iterable['SoquetT'], Iterable['SoquetT']]:
5955
(ctrl,) = ctrl_soqs
60-
ctrl, *out_soqs = bb.add_t(ctrl_bloq, ctrl=ctrl, **in_soqs)
61-
return [ctrl], out_soqs
56+
in_soqs |= {ctrl_reg_name: ctrl}
57+
58+
out_soqs = bb.add_d(ctrl_bloq, **in_soqs)
59+
60+
ctrl = out_soqs.pop(ctrl_reg_name)
61+
return [ctrl], out_soqs.values()
6262

6363
else:
6464
# the difficult case: must combine the two controls into one

0 commit comments

Comments
 (0)