qibo icon indicating copy to clipboard operation
qibo copied to clipboard

Transpiler refactor

Open csookim opened this issue 4 months ago • 5 comments

This covers issue #1493.

This PR updates the qubit representation in qibo to support hardware execution after transpilation. Circuit.wire_names and Gate.qubits will be used on the hardware side.

Terms

  • physical qubit = qubit name = Circuit.wire_names: list[str | int]
  • logical qubit = qubit index = Gate.qubits: Tuple[int, ...]
  • connectivity = nx.Graph
  • mapping = qubit layout

Updates

  • Removed initial_layout, which was used to represent the mapping between {physical qubit: logical qubit}.
  • wire_names itself serves as the mapping. Qubit i corresponds to the physical qubit named wire_names[i].

Circuit

  • wire_names can now contain both str and int. If None, default is ["q0", "q1", ...].

Transpiler

  • To transpile a circuit, the user must provide connectivity representing the hardware.
  • Node names in connectivity must match the wire_names in the circuit.
  • Placer calculates the placement based on connectivity and circuit. It updates the wire_names directly with no return value.
  • Router does routing based on connectivity and circuit, returning a new_circuit and final_mapping.

Discussion

1

How should we handle cases where a user adds multiple Placers? This doesn’t impact the transpiler. In the previous approach, Passes generated an error.

2

If #qubits in the circuit is different from #nodes in the connectivity, users have two explicit options for transpilation:

  • Use the Preprocessor to automatically add qubits.
  • Use on_qubits to restrict the connectivity.

Then, Is it acceptable for all Placer and Router components to enforce that the input #qubits and #nodes must be the same? Previously, some components had this restriction while others did not.

3

In this implementation, the Placer only changes the order of the names.

# Original Circuit
A: ─o───
B: ─Z─o─
C: ───|─
D: ───Z─
E: ─────

# After Placer
B: ─o───
C: ─Z─o─
A: ───|─
E: ───Z─
D: ─────

Should we also change the wires accordingly?

A: ─────
B: ─o───
C: ─Z─o─
D: ───|──
E: ───Z─

Checklist:

  • [ ] Reviewers confirm new code works as expected.
  • [ ] Tests are passing.
  • [ ] Coverage does not decrease.
  • [ ] Documentation is updated.

csookim avatar Oct 22 '24 13:10 csookim