Skip to content

Commit ed26d2f

Browse files
authored
Fix ordering issue in random_rotations_between_grid_interaction_layers_circuit (#6261)
1 parent 7ed95aa commit ed26d2f

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

cirq-core/cirq/experiments/random_quantum_circuit_generation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -693,5 +693,5 @@ def _two_qubit_layer(
693693
prng: 'np.random.RandomState',
694694
) -> 'cirq.OP_TREE':
695695
for a, b in coupled_qubit_pairs:
696-
if (a, b) in layer:
696+
if (a, b) in layer or (b, a) in layer:
697697
yield two_qubit_op_factory(a, b, prng)

cirq-core/cirq/experiments/random_quantum_circuit_generation_test.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,30 @@ def __init__(self):
259259
'seed, expected_circuit_length, single_qubit_layers_slice, '
260260
'two_qubit_layers_slice',
261261
(
262+
(
263+
(cirq.q(0, 0), cirq.q(0, 1), cirq.q(0, 2)),
264+
4,
265+
lambda a, b, _: cirq.CZ(a, b),
266+
[[(cirq.q(0, 0), cirq.q(0, 1))], [(cirq.q(0, 1), cirq.q(0, 2))]],
267+
(cirq.X**0.5,),
268+
True,
269+
1234,
270+
9,
271+
slice(None, None, 2),
272+
slice(1, None, 2),
273+
),
274+
(
275+
(cirq.q(0, 0), cirq.q(0, 1), cirq.q(0, 2)),
276+
4,
277+
lambda a, b, _: cirq.CZ(a, b),
278+
[[(cirq.q(0, 1), cirq.q(0, 0))], [(cirq.q(0, 1), cirq.q(0, 2))]],
279+
(cirq.X**0.5,),
280+
True,
281+
1234,
282+
9,
283+
slice(None, None, 2),
284+
slice(1, None, 2),
285+
),
262286
(
263287
cirq.GridQubit.rect(4, 3),
264288
20,
@@ -406,7 +430,10 @@ def _validate_two_qubit_layers(
406430
# Operation is two-qubit
407431
assert cirq.num_qubits(op) == 2
408432
# Operation fits pattern
409-
assert op.qubits in pattern[i % len(pattern)]
433+
assert (
434+
op.qubits in pattern[i % len(pattern)]
435+
or op.qubits[::-1] in pattern[i % len(pattern)]
436+
)
410437
active_pairs.add(op.qubits)
411438
# All interactions that should be in this layer are present
412439
assert all(

0 commit comments

Comments
 (0)