quantumlib / Qualtran

Qᴜᴀʟᴛʀᴀɴ is a Python library for expressing and analyzing Fault Tolerant Quantum algorithms.
https://qualtran.readthedocs.io/en/latest/
Apache License 2.0
132 stars 35 forks source link

Rough edges when swapping QROM for SelectSwapQROM in StatePreparationViaRotation #1019

Closed wjhuggins closed 1 month ago

wjhuggins commented 1 month ago

I was trying to see what would happen to the resource counts if I replaced QROM with SelectSwapQROM in StatePreparationViaRotation and I ran into an issue. A drop in replacement doesn't work. It fails in a way that is captured in this MWE:

import numpy as np

from qualtran.bloqs.data_loading.qrom import QROM
from qualtran.bloqs.data_loading.select_swap_qrom import SelectSwapQROM

data = np.array([1])
selection_bitsize = 0
target_bitsize = 2
control_bitsize = 1

qrom = QROM(
    [data],
    selection_bitsizes=(selection_bitsize,),
    target_bitsizes=(target_bitsize,),
    num_controls=control_bitsize,
)

select_swap_qrom = SelectSwapQROM(
    [data],
    selection_bitsizes=(selection_bitsize,),
    target_bitsizes=(target_bitsize,),
    num_controls=control_bitsize,
)
fdmalone commented 1 month ago

This looks like a case where a more sensible error should be raised, does SelectSwapQROM make sense with a length 1 array (I think the answer is it should handle it gracefully).