1

I am trying to familiarise myself with Cirq, and I came across something I don't know how to code.

I would like to define two sets of qubits as follows: say the number of qubits in set 1 and 2 are both 3, then I would like my qubits in set 1 to be [cirq.GridQubit(0,0), cirq.GridQubit(0,1), cirq.GridQubit(0,2)] and my qubits in set 2 to be [cirq.GridQubit(1,0), cirq.GridQubit(1,1), cirq.GridQubit(1,2)]. I would like to be able to generalise this for an arbitrary number of qubits. In other words, I would like to be able to refer to a qubit in set 1 as cirq.GridQubit(0,i), and to a qubit in set 2 as cirq.GridQubit(1,j), for 0≤i<number of qubits in set 1 and 0≤j<number of qubits in set 2.

I can create my first set of qubits using qubits_set1 = cirq.GridQubit.rect(1, number_qubits_set1), but I am not sure how to create the second set?

Many thanks!

Q.Ask
  • 195
  • 6

1 Answers1

2

You can do this using the top keyword argument for cirq.GridQubit.rect which controls the starting index value for the first (topmost) row of the rectangle is indexed from:

qubits_set1 = cirq.GridQubit.rect(1, num_qubits_set1, top=0)
qubits_set2 = cirq.GridQubit.rect(1, num_qubits_set2, top=1)

The left keyword provides analogous behavior for the column indexing by controlling the starting index value for the first column

forky40
  • 6,678
  • 2
  • 9
  • 30