336 lines
11 KiB
Plaintext
336 lines
11 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
|
||
---
|
||
|
||
# CouplingMap
|
||
|
||
<Class id="qiskit.transpiler.CouplingMap" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.19/qiskit/transpiler/coupling.py" signature="CouplingMap(couplinglist=None, description=None)" modifiers="class">
|
||
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]]. It is required that nodes are contiguously indexed starting at 0. Missed nodes will be added as isolated nodes in the coupling map.
|
||
* **description** (*str*) – A string to describe the coupling map.
|
||
|
||
## Methods
|
||
|
||
### add\_edge
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.add_edge" signature="CouplingMap.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="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
|
||
</Function>
|
||
|
||
### compute\_distance\_matrix
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.compute_distance_matrix" signature="CouplingMap.compute_distance_matrix()">
|
||
Compute the full distance matrix on pairs of nodes.
|
||
|
||
The distance map self.\_dist\_matrix is computed from the graph using all\_pairs\_shortest\_path\_length. This is normally handled internally by the [`distance_matrix`](qiskit.transpiler.CouplingMap#distance_matrix "qiskit.transpiler.CouplingMap.distance_matrix") attribute or the [`distance()`](qiskit.transpiler.CouplingMap#distance "qiskit.transpiler.CouplingMap.distance") method but can be called if you’re accessing the distance matrix outside of those or want to pre-generate it.
|
||
</Function>
|
||
|
||
### distance
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.distance" signature="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
|
||
</Function>
|
||
|
||
### draw
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.draw" signature="CouplingMap.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**
|
||
|
||
**MissingOptionalLibraryError** – when pydot or pillow are not installed.
|
||
</Function>
|
||
|
||
### from\_full
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_full" signature="CouplingMap.from_full(num_qubits, bidirectional=True)" modifiers="classmethod">
|
||
Return a fully connected coupling map on n qubits.
|
||
|
||
**Return type**
|
||
|
||
`CouplingMap`
|
||
</Function>
|
||
|
||
### from\_grid
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_grid" signature="CouplingMap.from_grid(num_rows, num_columns, bidirectional=True)" modifiers="classmethod">
|
||
Return a coupling map of qubits connected on a grid of num\_rows x num\_columns.
|
||
|
||
**Return type**
|
||
|
||
`CouplingMap`
|
||
</Function>
|
||
|
||
### from\_heavy\_hex
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_heavy_hex" signature="CouplingMap.from_heavy_hex(distance, bidirectional=True)" modifiers="classmethod">
|
||
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](https://journals.aps.org/prx/abstract/10.1103/PhysRevX.10.011022)
|
||
|
||
**Parameters**
|
||
|
||
* **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: $n = \frac{5d^2 - 2d - 1}{2}$ where $n$ is the number of qubits and $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**
|
||
|
||
A heavy hex coupling graph
|
||
|
||
**Return type**
|
||
|
||
[CouplingMap](qiskit.transpiler.CouplingMap "qiskit.transpiler.CouplingMap")
|
||
</Function>
|
||
|
||
### from\_heavy\_square
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_heavy_square" signature="CouplingMap.from_heavy_square(distance, bidirectional=True)" modifiers="classmethod">
|
||
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](https://journals.aps.org/prx/abstract/10.1103/PhysRevX.10.011022)
|
||
|
||
**Parameters**
|
||
|
||
* **distance** (*int*) – The code distance for the generated heavy square graph. The value for distance can be any odd positive integer. The distance relates to the number of qubits by: $n = 3d^2 - 2d$ where $n$ is the number of qubits and $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**
|
||
|
||
A heavy square coupling graph
|
||
|
||
**Return type**
|
||
|
||
[CouplingMap](qiskit.transpiler.CouplingMap "qiskit.transpiler.CouplingMap")
|
||
</Function>
|
||
|
||
### from\_hexagonal\_lattice
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_hexagonal_lattice" signature="CouplingMap.from_hexagonal_lattice(rows, cols, bidirectional=True)" modifiers="classmethod">
|
||
Return a hexagonal lattice graph coupling map.
|
||
|
||
**Parameters**
|
||
|
||
* **rows** (*int*) – The number of rows to generate the graph with.
|
||
* **cols** (*int*) – The number of columns to generate the graph with.
|
||
* **bidirectional** (*bool*) – Whether the edges in the output coupling graph are bidirectional or not. By default this is set to `True`
|
||
|
||
**Returns**
|
||
|
||
A hexagonal lattice coupling graph
|
||
|
||
**Return type**
|
||
|
||
[CouplingMap](qiskit.transpiler.CouplingMap "qiskit.transpiler.CouplingMap")
|
||
</Function>
|
||
|
||
### from\_line
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_line" signature="CouplingMap.from_line(num_qubits, bidirectional=True)" modifiers="classmethod">
|
||
Return a coupling map of n qubits connected in a line.
|
||
|
||
**Return type**
|
||
|
||
`CouplingMap`
|
||
</Function>
|
||
|
||
### from\_ring
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.from_ring" signature="CouplingMap.from_ring(num_qubits, bidirectional=True)" modifiers="classmethod">
|
||
Return a coupling map of n qubits connected to each of their neighbors in a ring.
|
||
|
||
**Return type**
|
||
|
||
`CouplingMap`
|
||
</Function>
|
||
|
||
### get\_edges
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.get_edges" signature="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)
|
||
</Function>
|
||
|
||
### is\_connected
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.is_connected" signature="CouplingMap.is_connected()">
|
||
Test if the graph is connected.
|
||
|
||
Return True if connected, False otherwise
|
||
</Function>
|
||
|
||
### largest\_connected\_component
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.largest_connected_component" signature="CouplingMap.largest_connected_component()">
|
||
Return a set of qubits in the largest connected component.
|
||
</Function>
|
||
|
||
### make\_symmetric
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.make_symmetric" signature="CouplingMap.make_symmetric()">
|
||
Convert uni-directional edges into bi-directional.
|
||
</Function>
|
||
|
||
### neighbors
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.neighbors" signature="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.
|
||
</Function>
|
||
|
||
### reduce
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.reduce" signature="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**
|
||
|
||
[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="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.
|
||
</Function>
|
||
|
||
### size
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.size" signature="CouplingMap.size()">
|
||
Return the number of physical qubits in this graph.
|
||
</Function>
|
||
|
||
### subgraph
|
||
|
||
<Function id="qiskit.transpiler.CouplingMap.subgraph" signature="CouplingMap.subgraph(nodelist)">
|
||
Return a CouplingMap object for a subgraph of self.
|
||
|
||
nodelist (list): list of integer node labels
|
||
</Function>
|
||
|
||
## Attributes
|
||
|
||
### description
|
||
|
||
<Attribute id="qiskit.transpiler.CouplingMap.description" />
|
||
|
||
### distance\_matrix
|
||
|
||
<Attribute id="qiskit.transpiler.CouplingMap.distance_matrix">
|
||
Return the distance matrix for the coupling map.
|
||
</Attribute>
|
||
|
||
### graph
|
||
|
||
<Attribute id="qiskit.transpiler.CouplingMap.graph" />
|
||
|
||
### is\_symmetric
|
||
|
||
<Attribute id="qiskit.transpiler.CouplingMap.is_symmetric">
|
||
Test if the graph is symmetric.
|
||
|
||
Return True if symmetric, False otherwise
|
||
</Attribute>
|
||
|
||
### physical\_qubits
|
||
|
||
<Attribute id="qiskit.transpiler.CouplingMap.physical_qubits">
|
||
Returns a sorted list of physical\_qubits
|
||
</Attribute>
|
||
</Class>
|
||
|