# cirq.experiments.build_entangling_layers

Builds a sequence of gates that entangle all pairs of qubits on a grid.

The qubits are restricted to be physically on a square grid with distinct row and column indices (not every node of the grid needs to have a qubit). To entangle all pairs of qubits, a user-specified two-qubit gate is applied between each and every pair of qubit that are next to each other. In general, a total of four sets of parallel operations are needed to perform all possible two-qubit gates. We proceed as follows:

The first layer applies two-qubit gates to qubits (i, j) and (i, j + 1) where i is any integer and j is an even integer. The second layer applies two-qubit gates to qubits (i, j) and (i + 1, j) where i is an even integer and j is any integer. The third layer applies two-qubit gates to qubits (i, j) and (i, j + 1) where i is any integer and j is an odd integer. The fourth layer applies two-qubit gates to qubits (i, j) and (i + 1, j) where i is an odd integer and j is any integer.

After the layers are built as above, any empty layer is ejected.:

``````         Cycle 1:                            Cycle 2:
q00 ── q01    q02 ── q03            q00    q01    q02    q03
|      |      |      |
q10 ── q11    q12 ── q13            q10    q11    q12    q13

q20 ── q21    q22 ── q23            q20    q21    q22    q23
|      |      |      |
q30 ── q31    q32 ── q33            q30    q31    q32    q33

Cycle 3:                           Cycle 4:
q00    q01 ── q02    q03            q00    q01    q02    q03

q10    q11 ── q12    q13            q10    q11    q12    q13
|      |      |      |
q20    q21 ── q22    q23            q20    q21    q22    q23

q30    q31 ── q32    q33            q30    q31    q32    q33
``````

`qubits` The grid qubits included in the entangling operations.
`two_qubit_gate` The two-qubit gate to be applied between all neighboring pairs of qubits.

A list of ops.Moment, with a maximum length of 4. Each ops.Moment includes two-qubit gates which can be performed at the same time.

`ValueError` two-qubit gate is not used.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]