Skip to content

BugFix in gate counts for QROAMClean for small log_block_sizes #1634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions qualtran/bloqs/cryptography/ecc/ec_add_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,8 @@ def test_ec_add_small(bloq_autotester):
@pytest.mark.notebook
def test_notebook():
qlt_testing.execute_notebook('ec_add')


def test_ec_add_small_gate_cost():
bloq = _ec_add_small.make()
assert get_cost_value(bloq, QECGatesCost()).toffoli == 29
4 changes: 4 additions & 0 deletions qualtran/bloqs/data_loading/qroam_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def build_call_graph(self, ssa: 'SympySymbolAllocator') -> 'BloqCountDictT':
block_sizes = prod([2**k for k in self.log_block_sizes])
data_size = prod(self.data_shape)
n_toffoli = ceil(data_size / block_sizes) + block_sizes - 4 + self.num_controls
if not is_symbolic(n_toffoli):
n_toffoli = max(0, n_toffoli)
return {Toffoli(): n_toffoli}

@cached_property
Expand Down Expand Up @@ -278,6 +280,8 @@ def build_call_graph(self, ssa: 'SympySymbolAllocator') -> 'BloqCountDictT':
block_sizes = prod([2**k for k in self.log_block_sizes])
data_size = prod(self.qroam_clean.data_shape)
n_toffoli = ceil(data_size / block_sizes) + block_sizes - 4 + self.qroam_clean.num_controls
if not is_symbolic(n_toffoli):
n_toffoli = max(0, n_toffoli)
return {Toffoli(): n_toffoli}

def adjoint(self) -> 'QROAMClean':
Expand Down
16 changes: 16 additions & 0 deletions qualtran/bloqs/data_loading/qroam_clean_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,19 @@ def test_qroam_clean_classical_sim_multi_dataset():
target1_=vals[3],
junk_target1_=vals[5],
) == (x, y)


def test_qroam_clean_small_bloq_counts():
qroam_clean = QROAMClean(
data_or_shape=(np.array([0, 7]),),
selection_bitsizes=(1,),
target_bitsizes=(6,),
target_shapes=((),),
num_controls=0,
log_block_sizes=(0,),
)
assert qroam_clean.t_complexity().t == 0
qroam_clean_adj_wrapper = QROAMCleanAdjointWrapper(
qroam_clean=qroam_clean, log_block_sizes=(0,)
)
assert qroam_clean_adj_wrapper.t_complexity().t == 0