Skip to content
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

Fix QROAMClean sum logic when determining total bitsize #1302

Merged
merged 5 commits into from
Aug 20, 2024
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
8 changes: 4 additions & 4 deletions qualtran/bloqs/data_loading/qroam_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def build_from_bitsize(

@log_block_sizes.default
def _default_log_block_sizes(self) -> Tuple[SymbolicInt, ...]:
target_bitsize = sum(self.target_bitsizes) * sum(
prod(shape) for shape in self.target_shapes
target_bitsize = sum(
bs * prod(shape) for (bs, shape) in zip(self.target_bitsizes, self.target_shapes)
)
return tuple(
get_optimal_log_block_size_clean_ancilla(ilen, target_bitsize, adjoint=True)
Expand Down Expand Up @@ -256,8 +256,8 @@ def _target_reg_side(self) -> Side:

@log_block_sizes.default
def _default_log_block_sizes(self) -> Tuple[SymbolicInt, ...]:
target_bitsize = sum(self.target_bitsizes) * sum(
prod(shape) for shape in self.target_shapes
target_bitsize = sum(
bs * prod(shape) for (bs, shape) in zip(self.target_bitsizes, self.target_shapes)
fdmalone marked this conversation as resolved.
Show resolved Hide resolved
)
return tuple(
get_optimal_log_block_size_clean_ancilla(ilen, target_bitsize)
Expand Down
14 changes: 14 additions & 0 deletions qualtran/bloqs/data_loading/qroam_clean_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from qualtran.bloqs.data_loading.qroam_clean import (
_qroam_clean_multi_data,
_qroam_clean_multi_dim,
get_optimal_log_block_size_clean_ancilla,
QROAMClean,
QROAMCleanAdjoint,
)
Expand Down Expand Up @@ -61,6 +62,19 @@ def test_t_complexity_2d_data_symbolic():
assert bloq_inv.t_complexity().t == 4 * expected_toffoli_inv


@pytest.mark.parametrize('n', range(3, 8))
def test_qroam_default_log_block_sizes(n: int):
data = np.arange(2**n)
bloq = QROAMClean.build_from_data(data, data, target_bitsizes=(n.bit_length(), n.bit_length()))
bs = get_optimal_log_block_size_clean_ancilla(len(data), sum(bloq.target_bitsizes))
assert bs == bloq.log_block_sizes[0]
bloq = bloq.adjoint()
bs = get_optimal_log_block_size_clean_ancilla(
len(data), sum(bloq.target_bitsizes), adjoint=True
)
assert bs == bloq.log_block_sizes[0]


def test_qroam_clean_classical_sim():
rng = np.random.default_rng(42)
# 1D data, 1 dataset
Expand Down
Loading