qibo
qibo copied to clipboard
Transpiler refactor
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. Qubiti
corresponds to the physical qubit namedwire_names[i]
.
Circuit
-
wire_names
can now contain bothstr
andint
. 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 thewire_names
in the circuit. -
Placer
calculates the placement based onconnectivity
andcircuit
. It updates thewire_names
directly with no return value. -
Router
does routing based onconnectivity
andcircuit
, returning anew_circuit
andfinal_mapping
.
Discussion
1
How should we handle cases where a user adds multiple Placer
s? 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 theconnectivity
.
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.