274 lines
13 KiB
Plaintext
274 lines
13 KiB
Plaintext
---
|
||
title: CouplingMap
|
||
description: API reference for qiskit.transpiler.CouplingMap
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.transpiler.CouplingMap
|
||
---
|
||
|
||
# qiskit.transpiler.CouplingMap
|
||
|
||
<Class id="qiskit.transpiler.CouplingMap" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.17/qiskit/transpiler/coupling.py" signature="CouplingMap(couplinglist=None, description=None)" modifiers="class">
|
||
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.
|
||
|
||
### \_\_init\_\_
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.__init__" signature="__init__(couplinglist=None, description=None)">
|
||
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.
|
||
</Function>
|
||
|
||
## Methods
|
||
|
||
| | |
|
||
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
||
| [`__init__`](#qiskit.transpiler.CouplingMap.__init__ "qiskit.transpiler.CouplingMap.__init__")(\[couplinglist, description]) | Create coupling graph. |
|
||
| [`add_edge`](#qiskit.transpiler.CouplingMap.add_edge "qiskit.transpiler.CouplingMap.add_edge")(src, dst) | Add directed edge to coupling graph. |
|
||
| [`add_physical_qubit`](#qiskit.transpiler.CouplingMap.add_physical_qubit "qiskit.transpiler.CouplingMap.add_physical_qubit")(physical\_qubit) | Add a physical qubit to the coupling graph as a node. |
|
||
| [`distance`](#qiskit.transpiler.CouplingMap.distance "qiskit.transpiler.CouplingMap.distance")(physical\_qubit1, physical\_qubit2) | Returns the undirected distance between physical\_qubit1 and physical\_qubit2. |
|
||
| [`draw`](#qiskit.transpiler.CouplingMap.draw "qiskit.transpiler.CouplingMap.draw")() | Draws the coupling map. |
|
||
| [`from_full`](#qiskit.transpiler.CouplingMap.from_full "qiskit.transpiler.CouplingMap.from_full")(num\_qubits\[, bidirectional]) | Return a fully connected coupling map on n qubits. |
|
||
| [`from_grid`](#qiskit.transpiler.CouplingMap.from_grid "qiskit.transpiler.CouplingMap.from_grid")(num\_rows, num\_columns\[, bidirectional]) | Return qubits connected on a grid of num\_rows x num\_columns. |
|
||
| [`from_line`](#qiskit.transpiler.CouplingMap.from_line "qiskit.transpiler.CouplingMap.from_line")(num\_qubits\[, bidirectional]) | Return a fully connected coupling map on n qubits. |
|
||
| [`from_ring`](#qiskit.transpiler.CouplingMap.from_ring "qiskit.transpiler.CouplingMap.from_ring")(num\_qubits\[, bidirectional]) | Return a fully connected coupling map on n qubits. |
|
||
| [`get_edges`](#qiskit.transpiler.CouplingMap.get_edges "qiskit.transpiler.CouplingMap.get_edges")() | Gets the list of edges in the coupling graph. |
|
||
| [`is_connected`](#qiskit.transpiler.CouplingMap.is_connected "qiskit.transpiler.CouplingMap.is_connected")() | Test if the graph is connected. |
|
||
| [`largest_connected_component`](#qiskit.transpiler.CouplingMap.largest_connected_component "qiskit.transpiler.CouplingMap.largest_connected_component")() | Return a set of qubits in the largest connected component. |
|
||
| [`make_symmetric`](#qiskit.transpiler.CouplingMap.make_symmetric "qiskit.transpiler.CouplingMap.make_symmetric")() | Convert uni-directional edges into bi-directional. |
|
||
| [`neighbors`](#qiskit.transpiler.CouplingMap.neighbors "qiskit.transpiler.CouplingMap.neighbors")(physical\_qubit) | Return the nearest neighbors of a physical qubit. |
|
||
| [`reduce`](#qiskit.transpiler.CouplingMap.reduce "qiskit.transpiler.CouplingMap.reduce")(mapping) | Returns a reduced coupling map that corresponds to the subgraph of qubits selected in the mapping. |
|
||
| [`shortest_undirected_path`](#qiskit.transpiler.CouplingMap.shortest_undirected_path "qiskit.transpiler.CouplingMap.shortest_undirected_path")(physical\_qubit1, …) | Returns the shortest undirected path between physical\_qubit1 and physical\_qubit2. |
|
||
| [`size`](#qiskit.transpiler.CouplingMap.size "qiskit.transpiler.CouplingMap.size")() | Return the number of physical qubits in this graph. |
|
||
| [`subgraph`](#qiskit.transpiler.CouplingMap.subgraph "qiskit.transpiler.CouplingMap.subgraph")(nodelist) | Return a CouplingMap object for a subgraph of self. |
|
||
|
||
## Attributes
|
||
|
||
| | |
|
||
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
|
||
| [`distance_matrix`](#qiskit.transpiler.CouplingMap.distance_matrix "qiskit.transpiler.CouplingMap.distance_matrix") | Return the distance matrix for the coupling map. |
|
||
| [`is_symmetric`](#qiskit.transpiler.CouplingMap.is_symmetric "qiskit.transpiler.CouplingMap.is_symmetric") | Test if the graph is symmetric. |
|
||
| [`physical_qubits`](#qiskit.transpiler.CouplingMap.physical_qubits "qiskit.transpiler.CouplingMap.physical_qubits") | Returns a sorted list of physical\_qubits |
|
||
|
||
### add\_edge
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.add_edge" signature="add_edge(src, dst)">
|
||
Add directed edge to coupling graph.
|
||
|
||
src (int): source physical qubit dst (int): destination physical qubit
|
||
</Function>
|
||
|
||
### add\_physical\_qubit
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.add_physical_qubit" signature="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
|
||
</Function>
|
||
|
||
### distance
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.distance" signature="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
|
||
</Function>
|
||
|
||
### distance\_matrix
|
||
|
||
<Attribute id="qiskit.transpiler.CouplingMap.distance_matrix">
|
||
Return the distance matrix for the coupling map.
|
||
</Attribute>
|
||
|
||
### draw
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.draw" signature="draw()">
|
||
Draws the coupling map.
|
||
|
||
This function needs [pydot](https://github.com/erocarrera/pydot), which in turn needs [Graphviz](https://www.graphviz.org/) to be installed. Additionally, [pillow](https://python-pillow.org/) will need to be installed.
|
||
|
||
**Returns**
|
||
|
||
Drawn coupling map.
|
||
|
||
**Return type**
|
||
|
||
PIL.Image
|
||
|
||
**Raises**
|
||
|
||
**ImportError** – when pydot or pillow are not installed.
|
||
</Function>
|
||
|
||
### from\_full
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_full" signature="from_full(num_qubits, bidirectional=True)" modifiers="classmethod">
|
||
Return a fully connected coupling map on n qubits.
|
||
</Function>
|
||
|
||
### from\_grid
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_grid" signature="from_grid(num_rows, num_columns, bidirectional=True)" modifiers="classmethod">
|
||
Return qubits connected on a grid of num\_rows x num\_columns.
|
||
</Function>
|
||
|
||
### from\_line
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_line" signature="from_line(num_qubits, bidirectional=True)" modifiers="classmethod">
|
||
Return a fully connected coupling map on n qubits.
|
||
</Function>
|
||
|
||
### from\_ring
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_ring" signature="from_ring(num_qubits, bidirectional=True)" modifiers="classmethod">
|
||
Return a fully connected coupling map on n qubits.
|
||
</Function>
|
||
|
||
### get\_edges
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.get_edges" signature="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)
|
||
</Function>
|
||
|
||
### is\_connected
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.is_connected" signature="is_connected()">
|
||
Test if the graph is connected.
|
||
|
||
Return True if connected, False otherwise
|
||
</Function>
|
||
|
||
### is\_symmetric
|
||
|
||
<Attribute id="qiskit.transpiler.CouplingMap.is_symmetric">
|
||
Test if the graph is symmetric.
|
||
|
||
Return True if symmetric, False otherwise
|
||
</Attribute>
|
||
|
||
### largest\_connected\_component
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.largest_connected_component" signature="largest_connected_component()">
|
||
Return a set of qubits in the largest connected component.
|
||
</Function>
|
||
|
||
### make\_symmetric
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.make_symmetric" signature="make_symmetric()">
|
||
Convert uni-directional edges into bi-directional.
|
||
</Function>
|
||
|
||
### neighbors
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.neighbors" signature="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.
|
||
</Function>
|
||
|
||
### physical\_qubits
|
||
|
||
<Attribute id="qiskit.transpiler.CouplingMap.physical_qubits">
|
||
Returns a sorted list of physical\_qubits
|
||
</Attribute>
|
||
|
||
### reduce
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.reduce" signature="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**
|
||
|
||
[CouplingMap](#qiskit.transpiler.CouplingMap "qiskit.transpiler.CouplingMap")
|
||
|
||
**Raises**
|
||
|
||
**CouplingError** – Reduced coupling map must be connected.
|
||
</Function>
|
||
|
||
### shortest\_undirected\_path
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.shortest_undirected_path" signature="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.
|
||
</Function>
|
||
|
||
### size
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.size" signature="size()">
|
||
Return the number of physical qubits in this graph.
|
||
</Function>
|
||
|
||
### subgraph
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.subgraph" signature="subgraph(nodelist)">
|
||
Return a CouplingMap object for a subgraph of self.
|
||
|
||
nodelist (list): list of integer node labels
|
||
</Function>
|
||
</Class>
|
||
|