Skip to content

generate_topology

Generates a chip coupling map (topology) for a specified number of qubits and topology type.

Signature

python
generate_topology(
    num_qubit: int,
    topology_type: str,
) -> list[list[int]]

Parameters

ParameterTypeDescription
num_qubitintThe number of qubits in the topology.
topology_typestrThe type of topology to generate. Supported values include "linear" for a nearest-neighbor chain and "circular" for a ring topology.

Returns

list[list[int]] -- A list of edges, where each edge is a two-element list [u, v] representing a bidirectional connection between physical qubit u and physical qubit v.

Examples

Generate a linear topology for 4 qubits:

python
from pyqpanda3.transpilation import generate_topology

topology = generate_topology(4, "linear")
# topology = [[0, 1], [1, 2], [2, 3]]

Generate a circular (ring) topology for 4 qubits:

python
from pyqpanda3.transpilation import generate_topology

topology = generate_topology(4, "circular")
# topology = [[0, 1], [1, 2], [2, 3], [3, 0]]

Use the generated topology with the Transpiler:

python
from pyqpanda3.transpilation import Transpiler, generate_topology

topology = generate_topology(5, "linear")
transpiler = Transpiler()
result = transpiler.transpile(prog, chip_topology_edges=topology)

See Also

  • Transpiler -- Use the generated topology in transpilation

Released under the MIT License.