# GridQubit in Cirq vs LineQubit

It's perhaps a very silly question, but in what ways is it advantageous to use GridQubit vs LineQubits to develop quantum circuits? Specially to develop ansatz ? Are GridQubits Cirq's way of representing lattices or possibly surface codes?

Thank you

When using a simulator, it doesn't really matter what kind of qubit you refer to. You can even mix-and-match the types. The type of qubit only becomes relevant when you intend to run on a device, because devices have qubits at specific locations.

For example, if you wanted to run on Bristlecone, you would limit yourself to GridQubit instances that actually appeared on the chip:

>>> import cirq
(0, 5)────(0, 6)
│         │
│         │
(1, 4)───(1, 5)────(1, 6)────(1, 7)
│        │         │         │
│        │         │         │
(2, 3)───(2, 4)───(2, 5)────(2, 6)────(2, 7)───(2, 8)
│        │        │         │         │        │
│        │        │         │         │        │
(3, 2)───(3, 3)───(3, 4)───(3, 5)────(3, 6)────(3, 7)───(3, 8)───(3, 9)
│        │        │        │         │         │        │        │
│        │        │        │         │         │        │        │
(4, 1)───(4, 2)───(4, 3)───(4, 4)───(4, 5)────(4, 6)────(4, 7)───(4, 8)───(4, 9)───(4, 10)
│        │        │        │        │         │         │        │        │        │
│        │        │        │        │         │         │        │        │        │
(5, 0)───(5, 1)───(5, 2)───(5, 3)───(5, 4)───(5, 5)────(5, 6)────(5, 7)───(5, 8)───(5, 9)───(5, 10)───(5, 11)
│        │        │        │        │         │         │        │        │        │
│        │        │        │        │         │         │        │        │        │
(6, 1)───(6, 2)───(6, 3)───(6, 4)───(6, 5)────(6, 6)────(6, 7)───(6, 8)───(6, 9)───(6, 10)
│        │        │        │         │         │        │        │
│        │        │        │         │         │        │        │
(7, 2)───(7, 3)───(7, 4)───(7, 5)────(7, 6)────(7, 7)───(7, 8)───(7, 9)
│        │        │         │         │        │
│        │        │         │         │        │
(8, 3)───(8, 4)───(8, 5)────(8, 6)────(8, 7)───(8, 8)
│        │         │         │
│        │         │         │
(9, 4)───(9, 5)────(9, 6)────(9, 7)
│         │
│         │
(10, 5)───(10, 6)


Whereas if you were intending to run on an ion trap which arranged qubits into a line, you would be more likely to work in terms of LineQubits.

Another situation where you would use a LineQubit is if you had an algorithm that only required linear nearest-neighbor connectivity, such as a chemistry algorithm based on an fswap network. You would define the circuit in terms of LineQubits and then use a placement pass to map the line onto the actual device, replacing LineQubits with GridQubits perhaps returned by cirq.google.line_on_device.

>>> cirq.google.line_on_device(cirq.google.Bristlecone, 10)
(cirq.GridQubit(0, 5),
cirq.GridQubit(0, 6),
cirq.GridQubit(1, 6),
cirq.GridQubit(1, 7),
cirq.GridQubit(2, 7),
cirq.GridQubit(2, 8),
cirq.GridQubit(3, 8),
cirq.GridQubit(3, 9),
cirq.GridQubit(4, 9),
cirq.GridQubit(4, 10))


Cirq defines qubits to be LineQubits or GridQubits, since these are common constructions in NISQ computers. Qubits are commonly defined in lists (or generally iterables) for easy indexing in algorithms. In simulation using either has no impact on your algorithm.

GridQubit is a qubit on a 2d square lattice.