Skip to content

Commit

Permalink
Variable spacing QROM should depend upon structure of different data …
Browse files Browse the repository at this point in the history
…sequences and not exact elements (#6280)
  • Loading branch information
tanujkhattar authored Sep 6, 2023
1 parent eddb2d9 commit e235642
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 1 addition & 5 deletions cirq-ft/cirq_ft/algos/qrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Callable, Sequence, Tuple, Set
from typing import Callable, Sequence, Tuple

import attr
import cirq
Expand Down Expand Up @@ -166,14 +166,10 @@ def decompose_zero_selection(
context.qubit_manager.qfree(and_ancilla + [and_target])

def _break_early(self, selection_index_prefix: Tuple[int, ...], l: int, r: int):
global_unique_element: Set[int] = set()
for data in self.data:
unique_element = np.unique(data[selection_index_prefix][l:r])
if len(unique_element) > 1:
return False
global_unique_element.add(unique_element[0])
if len(global_unique_element) > 1:
return False
return True

def nth_operation(
Expand Down
4 changes: 3 additions & 1 deletion cirq-ft/cirq_ft/algos/qrom_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ def test_qrom_variable_spacing():
assert cirq_ft.t_complexity(cirq_ft.QROM.build(data)).t == (8 - 2) * 4
# Works as expected when multiple data arrays are to be loaded.
data = [1, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5]
# (a) Both data sequences are identical
assert cirq_ft.t_complexity(cirq_ft.QROM.build(data, data)).t == (5 - 2) * 4
assert cirq_ft.t_complexity(cirq_ft.QROM.build(data, 2 * np.array(data))).t == (16 - 2) * 4
# (b) Both data sequences have identical structure, even though the elements are not same.
assert cirq_ft.t_complexity(cirq_ft.QROM.build(data, 2 * np.array(data))).t == (5 - 2) * 4
# Works as expected when multidimensional input data is to be loaded
qrom = cirq_ft.QROM.build(
np.array(
Expand Down

0 comments on commit e235642

Please sign in to comment.