1
$\begingroup$

The question concerns logical to physical qubit mapping when compiling quantum circuits with BQSKit. In Qiskit, I can specify the initial layout for the transpilation. It is also possible to retrieve the final layout. With Qiskit Transpiler and BQSKit Compiler, the final layout generally differs from the initial layout because the compiler can permute logical qubits. My question is whether I can specify the initial layout and retrieve the final layout with BQSKit.

I found the following way to retrieve the final layout:

 1. Add measurements on all active qubits of a Qiskit circuit.
 2. Compile the circuit with BQSKit.
 3. Translate back to Qiskit and draw.
 4. Read out the mapping from the positions of final measurements. 
 5. Notice that q1 and q2 are permuted at the end.

enter image description here

However, I am interested in a programmatic solution.

$\endgroup$

2 Answers 2

2
$\begingroup$

This is an awesome question about BQSKit. Currently, the off-the-shelf (bqskit.compile) workflows do not provide a mechanism for this besides what you have discovered yourself.

If you would like to force an initial layout, you can design your own workflow that provides a value for the initial_mapping key in the pass's data, then perform routing. You can see the layout passes here for examples.

If you build a workflow yourself and compile a circuit with it, you can request the initial_mapping and final_mapping data members to get these results programmatically.

If you make a GitHub issue on the BQSKit page requesting easier access here, I am sure the developers will accommodate that quickly.

$\endgroup$
1
$\begingroup$

I find the following solution, which might help you as well:

You can make the following modifications to /BQSKit/compiler/passes/mapping/routing/sabre.py:

(1) add this line: import numpy as np to the beginning of this file;
(2) add this line: np.save('final_mapping.npy', data['final_mapping']) to the end of this file.

These modifications help us save the map from logical qubits to physical qubits as a file. After making these modifications and performing the compilation that you want, the final map (namely the layout of qubits) can be readout using the following instructions:

import numpy as np
final_mapping = np.load('final_mapping.npy')
print("the indexes of physical qubits that correspond to logical qubits 1, 2, ..., end are:", final_mapping)
$\endgroup$
1
  • $\begingroup$ Thank you, I will try it out! $\endgroup$ Commented May 7, 2023 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.