BQSKit / bqskit

Berkeley Quantum Synthesis Toolkit
Other
106 stars 31 forks source link

Usign the with_mapping=True option in bqskit.compiler() does not return a full mapping when no qubits are remapped #253

Open n-ion opened 1 week ago

n-ion commented 1 week ago

When running bqskit.compile() with the with_mapping=True parameter, if the compiler does not do any qubit re-mapping or re-routing, then the returned values of initial_mapping and final_mapping appear to be [0], instead of a list with length equal to the number of qubits. Would it be better to return the initial unremapped layout instead for consistency?

For example, the following circuit, when compiled with optimization level 1 or 2 does not seem to cause any re-mapping or re-routing.

     ┌───┐      
q_0: ┤ X ├──────
     └─┬─┘┌────┐
q_1: ──┼──┤ √X ├
       │  └────┘
q_2: ──■────────

The compiler therefore returns [0] for both initial_mapping and final_mapping .

However, when compiled with optimization level 4, some re-mapping occured and the compiler returned [0, 1, 2] for initial_mapping and [2, 1, 0] for final_mapping (I assume this is only one possible remapping, it could change from run to run).

In this scenario, would it be more consistent if the returned value for initial_mapping and final_mapping in the optimization level 1 case was just [0, 1, 2]?

edyounis commented 1 week ago

Yes, definitely! Good catch. We should be returning the trivial mapping in the case where nothing is done. Is this something you would be interested in fixing?

Looking at this line, I would expect this to be the case already. It seems this is, therefore, a bug.