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
| Parameter | Type | Description |
|---|---|---|
| num_qubit | int | The number of qubits in the topology. |
| topology_type | str | The type of topology to generate. Supported values: "linear" for a nearest-neighbor chain, "square" for a 2D grid topology, and "all-to-all" for a fully-connected topology where every qubit is linked to every other qubit. |
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 2D square-grid topology for 4 qubits:
python
from pyqpanda3.transpilation import generate_topology
topology = generate_topology(4, "square")
# topology = [[0, 1], [0, 3], [1, 2], [1, 4], [2, 5],
# [3, 4], [3, 6], [4, 5], [4, 7], [5, 8],
# [6, 7], [7, 8]]Use the generated topology with the Transpiler:
python
from pyqpanda3.transpilation import Transpiler, generate_topology
from pyqpanda3.core import QProg, H, CNOT
topology = generate_topology(5, "linear")
prog = QProg() << H(0) << CNOT(0, 1)
transpiler = Transpiler()
result = transpiler.transpile(prog, chip_topology_edges=topology)See Also
- Transpiler -- Use the generated topology in transpilation