CouplingMap#

class qiskit.transpiler.CouplingMap(couplinglist=None, description=None)[소스]#

기반 클래스: object

Directed graph specifying fixed coupling.

Nodes correspond to physical qubits (integers) and directed edges correspond to permitted CNOT gates, with source and destination corresponding to control and target qubits, respectively.

Create coupling graph. By default, the generated coupling has no nodes.

매개변수:
  • 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.

Attributes

description#
graph#
distance_matrix#

Return the distance matrix for the coupling map.

For any qubits where there isn’t a path available between them the value in this position of the distance matrix will be math.inf.

is_symmetric#

Test if the graph is symmetric.

Return True if symmetric, False otherwise

physical_qubits#

Returns a sorted list of physical_qubits

Methods

add_edge(src, dst)[소스]#

Add directed edge to coupling graph.

src (int): source physical qubit dst (int): destination physical qubit

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.

예외 발생:

CouplingError – if trying to add duplicate qubit

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 attribute or the distance() method but can be called if you’re accessing the distance matrix outside of those or want to pre-generate it.

connected_components()[소스]#

Separate a CouplingMap into subgraph CouplingMap for each connected component.

The connected components of a CouplingMap are the subgraphs that are not part of any larger subgraph. For example, if you had a coupling map that looked like:

0 --> 1   4 --> 5 ---> 6 --> 7
|     |
|     |
V     V
2 --> 3

then the connected components of that graph are the subgraphs:

0 --> 1
|     |
|     |
V     V
2 --> 3

and:

4 --> 5 ---> 6 --> 7

For a connected CouplingMap object there is only a single connected component, the entire CouplingMap.

This method will return a list of CouplingMap objects, one for each connected component in this CouplingMap. The data payload of each node in the graph attribute will contain the qubit number in the original graph. This will enables mapping the qubit index in a component subgraph to the original qubit in the combined CouplingMap. For example:

from qiskit.transpiler import CouplingMap

cmap = CouplingMap([[0, 1], [1, 2], [2, 0], [3, 4], [4, 5], [5, 3]])
component_cmaps = cmap.connected_components()
print(component_cmaps[1].graph[0])

will print 3 as index 0 in the second component is qubit 3 in the original cmap.

반환:

A list of CouplingMap objects for each connected

components. The order of this list is deterministic but implementation specific and shouldn’t be relied upon as part of the API.

반환 형식:

list

distance(physical_qubit1, physical_qubit2)[소스]#

Returns the undirected distance between physical_qubit1 and physical_qubit2.

매개변수:
  • physical_qubit1 (int) – A physical qubit

  • physical_qubit2 (int) – Another physical qubit

반환:

The undirected distance

반환 형식:

int

예외 발생:

CouplingError – if the qubits do not exist in the CouplingMap

draw()[소스]#

Draws the coupling map.

This function calls the graphviz_draw() function from the rustworkx package to draw the CouplingMap object.

반환:

Drawn coupling map.

반환 형식:

PIL.Image

classmethod from_full(num_qubits, bidirectional=True)[소스]#

Return a fully connected coupling map on n qubits.

반환 형식:

CouplingMap

classmethod from_grid(num_rows, num_columns, bidirectional=True)[소스]#

Return a coupling map of qubits connected on a grid of num_rows x num_columns.

반환 형식:

CouplingMap

classmethod from_heavy_hex(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

매개변수:
  • 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

반환:

A heavy hex coupling graph

반환 형식:

CouplingMap

classmethod from_heavy_square(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

매개변수:
  • 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

반환:

A heavy square coupling graph

반환 형식:

CouplingMap

classmethod from_hexagonal_lattice(rows, cols, bidirectional=True)[소스]#

Return a hexagonal lattice graph coupling map.

매개변수:
  • 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

반환:

A hexagonal lattice coupling graph

반환 형식:

CouplingMap

classmethod from_line(num_qubits, bidirectional=True)[소스]#

Return a coupling map of n qubits connected in a line.

반환 형식:

CouplingMap

classmethod from_ring(num_qubits, bidirectional=True)[소스]#

Return a coupling map of n qubits connected to each of their neighbors in a ring.

반환 형식:

CouplingMap

get_edges()[소스]#

Gets the list of edges in the coupling graph.

반환:

Each edge is a pair of physical qubits.

반환 형식:

Tuple(int,int)

is_connected()[소스]#

Test if the graph is connected.

Return True if connected, False otherwise

largest_connected_component()[소스]#

Return a set of qubits in the largest connected component.

make_symmetric()[소스]#

Convert uni-directional edges into bi-directional.

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(mapping)[소스]#

Returns a reduced coupling map that corresponds to the subgraph of qubits selected in the mapping.

매개변수:

mapping (list) – A mapping of reduced qubits to device qubits.

반환:

A reduced coupling_map for the selected qubits.

반환 형식:

CouplingMap

예외 발생:

CouplingError – Reduced coupling map must be connected.

shortest_undirected_path(physical_qubit1, physical_qubit2)[소스]#

Returns the shortest undirected path between physical_qubit1 and physical_qubit2.

매개변수:
  • physical_qubit1 (int) – A physical qubit

  • physical_qubit2 (int) – Another physical qubit

반환:

The shortest undirected path

반환 형식:

List

예외 발생:

CouplingError – When there is no path between physical_qubit1, physical_qubit2.

size()[소스]#

Return the number of physical qubits in this graph.

subgraph(nodelist)[소스]#

Return a CouplingMap object for a subgraph of self.

nodelist (list): list of integer node labels

버전 0.20.0부터 폐지됨: The method qiskit.transpiler.coupling.CouplingMap.subgraph() is deprecated as of qiskit-terra 0.20.0. It will be removed no earlier than 3 months after the release date. Instead, use reduce(). It does the same thing, but preserves nodelist order.