Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the ergonomics of the TranspileLayout class (Qiskit#10835)
* Improve the ergonomics of the TranspileLayout class This commit updates the TranspileLayout class to make it easier to work with. The TranspileLayout class was orginally just an a container class that took the information returned from the transpiler needed to reverse the transpiler layout permutation (in the absence of ancillas) so that `QuantumCircuit.from_circuit()` could compare Operator instances across a `transpile()`. However, the internal data structures used by the transpiler are hard to work with, and don't map well to the normal reasoning around how the transpiler transforms the circuit. To improve the usability of the class this commit adds 4 new methods to the class: - initial_layout_list() and final_layout_list() which compute a list form of the initial_layout and final_layout respectively - full_layout() which generates a list that maps the input circuits qubit positions in the input circuit to the final position at the end of the circuit (which is what most people think of when they hear "final layout") - permute_sparse_pauli_op() which takes in a SparsePauliOp object and permutes it based on the full layout. This is especially useful when combined with the Estimator primitive To implement these functions a few extra pieces of information are needed to fully implement them. The first is we need to know the number of original circuit qubits. This is used to account for any ancillas that are added in the circuit, once we have the input circuit count we can use the original_qubit_indices attribute to discern which qubits in the initial layout are from the original circuit and which are ancillas. The second piece of information needed is the list of qubits in the output circuit. as this is needed to look up the position of the virtual qubit in the final_layout. These are both added as optional private attributes to the TranspileLayout class and there are some small changes to the pass manager and QPY to accomodate them. Similarly the change in the TranspileLayout class requires a new QPY version to include the missing details that were not being serialized in QPY and weren't representable in the previous payload format. Fixes Qiskit#10826 Fixes Qiskit#10818 * Handle None for the private TranspileLayout fields in QPY * Add test for full_layout with ancillas * Rework interface to be more consistent This commit reworks the names of the new methods added in this API to be more self consistent. It uses the format '*_index_layout' to replace the `*_layout_list` name. Similarly new methods `*_virtual_layout` are added for methods that return layout objects. * Apply suggestions from code review Co-authored-by: Jake Lishman <[email protected]> * Remove permute_sparse_pauli_op() This commit remove the TranspileLayout.permute_sparse_pauli_op() method. This was a bit out of place on the TranspileLayout class, and it will instead be replaced in a follow-up PR by a apply_layout() method on the SparePauliOp class that takes in a TranspileLayout object. * Update docs * Fix docs build post-rebase * Fix docs issues --------- Co-authored-by: Jake Lishman <[email protected]>
- Loading branch information