mindquantum.algorithm.mapping.MQSABRE

View Source On Gitee
class mindquantum.algorithm.mapping.MQSABRE(circuit: Circuit, topology: QubitsTopology, cnoterrorandlength: List[Tuple[Tuple[int, int], List[float]]])[source]

MQSABRE algorithm for hardware-aware qubit mapping optimization.

MQSABRE extends the SABRE (SWAP-based BidiREctional heuristic search) algorithm by incorporating hardware-specific characteristics into the mapping optimization process. The algorithm performs initial mapping and routing optimization in three phases:

  1. Initial mapping: Uses a graph-center-based approach to generate an initial mapping that minimizes the average distance between frequently interacting qubits.

  2. Mapping optimization: Employs bidirectional heuristic search with a hardware-aware cost function.

  3. Circuit transformation: Inserts SWAP gates and transforms the circuit to be compatible with hardware constraints.

The algorithm uses a weighted cost function that combines three metrics: H = α₁D + α₂K + α₃T where:

  • D: Shortest path distance between qubits in the coupling graph

  • K: Error rate metric derived from CNOT and SWAP success rates

  • T: Gate execution time metric considering CNOT and SWAP durations

  • α₁, α₂, α₃: Weight parameters for balancing different optimization objectives

Parameters
  • circuit (Circuit) – The quantum circuit to be mapped. Currently only supports circuits composed of single-qubit gates and two-qubit gates (including controlled gates).

  • topology (QubitsTopology) – The hardware qubit topology. Must be a connected coupling graph.

  • cnoterrorandlength (List[Tuple[Tuple[int, int], List[float]]]) – Hardware-specific CNOT characteristics. Each entry contains a tuple (i, j) specifying the physical qubit pair in the topology, and a list [error_rate, gate_time] where error_rate is the CNOT error rate between qubits i and j (range: [0, 1]), and gate_time is the CNOT execution time in arbitrary units.

Raises

ValueError – If the topology is not a connected graph.

Examples

>>> from mindquantum.algorithm.mapping import MQSABRE
>>> from mindquantum.core.circuit import Circuit
>>> from mindquantum.core.gates import RX, X
>>> from mindquantum.device import GridQubits
>>> # Create a quantum circuit
>>> circ = Circuit()
>>> circ += RX('a').on(0)
>>> circ += RX('b').on(1)
>>> circ += X.on(1, 0)
>>> # Define hardware characteristics
>>> cnot_data = [
...     ((0, 1), [0.001, 250.0]),  # CNOT 0->1: 0.1% error, 250ns
...     ((1, 2), [0.002, 300.0]),  # CNOT 1->2: 0.2% error, 300ns
... ]
>>> # Create a linear topology: 0-1-2
>>> topology = GridQubits(1, 3)
>>> # Initialize and run MQSABRE
>>> solver = MQSABRE(circ, topology, cnot_data)
>>> new_circ, init_map, final_map = solver.solve()
solve(w: float = 0.5, alpha1: float = 0.3, alpha2: float = 0.2, alpha3: float = 0.1)[source]

Solve the qubit mapping problem using the MQSABRE algorithm.

The method performs three main steps: 1. Constructs the distance matrix D using Floyd-Warshall algorithm 2. Computes hardware-specific matrices K (error rates) and T (gate times) 3. Performs heuristic search to optimize the mapping while considering the combined cost function

Parameters
  • w (float, optional) – Look-ahead weight parameter that balances between current and future gate operations in the heuristic search. Range: [0, 1]. When w > 0.5, it favors future operations, potentially reducing circuit depth. When w < 0.5, it prioritizes current operations, potentially reducing total gate count. Defaults: 0.5.

  • alpha1 (float, optional) – Weight for the distance metric (D) in the cost function. Higher values prioritize minimizing qubit distances. Defaults: 0.3.

  • alpha2 (float, optional) – Weight for the error rate metric (K). Higher values prioritize connections with lower error rates. Defaults: 0.2.

  • alpha3 (float, optional) – Weight for the gate time metric (T). Higher values prioritize faster gate execution paths. Defaults: 0.1.

Returns

The transformed circuit with inserted SWAP gates - initial_mapping (List[int]): Initial mapping from logical to physical qubits - final_mapping (List[int]): Final mapping from logical to physical qubits

Return type

Examples

>>> # Use default parameters
>>> new_circ, init_map, final_map = solver.solve()
>>> # Prioritize error rate optimization
>>> new_circ, init_map, final_map = solver.solve(alpha2=0.5)
>>> # Focus on circuit depth reduction
>>> new_circ, init_map, final_map = solver.solve(w=0.7)