Open steve-jeffrey opened 2 years ago
Quilc appears to return rewiring in two forms:
Index: 0 1 2 3 4 5 6 7 8 9
| | |
Value: 0 2 4 3 5 1 6 9 7 8
A list of integers, where the first "n" elements are the new qubit indexes, in order of the corresponding original indices arranged in ascending order. The remaining elements in the list are the unused new indexes, arranged in ascending order. For example, if the program contained qubits [8, 10, 1, 15] and the compiler rewired them to [1, 2, 10, 9] respectively, the rewiring metadata would be:
Index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Value: 10 1 2 9 0 3 4 5 6 7 8 11 12 13 14 15
| | | |
1 8 10 15 <-- Original qubit indices in ascending order
If this is correct, it explains the rewiring generated by quilc
.
The attached code can be used to generate rewiring metadata to test the above hypothesis. quilc_metadata_tests.py.gz
If the nodes in the Program
being compiled form a zero-based contiguous set, the rewiring metadata appear to be a simple mapping, and the two formats shown above become equivalent.
The rewiring metadata returned by the compiler appears to be incorrect in some cases. The metadata are stored in the
metadata.final_rewiring
field of the response from the gRPC call:response = self._compiler_client.compile_to_native_quil(request)
in functionquil_to_native_quil
in filepyquil.api.abstractcompiler.py
.The test codes and output below demonstrate three cases:
Case 1. The metadata are correct and the mapping between logical and physical qubit IDs is given by:
physical qubit ID = final_rewiring[local_qubit_ID]
. This interpretation appears to agree with the documentation.Code:
Output:
For example, logical qubit 22 (see the original program above) has been mapped to physical qubit 5:
final_rewiring[22] = 5
Case 2. The metadata returned by the compiler needs to be remapped as follows:
physical qubit ID = final_rewiring[ID]
, whereID
is the index of the logical qubit in an array containing all qubits, arranged in order of qubit ID.Note: the mapping shown below can be used when: (i) all lattice qubits are used; or (ii) the device (and compiler ISA) are reduced to a subset of the full qubit lattice, and the the user program uses all qubits in the selected sub-lattice.
Code:
Output:
The remapped metadata appear to be correct.
Case 3. I cannot see how to interpret or remap the metadata.
Code:
Output:
It is not clear how the rewiring metadata can be interpreted.