Skip to content

Commit

Permalink
Fix ordering issue in random_rotations_between_grid_interaction_layer…
Browse files Browse the repository at this point in the history
…s_circuit (#6261)
  • Loading branch information
andbe91 committed Aug 25, 2023
1 parent 7ed95aa commit ed26d2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Expand Up @@ -693,5 +693,5 @@ def _two_qubit_layer(
prng: 'np.random.RandomState',
) -> 'cirq.OP_TREE':
for a, b in coupled_qubit_pairs:
if (a, b) in layer:
if (a, b) in layer or (b, a) in layer:
yield two_qubit_op_factory(a, b, prng)
Expand Up @@ -259,6 +259,30 @@ def __init__(self):
'seed, expected_circuit_length, single_qubit_layers_slice, '
'two_qubit_layers_slice',
(
(
(cirq.q(0, 0), cirq.q(0, 1), cirq.q(0, 2)),
4,
lambda a, b, _: cirq.CZ(a, b),
[[(cirq.q(0, 0), cirq.q(0, 1))], [(cirq.q(0, 1), cirq.q(0, 2))]],
(cirq.X**0.5,),
True,
1234,
9,
slice(None, None, 2),
slice(1, None, 2),
),
(
(cirq.q(0, 0), cirq.q(0, 1), cirq.q(0, 2)),
4,
lambda a, b, _: cirq.CZ(a, b),
[[(cirq.q(0, 1), cirq.q(0, 0))], [(cirq.q(0, 1), cirq.q(0, 2))]],
(cirq.X**0.5,),
True,
1234,
9,
slice(None, None, 2),
slice(1, None, 2),
),
(
cirq.GridQubit.rect(4, 3),
20,
Expand Down Expand Up @@ -406,7 +430,10 @@ def _validate_two_qubit_layers(
# Operation is two-qubit
assert cirq.num_qubits(op) == 2
# Operation fits pattern
assert op.qubits in pattern[i % len(pattern)]
assert (
op.qubits in pattern[i % len(pattern)]
or op.qubits[::-1] in pattern[i % len(pattern)]
)
active_pairs.add(op.qubits)
# All interactions that should be in this layer are present
assert all(
Expand Down

0 comments on commit ed26d2f

Please sign in to comment.