-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add from_heavy_hex()
and from_heavy_square()
generator methods to CouplingMap
#6959
Changes from 17 commits
1e13980
dd92051
16bba04
53c7326
504a232
8bffc75
6888da9
2ea1f0e
cd50b7a
a8a69e0
ba9f7f1
3a3896f
de67786
11ea9b1
124894e
37c6a63
313dc92
4da61b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,6 +320,56 @@ def from_grid(cls, num_rows, num_columns, bidirectional=True): | |
) | ||
return cmap | ||
|
||
@classmethod | ||
def from_heavy_hex(cls, distance, bidirectional=True): | ||
"""Return a heavy hexagon graph coupling map | ||
|
||
A heavy hexagon graph is described in: | ||
|
||
https://journals.aps.org/prx/abstract/10.1103/PhysRevX.10.011022 | ||
|
||
Args: | ||
distance (int): The code distance for the generated heavy hex | ||
graph. The value for distance can be any odd positive integer. | ||
The distance relates to the number of qubits by: | ||
:math:`n = \\frac{5d^2 - 2d - 1}{2}` where :math:`n` is the | ||
number of qubits and :math:`d` is the ``distance`` parameter. | ||
bidirectional (bool): Whether the edges in the output coupling | ||
graph are bidirectional or not. By default this is set to | ||
``True`` | ||
Comment on lines
+337
to
+339
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If The black dots are control, and other colors are target. The edge direction in the graph should always go from control to target. This is for both heavy-hex and heavy-square. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does follow the diagram from the paper. This was something that I brought up in review on the retworkx PRs: Qiskit/rustworkx#293 (review) and Qiskit/rustworkx#313 (review) |
||
Returns: | ||
CouplingMap: A heavy hex coupling graph | ||
""" | ||
cmap = cls(description="heavy-hex") | ||
cmap.graph = rx.generators.directed_heavy_hex_graph(distance, bidirectional=bidirectional) | ||
return cmap | ||
|
||
@classmethod | ||
def from_heavy_square(cls, distance, bidirectional=True): | ||
"""Return a heavy square graph coupling map. | ||
|
||
A heavy square graph is described in: | ||
|
||
https://journals.aps.org/prx/abstract/10.1103/PhysRevX.10.011022 | ||
|
||
Args: | ||
distance (int): The code distance for the generated heavy hex | ||
graph. The value for distance can be any odd positive integer. | ||
mtreinish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The distance relates to the number of qubits by: | ||
:math:`n = 3d^2 - 2d` where :math:`n` is the | ||
number of qubits and :math:`d` is the ``distance`` parameter. | ||
bidirectional (bool): Whether the edges in the output coupling | ||
graph are bidirectional or not. By default this is set to | ||
``True`` | ||
Returns: | ||
CouplingMap: A heavy hex coupling graph | ||
mtreinish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
cmap = cls(description="heavy-square") | ||
cmap.graph = rx.generators.directed_heavy_square_graph( | ||
distance, bidirectional=bidirectional | ||
) | ||
return cmap | ||
|
||
def largest_connected_component(self): | ||
"""Return a set of qubits in the largest connected component.""" | ||
return max(rx.weakly_connected_components(self.graph), key=len) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
features: | ||
- | | ||
Added two new constructor methods, | ||
:meth:`~qiskit.transpiler.CouplingMap.from_heavy_hex` and | ||
:meth:`~qiskit.transpiler.CouplingMap.from_heavy_square`, to the | ||
:class:`~qiskit.transpiler.CouplingMap` class. These constructor methods | ||
are used to create a :class:`~qiskit.transpiler.CouplingMap` that are | ||
a heavy hex or heavy square graph as described in: | ||
https://journals.aps.org/prx/abstract/10.1103/PhysRevX.10.011022 | ||
|
||
For example: | ||
|
||
.. jupyter-execute:: | ||
|
||
from qiskit.transpiler import CouplingMap | ||
|
||
cmap = CouplingMap.from_heavy_hex(5) | ||
cmap.draw() | ||
|
||
|
||
.. jupyter-execute:: | ||
|
||
from qiskit.transpiler import CouplingMap | ||
|
||
cmap = CouplingMap.from_heavy_square(5) | ||
cmap.draw() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering how one might make a coupling map like ibmq_mumbai using this, since it is a 27-qubit graph. Maybe if there was a way to remove some qubits from a coupling map, a user could start with a base and manually work towards that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think the only way right now would be to leverage the
reduce()
method after calling the heavy hex generator. Something like:It's not the prettiest interface for that though, mostly because the node order retworkx creates is by type (data, syndrome, and flag qubits are created up front based on the number given the distance: https://github.com/Qiskit/retworkx/blob/0.10.2/src/generators.rs#L1692-L1702
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
bidirectional=False
: