forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add public layout attribute to QuantumCircuit (Qiskit#9486)
* Add public layout attribute to QuantumCircuit Since the Qiskit 0.9.0 release the QuantumCircuit has had a private `_layout` attribute which is used to track the permutations introduced to a circuit by the transpiler. At the time this was made private because we didn't want to commit to an interface on this at the time until a dedicated API could be introduced (see Qiskit#2853). However, since that time ~4 years ago we've never introduced an alternative public interface for `_layout` was never introduced. This has left users needing to reason about the permutation caused by transpile() in a weird place because the only mechanism to do this is private. This commit adds a public read-only attribute `.layout` to solve this, which just exposes the previously private `._layout` attribute via a documented and public interface. Unlike from 0.9.x through 0.21.x we introduced a new data class container `TranspileLayout` as part of the 0.22.0 release which _layout was updated to use at the time. Having a dedicated class used for the field gives us a certain degree of flexibility to evolve the interface over time if needed. Right now it contains 3 pieces of information the initial layout caused by the layout phase of transpile(), the input qubit mapping to figure out the qubit index on the original circuit, and the final layout caused by swaps inserted during routing. Closes Qiskit#8803 * Fix typo in QuantumCircuit.layout docs * Disable cyclic import check on conditional type hint import
- Loading branch information
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
releasenotes/notes/add-layout-attribute-c84e56c08ca93ada.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
features: | ||
- | | ||
Added a new attribute, :attr:`~.QuantumCircuit.layout`, to the | ||
:class:`~.QuantumCircuit` class. This attribute is typically populated | ||
by :func:`~.transpile` or :class:`.PassManager.run` (when the | ||
:ref:`layout_stage` and :ref:`routing_stage` are run in the | ||
:class:`~PassManager`) and contains a :class:`~.TranspileLayout` which | ||
contains the information about the permutation of the input circuit | ||
during :class:`~.transpile`. |