qiskit-community / qiskit-community/mapomatic
Deflate circuit should retain qubit register ordering to prevent incorrect mapping upon transpilation to new layout
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 64
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
As an example, consider a logical circuit (circuit A) with logical qubits 0, 1, and 2. Let's assume there's only one two-qubit gate between logical qubits 0 and 2. Therefore, optimal transpilation to a physical architecture with nearest-neighbor coupling between physical qubits will result in a circuit (circuit B) with e.g. logical qubit 0, 1, and 2 mapping to physical qubits 0, 2, and 1.
Now, say we want to use mapomatic to find the best qubits on said device. The standard procedure in the README is to first deflate the circuit (to circuit C). This results in a circuit with three logical qubits labelled, in order, 0, 1, and 2--note that the original qubit register ordering has been lost! So say we find that the best physical qubits are 3, 4, and 5 for logical qubits 0, 2, and 1 that have been mistakenly labelled 0, 1, and 2 by mm.deflate_circuits as qubits 0, 1, and 2. If we now re-transpile not the deflated circuit (circuit C), but the original transpiled circuit (circuit B) onto this new layout, because the qubit ordering has been lost, we'll find that logical qubits 0, 1, and 2 will be mapped onto physical qubits 3, 4, and 5. But we know that logical qubits 0 and 2 have a 2Q gate, so because qubits 3 and 5 are not directly coupled, transpilation will necessarily add a (costly) SWAP! Note, however, that the logical circuit is preserved, however, because the ordering of the classical registers does not get lost during deflation, which may contribute to why this issue had no been previously noticed.
And finally, one can argue that one should not use the "best" layout found for circuit C on another circuit (circuit B, or an entirely differently circuit D), so one could just apply this new layout directly on the deflated circuit (circuit C) and avert these problems. However, it is often the case that one finds the best layout for one circuit and uses that circuit again and again with different parameters (say, in a variational problem) or repeated different times (say, for time evolution). In these cases, the circuit has the same coupling map and the evaluated cost function is likely to result in the same layout for different parameters/repetition number, so it is advantageous to just use mapomatic one time on one prototypical circuit and then transpile all other circuits to the same layout.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the README workflow and the mm.deflate_circuits entry point described in the issue. Reproduce the circuit A/B/C example with reordered logical qubits, then trace how qubit and classical-register ordering is represented. Done means deflation preserves the original qubit mapping so a layout selected for the deflated circuit can be reused without introducing an avoidable SWAP.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100