Cirq icon indicating copy to clipboard operation
Cirq copied to clipboard

Adding easier support for GridQubits to LineQubits conversation

Open arnavdas88 opened this issue 4 years ago • 4 comments

Firstly, there should be more examples for this problem. At the very least, a good documentation would be appreciated.

Work on the function transform_qubits is needed. It is really incomplete, in the sense that it cannot be used easily for various purposes, as it lacks proper documentation.

Please change the design of the function :


transform_qubits(
    qubit_map: Union[Dict['cirq.Qid', 'cirq.Qid'], Callable[['cirq.Qid'], 'cirq.Qid']]
) -> cirq.ops.raw_types.TSelf

or add a function like :

qubit_grid_to_line(
    qubit_source: List[GridQubit]
) -> List[LineQubit]

arnavdas88 avatar Apr 11 '21 13:04 arnavdas88

Can you please provide an example where you found the conversion to be hard? As the function argument and docstring suggests, if you want to convert GridQubits to LineQubits, you need to provide an explicit mapping as there can be N! ways to map the N GridQubits to LineQubits.

This mapping can be provided by a function or a dictionary, as stated in the function definition. As an example:

In [2]: grid_qubits = cirq.GridQubit.square(2)

In [3]: line_qubits = cirq.LineQubit.range(4)

In [4]: circuit = cirq.Circuit([cirq.H(q) for q in line_qubits])

In [5]: circuit
Out[5]:
0: ───H───

1: ───H───

2: ───H───

3: ───H───

In [6]: circuit.transform_qubits(lambda q : grid_qubits[q.x])
Out[6]:
(0, 0): ───H───

(0, 1): ───H───

(1, 0): ───H───

(1, 1): ───H───

tanujkhattar avatar Apr 12 '21 13:04 tanujkhattar

The usage of the function looks easy when you put it like that...

But the documentation looks incomplete! That's the reason why i took reference from other complex codes [link] that were showing the usage of that function.

The reason why i say this:

  • The reference [link] here does not gives example for the conversions
  • Also, their are no good examples in the form of blogs / github projects that shows the usage for these functions.

How i came across these grid qubits and this function is basically during the qchack problem statement. where the whole decomposition has to done for sycamore for grid qubits. No offence, but most of my friends and colleagues doesn't even know about grid qubits... so the data about these grid qubits and qubit transformation functions are really limited, specially when there are no good examples.

So Is there something we can work on, to imporve these conditions (conditions like lack of simpler examples)???

arnavdas88 avatar Apr 17 '21 18:04 arnavdas88

I am open to have one or two example transformations in the docstring of https://quantumai.google/reference/python/cirq/ops/Operation#transform_qubits!

balopat avatar Apr 27 '21 23:04 balopat

Marking as after-1.0 since only a documentation change is necessary.

verult avatar Mar 28 '22 20:03 verult