As far I understand, qubits in cirq are labelled by their positions on chip. For example

print( )


frozenset({GridQubit(0, 1), GridQubit(1, 9), GridQubit(0, 2), ...

I would like to get a simpler version of the above, namely a simple array of tuples for the positions of all qubits

[ (0,1), (0,2), (0,3), ..., (1,1), (1,2), (1,3), ... ]

What is the easiest way to obtain this for a given known device in cirq?

up vote 7 down vote accepted

GridQubit has comparison methods defined, so sorted will give you a list of the qubits in row-major order:

>>> sorted(
[GridQubit(0, 0), GridQubit(0, 1), [...] GridQubit(1, 9), GridQubit(1, 10)]

Once you have that, you're one list comprehension away:

>>> [(q.row, q.col) for q in sorted(]
[(0, 0), (0, 1), [...] (1, 9), (1, 10)]

Because tuples also have a default ordering, it doesn't matter whether you sort before or after the conversion:

>>> sorted((q.row, q.col) for q in
[(0, 0), (0, 1), [...] (1, 9), (1, 10)]

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.