5
$\begingroup$

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

print( cirq.google.Foxtail.qubits )

yields

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?

$\endgroup$
7
$\begingroup$

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

>>> sorted(cirq.google.Foxtail.qubits)
[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(cirq.google.Foxtail.qubits)]
[(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 cirq.google.Foxtail.qubits)
[(0, 0), (0, 1), [...] (1, 9), (1, 10)]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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