wy_qcos.transpiler.cmss.mapping.routing package

Submodules

wy_qcos.transpiler.cmss.mapping.routing.mcts_routing module

wy_qcos.transpiler.cmss.mapping.routing.mcts_routing.log_data = 0

default select_mode specifies the mode for evaluation during selection Paper recommends c=20 for UCT formula(c is a preset parameter)

class wy_qcos.transpiler.cmss.mapping.routing.mcts_routing.MCTree(AG, DG, **args)

基类:DiGraph

蒙特卡洛树.

参数:
  • AG -- 硬件拓扑

  • DG -- 量子线路拓扑

  • shortest_length_AG -- 硬件上任意两个点间的最短距离

  • shortest_path_AG -- 硬件上任意两个点间的最短路径

  • select_mode -- 选择策略(默认 KS 方法)

  • mode_BP -- 反向传播方式(目前支持 globalscore)

  • mode_decision -- 子节点选择依据(默认 global_score)

  • objective -- 优化目标(size 或 depth)

  • root_node -- 根节点

add_node_mcts(father_node, added_swap=None, remote_exe_node=None)

Add a node to the Monte Carlo Tree.

Creates a new node in the MCTS tree. If father_node is None, creates the root node with initial mapping. Otherwise, creates a child node by applying either a SWAP operation or remote gate execution.

The new node stores the following attributes:
  • visited_time: Number of times this node has been visited.

  • local_score: Number of gates executed at this node.

  • global_score: Cumulative score considering all descendant nodes.

  • num_remain_gates: Number of unexecuted gates in logical circuit.

  • added_swap: The SWAP operation applied (if any).

  • added_remote: Remote CNOTs added (if any).

参数:
  • father_node -- The parent node identifier. If None, creates the root node.

  • added_swap -- A tuple (q1, q2) representing the SWAP operation to apply. Mutually exclusive with remote_exe_node.

  • remote_exe_node -- The node for remote gate execution. Mutually exclusive with added_swap.

返回:

The generated node identifier, or None if the new node is not better than an existing equivalent node.

抛出:
  • ValueError -- If father_node is not None and neither added_swap nor remote_exe_node is provided.

  • ValueError -- If objective is "no_swap" and remaining gates exist when creating root node.

get_father(node)
get_circuit(node)
get_num_exe_gates(node)
node_cost_from_father(father_node, added_swap, added_cxs)
node_cost(node)
add_depth(node)

Add depth information to a new node.

This should be revoked after or at the end of the add_node method.

variables added:
depth_phy_qubits -> a list in which the index corresponds to the

physical qubits and value the depth

depth_add -> add depht corresponding to the current physical

circuit brougnt by insertinf SWAP gate

expand_node_via_swap(node, swap)
expand_node_via_remote(node)

Expand a node via reomte CNOTs.

expansion(node)

Expand a node via all non-trivival swaps and do backpropagation.

get_son_attributes(node, args)

Get attributes and sons from all sons of node.

pick_best_son_size(node, method)

This is a subfunction for selection section.

pick_best_son_depth(node, method)

This is a subfunction for selection section for depth opt.

back_propagation(start_node, mode_BP=None)

Backpropagate scores from a node up to the root.

Starting from the parent of start_node, propagates the global_score upward through the tree. In 'globalscore' mode, applies a decay factor at each step and updates parent nodes only if the new computed score exceeds the existing value.

参数:
  • start_node -- The node from which backpropagation originates. The propagation starts from this node's parent, using this node's global_score as the initial value.

  • mode_BP -- The backpropagation mode. If None, uses the instance default (self.mode_BP). Supported modes: - 'globalscore': Updates global_score using decay factor. Formula: new_value = local_score + decay * child_score. Propagation stops when new_value <= old_value.

抛出:

ValueError -- If mode_BP is not a supported mode.

selection()

我们从根节点选择子节点到叶节点,然后扩展叶节点并反向传播扩展节点的最佳分数.

delete_nodes(nodes)

Delete nodes and all its successors.

fallback()
decision(mode_decision=None)

选择一个叶子节点,删除其父节点的所有其他叶子节点.

sim_function(gate0, gate1, *args)
simulation(sim_node, mode_sim=None)

Run simulation and backpropagate the simulation score.

Performs a lookahead simulation from the given node to estimate future routing cost, then backpropagates the result if it improves the node's global score.

参数:
  • sim_node -- The node from which to run the simulation. If this is the root node, returns None immediately.

  • mode_sim -- The simulation mode as a list ['name', arg_list]. If None, uses the instance default (self.mode_sim). Supported modes: - 'fix_cx_num': Simulates execution of a fixed number of CNOT gates. arg_list = [simulation_times, num_CX_gates], where simulation_times is the number of simulation runs and num_CX_gates is the number of gates to simulate.

返回:

None if sim_node is root or simulation cannot proceed. True if simulation completed successfully (depth objective).

get_swaps()
to_dg()
print_node_attrs(node, names)
print_son_attrs(father_node, names_son, names_father=[])
class wy_qcos.transpiler.cmss.mapping.routing.mcts_routing.MCTSRouting

基类:ABC

MCTS路由搜索类.

负责执行基于蒙特卡罗树搜索的量子比特路由,插入SWAP门以满足硬件拓扑约束。

execute_routing(search_tree, ag, initial_layout, num_q_vir, measure_ops)

执行路由搜索,返回映射后的门列表.

参数:
  • search_tree -- MCTree 搜索树实例

  • ag -- 架构图(Architecture Graph)

  • initial_layout -- 初始布局字典 {逻辑比特: 物理比特}

  • num_q_vir -- 虚拟量子比特数

  • measure_ops -- 测量操作列表

返回:

映射后的门列表(包含插入的SWAP门和更新后的measure操作)

返回类型:

mapped_ir

wy_qcos.transpiler.cmss.mapping.routing.sabre_routing module

class wy_qcos.transpiler.cmss.mapping.routing.sabre_routing.Node(gate)

基类:object

参数:

gate (GateOperation)

class wy_qcos.transpiler.cmss.mapping.routing.sabre_routing.SABRE(coupling_list, extension_size=20, weight=0.5, decay=0.001)

基类:object

参数:
  • coupling_list (list | Graph)

  • extension_size (int)

  • weight (float)

  • decay (float)

get_rx_graph(coupling_list)

Convert a topology list to an rx.PyGraph.

参数:

coupling_list (list) -- The hardware topology list.

返回:

The graph object and a mapping from physical

qubit to its index in the graph.

返回类型:

rx.PyGraph, dict

execute(gates_list, initial_l2p=None)

Execute the SABRE mapping on the input circuit (IR).

参数:
  • gates_list (list[GateOperation]) -- a list of gates.

  • initial_l2p (list[int], optional) -- initial logical to physical mapping. Defaults to None.

get_qubit_num_from_ir(gates_list)

Get the logic qubit number from the gates_list.

参数:

gates_list (list[GateOperation]) -- a list of gates.

返回:

number of logic qubits.

返回类型:

int

can_execute(node)

Whether the node can be executed in physical.

参数:

node (Node)

obtain_swaps()

Obtain all candidate swap gates.

get_temp_mapping(edge)

Generate a new logic to physical mapping with a swap.

参数:

edge (tuple) -- a tuple of (u,v), indicate a swap gate.

返回:

a new logic to physical mapping.

返回类型:

list[int]

phy_gate(logic_gate)

Mapping a logic gate to a phy gate with logic2phy.

参数:

logic_gate (GateOperation) -- a logic gate, with logic qubits in targets.

返回:

a physical gate, with physical qubits in targets.

返回类型:

GateOperation

heuristic_cost(logic2phy)

The heuristic_cost function, calculate the cost of the new mapping.

参数:

logic2phy (list) -- a logic to physical mapping.

返回:

the heuristic cost of the new mapping.

返回类型:

float

delta_heuristic_cost(old_l2p, new_l2p, swap, extend_size, front_qubit_gate_map, extend_qubit_gate_map)

Calculate the incremental cost after applying a swap gate.

参数:
  • old_l2p (list) -- Original logical-to-physical qubit mapping.

  • new_l2p (list) -- New logical-to-physical qubit mapping.

  • swap (tuple) -- The candidate swap gate that transforms old_l2p to new_l2p.

  • extend_size (int) -- Size of the extension set, used for normalizing the cost.

  • front_qubit_gate_map (dict) -- Mapping from qubits in the front layer to the gates they affect, for quickly finding the cost impact of a swap.

  • extend_qubit_gate_map (dict) -- Same as above, but for the lookahead extension layer.

返回:

Incremental cost after applying the swap gate.

返回类型:

float

wy_qcos.transpiler.cmss.mapping.routing.sabre_routing_wrapper module

class wy_qcos.transpiler.cmss.mapping.routing.sabre_routing_wrapper.SABRERouting(extension_size=20, weight=0.5, decay=0.001)

基类:ABC

SABRE路由搜索包装类.

负责执行基于SABRE算法的量子比特路由,插入SWAP门以满足硬件拓扑约束。 该包装类使SABRE算法与SCRouting接口保持一致。

参数:
  • extension_size (int)

  • weight (float)

  • decay (float)

execute_routing(search_tree, ag, initial_layout, num_q_vir, measure_ops, dg=None)

执行路由搜索,返回映射后的门列表.

参数:
  • search_tree -- 未使用(为保持接口一致性保留)

  • ag -- 架构图(Architecture Graph)

  • initial_layout -- 初始布局字典 {逻辑比特: 物理比特}

  • num_q_vir -- 虚拟量子比特数

  • measure_ops -- 测量操作列表

  • dg -- 依赖图(可选,如果未提供则从search_tree获取)

返回:

映射后的门列表(包含插入的SWAP门和更新后的measure操作)

返回类型:

mapped_ir

wy_qcos.transpiler.cmss.mapping.routing.sc_routing module

class wy_qcos.transpiler.cmss.mapping.routing.sc_routing.SCRoutingFactory

基类:object

超导设备路由算法工厂类.

根据参数选择具体的路由算法实现(MCTS或SABRE)。

static create_routing(routing_algorithm='mct', **kwargs)

创建路由算法实例.

参数:
  • routing_algorithm (str) -- 路由算法名称,支持 "mct", "sc", "sabre"

  • **kwargs -- 路由算法的额外参数 - 对于SABRE算法:extension_size, weight, decay - 对于MCTS算法:selec_times

返回:

路由算法实例(MCTSRouting 或 SABRERouting)

抛出:

MappingException -- 如果路由算法名称不支持

Module contents