Skip to content

Commit e235642

Browse files
authored
Variable spacing QROM should depend upon structure of different data sequences and not exact elements (#6280)
1 parent eddb2d9 commit e235642

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

cirq-ft/cirq_ft/algos/qrom.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Callable, Sequence, Tuple, Set
15+
from typing import Callable, Sequence, Tuple
1616

1717
import attr
1818
import cirq
@@ -166,14 +166,10 @@ def decompose_zero_selection(
166166
context.qubit_manager.qfree(and_ancilla + [and_target])
167167

168168
def _break_early(self, selection_index_prefix: Tuple[int, ...], l: int, r: int):
169-
global_unique_element: Set[int] = set()
170169
for data in self.data:
171170
unique_element = np.unique(data[selection_index_prefix][l:r])
172171
if len(unique_element) > 1:
173172
return False
174-
global_unique_element.add(unique_element[0])
175-
if len(global_unique_element) > 1:
176-
return False
177173
return True
178174

179175
def nth_operation(

cirq-ft/cirq_ft/algos/qrom_test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ def test_qrom_variable_spacing():
141141
assert cirq_ft.t_complexity(cirq_ft.QROM.build(data)).t == (8 - 2) * 4
142142
# Works as expected when multiple data arrays are to be loaded.
143143
data = [1, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5]
144+
# (a) Both data sequences are identical
144145
assert cirq_ft.t_complexity(cirq_ft.QROM.build(data, data)).t == (5 - 2) * 4
145-
assert cirq_ft.t_complexity(cirq_ft.QROM.build(data, 2 * np.array(data))).t == (16 - 2) * 4
146+
# (b) Both data sequences have identical structure, even though the elements are not same.
147+
assert cirq_ft.t_complexity(cirq_ft.QROM.build(data, 2 * np.array(data))).t == (5 - 2) * 4
146148
# Works as expected when multidimensional input data is to be loaded
147149
qrom = cirq_ft.QROM.build(
148150
np.array(

0 commit comments

Comments
 (0)