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 support to CouplingMap for disjoint qubits (Qiskit#9710)
* Add support to CouplingMap for disjoint qubits Previously the CouplingMap class only supported graphs which were fully connected. This prevented us from modeling potential hardware which didn't have a path between all qubits. This isn't an inherent limitation of the underlying graph data structure but was a limitation put on the CouplingMap class because several pieces of the transpiler assume a path always exists between 2 qubits (mainly in layout and routing). This commit removes this limitation and also adds a method to get a subgraph CouplingMap for all the components of the CouplingMap. This enables us to model these devices with a CouplingMap, which is the first step towards supporting these devices in the transpiler. One limitation with this PR is most fo the layout and routing algorithms do not support disjoint connectivity. The primary exception being TrivialLayout (although the output might be invalid) VF2Layout and VF2PostLayout which inherently support this already. This commit lays the groundwork to fix this limitation in a follow-up PR but for the time being it just raises an error in those passes if a disconnected CouplingMap is being used. The intent here is to follow up to this commit soon for adding support for SabreLayout, SabreSwap, DenseLayout, and StochasticSwap to leverage the method get_component_subgraphs added here to make them usable on such coupling maps. * Remove coupling map connected check from NoiseAdaptiveLayout Noise adaptive layout doesn't use a CouplingMap so we can't check for a disconnected coupling map in it. * Change DenseLayout guard to only prevent running when it won't work * Rename get_component_subgraphs to components and cache result This commit renames the get_component_subgraphs() method to components() which is much more consise name. At the same time this adds caching to the return just in case building the component subgraphs is expensive to compute we only need to ever do it once. * Drop caching of connected components * Fix check for dense layout to do a valid comparison * Ensure self loops in CouplingMap.distance() return 0 In a previous commit the distance() method was updated to handle disjoint graphs correctly. Prior to this PR it was expected to raise when a path didn't exist between 2 qubits by nature of the distance matrix construction failing if there was a disconnected coupling map. Since that isn't the case after this PR the error condition was changed to check explicitly that there is no path available and then error. However, there was an issue in this case and self loops would incorrectly error as well when instead they should return 0. This commit updates the error check to ignore self loops so they return correctly. * Fix lint * Update CouplingMap.components() docstring Co-authored-by: Kevin Krsulich <kevin@krsulich.net> * Expand test coverage * Remove unused option for strongly connected components * Expand docstring to explain return list order * Use infinity for disconnected nodes in distance matrix * Update releasenotes/notes/add-cmap-componets-7ed56cdf294150f1.yaml * Rename CouplingMap.components to connected_components() THis commit renames the CouplingMap.components() method to connected_components(). It also adds an example to the docstring to better explain what a connected component is. * Fix typo in relaese note * Update method name in release note * Restore previous reduce() behavior The current reduce() error behavior of raising on trying to reduce to a disconnected coupling map is being depended on in other locations. To avoid a potentially breaking change this commit reverts the removal of that limitation in the method. We can look at doing that in the future independently of this PR because removing this specific restriction on the reduce() method is not 100% tied to generally allowing disconnected coupling map objects. * Add missing import --------- Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
- Loading branch information
1 parent
f122985
commit ef26ffd
Showing
7 changed files
with
172 additions
and
7 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
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
14 changes: 14 additions & 0 deletions
14
releasenotes/notes/add-cmap-componets-7ed56cdf294150f1.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,14 @@ | ||
--- | ||
features: | ||
- | | ||
Added support to the :class:`~.CouplingMap` object to have a disjoint | ||
connectivity. Previously, a :class:`~.CouplingMap` could only be | ||
constructed if the graph was connected. This will enable using | ||
:class:`~.CouplingMap` to represent hardware with disjoint qubits, such as hardware | ||
with qubits on multiple separate chips. | ||
- | | ||
Added a new method :meth:`.CouplingMap.connected_components` which | ||
is used to get a list of :class:`~.CouplingMap` component subgraphs for | ||
a disjoint :class:`~.CouplingMap`. If the :class:`~.CouplingMap` object | ||
is connected this will just return a single :class:`~.CouplingMap` | ||
equivalent to the original. |
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