CouplingMap
class CouplingMap(couplinglist=None, description=None)
Bases: object
Directed graph specifying fixed coupling.
Nodes correspond to physical qubits (integers) and directed edges correspond to permitted CNOT gates
Create coupling graph. By default, the generated coupling has no nodes.
Parameters
- couplinglist (list or None) – An initial coupling graph, specified as an adjacency list containing couplings, e.g. [[0,1], [0,2], [1,2]].
- description (str) – A string to describe the coupling map.
Methods
add_edge
CouplingMap.add_edge(src, dst)
Add directed edge to coupling graph.
src (int): source physical qubit dst (int): destination physical qubit
add_physical_qubit
CouplingMap.add_physical_qubit(physical_qubit)
Add a physical qubit to the coupling graph as a node.
physical_qubit (int): An integer representing a physical qubit.
Raises
CouplingError – if trying to add duplicate qubit
distance
CouplingMap.distance(physical_qubit1, physical_qubit2)
Returns the undirected distance between physical_qubit1 and physical_qubit2.
Parameters
- physical_qubit1 (int) – A physical qubit
- physical_qubit2 (int) – Another physical qubit
Returns
The undirected distance
Return type
int
Raises
CouplingError – if the qubits do not exist in the CouplingMap
draw
CouplingMap.draw()
Draws the coupling map.
This function needs pydot, which in turn needs Graphviz to be installed. Additionally, pillow will need to be installed.
Returns
Drawn coupling map.
Return type
PIL.Image
Raises
MissingOptionalLibraryError – when pydot or pillow are not installed.
from_full
classmethod CouplingMap.from_full(num_qubits, bidirectional=True)
Return a fully connected coupling map on n qubits.
from_grid
classmethod CouplingMap.from_grid(num_rows, num_columns, bidirectional=True)
Return qubits connected on a grid of num_rows x num_columns.
from_line
classmethod CouplingMap.from_line(num_qubits, bidirectional=True)
Return a fully connected coupling map on n qubits.
from_ring
classmethod CouplingMap.from_ring(num_qubits, bidirectional=True)
Return a fully connected coupling map on n qubits.
get_edges
CouplingMap.get_edges()
Gets the list of edges in the coupling graph.
Returns
Each edge is a pair of physical qubits.
Return type
Tuple(int,int)
is_connected
CouplingMap.is_connected()
Test if the graph is connected.
Return True if connected, False otherwise
largest_connected_component
CouplingMap.largest_connected_component()
Return a set of qubits in the largest connected component.
make_symmetric
CouplingMap.make_symmetric()
Convert uni-directional edges into bi-directional.
neighbors
CouplingMap.neighbors(physical_qubit)
Return the nearest neighbors of a physical qubit.
Directionality matters, i.e. a neighbor must be reachable by going one hop in the direction of an edge.
reduce
CouplingMap.reduce(mapping)
Returns a reduced coupling map that corresponds to the subgraph of qubits selected in the mapping.
Parameters
mapping (list) – A mapping of reduced qubits to device qubits.
Returns
A reduced coupling_map for the selected qubits.
Return type
Raises
CouplingError – Reduced coupling map must be connected.
shortest_undirected_path
CouplingMap.shortest_undirected_path(physical_qubit1, physical_qubit2)
Returns the shortest undirected path between physical_qubit1 and physical_qubit2.
Parameters
- physical_qubit1 (int) – A physical qubit
- physical_qubit2 (int) – Another physical qubit
Returns
The shortest undirected path
Return type
List
Raises
CouplingError – When there is no path between physical_qubit1, physical_qubit2.
size
CouplingMap.size()
Return the number of physical qubits in this graph.
subgraph
CouplingMap.subgraph(nodelist)
Return a CouplingMap object for a subgraph of self.
nodelist (list): list of integer node labels
Attributes
distance_matrix
Return the distance matrix for the coupling map.
is_symmetric
Test if the graph is symmetric.
Return True if symmetric, False otherwise
physical_qubits
Returns a sorted list of physical_qubits