wy_qcos.transpiler.cmss.mapping.utils package
Submodules
wy_qcos.transpiler.cmss.mapping.utils.dg module
- class wy_qcos.transpiler.cmss.mapping.utils.dg.DG
基类:
DiGraphTopology analysis and construction of a dependency graph.
- property num_gate
Get qubits which exist in both node1 and node2.
- 参数:
node1 (int) -- id of node1
node2 (int) -- id of node2
- 返回:
shared qubits list
- 返回类型:
list[int]
- add_line(node_in, node_out, qubits=None)
Connect two nodes using provided qubits.
- 参数:
node_in (int) -- id of node_in
node_out (int) -- id of node_out
qubits (list, optional) -- specified target. Defaults to None.
- add_multi_gates(gates, absorb=False)
Add multiple gates to the graph.
- 参数:
gates (list) -- list of gates
absorb (bool, optional) -- Whether absorb the gate. Defaults to False.
- add_gate(format_gate, gate=None, add_edges=True)
Add a gate to the graph.
Attributes of a node: gates, num_gate_1q, num_gate_2q, qubits.
- 参数:
format_gate (tuple) -- a tuple of (gate_name, (qubits), (parameters))
gate (GateOperation) -- Gate Operation
add_edges (bool, optional) -- wheater to add edges. Defaults to True.
- 返回:
id of new node
- 返回类型:
int
- get_dg_num_q()
Get the number of qubits in the dependency graph.
- get_node_num_q(node)
- get_node_num_2q_gates(node)
- get_node_num_1q_gates(node)
- get_node_gates(node)
- get_node_qubits(node)
Return the qubits associated with a node with robust type checks.
This implementation accesses the underlying node data defensively and provides clear error messages if the node or expected attribute is not present or not in the expected format. It ensures the returned value is a list of qubits.
- get_node_depth(node)
Get depth of a node, one SWAP takes 3 depth.
- 参数:
node (int) -- id of a node
- 返回:
depth of a node
- 返回类型:
int
- get_edge_qubits(edge)
- set_edge_qubits(edge, qubits)
- add_gate_absorb(format_gate, gate=None)
Add a gate and absorb is if possible.
- 参数:
format_gate (tuple) -- a tuple of (gate_name, (qubits), (parameters))
gate (GateOperation) -- Gate Operation
- 返回:
id of new node
- 返回类型:
int
- cascade_node(node1, node2)
Combine two given nodes.
Here we only update one node (node_in) and delete the other (node_out) instead of creating one node and deleting both.
- 参数:
node1 (int) -- id of node1
node2 (int) -- id of node2
- 返回:
id of new node
- 返回类型:
int
- from_qasm_string(qasm_string, absorb=True)
Parse OpenQASM string, build graph and get ir.
- 参数:
qasm_string (str) -- OpenQASM string
absorb (bool, optional) -- Whether absorb the gate. Defaults to True.
- 返回:
measure operations
- 返回类型:
list
- convert_ir(ir)
Convert the target qubits from str to int in ir.
- 参数:
ir (QuantumCircuit) -- quantum circuit intermediate representation
- from_ir(circ, absorb=True)
Build graph from circ.
- 参数:
circ (QuantumCircuit) -- quantum circuit
absorb (bool, optional) -- Whether absorb the gate. Defaults to True.
- 返回:
measure operations
- 返回类型:
list
- to_ir(add_barrier=False, decompose_swap=False)
Convert the DG to a ir.
If decompose_swap is set to True, we will decompose each SWAP into 3 CNOTs.
- draw()
Draw DG graph.
- check_parallel(node1, node2)
Check two nodes are parallel or not.
- 参数:
node1 (int) -- id of node1.
node2 (int) -- id of node2.
- 返回:
true if two nodes are parallel, false otherwise.
- 返回类型:
bool
- check_direct_dependency(node1, node2)
Check two nodes are directly dependent or not.
- We say node2 directly depends on node1 if
two nodes share at least one qubit;
for each shared qubit, there can't be any nodes existing between the two nodes;
there can't be any path connecting node1 and node2 other than the edge in 1)
If two node are directly dependent, these nodes can be absorbed or cascaded. Note that currently we won't accept node1 and node2 are parallel, in that case, we will return False! One can use self.check_parallel to check the parallelism between nodes.
- 参数:
node1 (int) -- id of node1.
node2 (int) -- id of node2.
- 返回:
true if two nodes are directly dependent, false otherwise.
- 返回类型:
bool
- check_absorbable(node1, node2)
Check if node1 and node2 can be obsorbed to each other.
node1 and node2 are absorbable if all qubits in node1 or node2 exist in node2 or node1 and they are directly dependent to each other.
- 参数:
node1 (int) -- id of node1.
node2 (int) -- id of node2.
- 返回:
true if two nodes are absorbable, false otherwise.
- 返回类型:
bool
wy_qcos.transpiler.cmss.mapping.utils.dg_swap_opt module
- wy_qcos.transpiler.cmss.mapping.utils.dg_swap_opt.swap_qubits_(qubits, swap_qubits)
- wy_qcos.transpiler.cmss.mapping.utils.dg_swap_opt.hybridization(dg_swap1, dg_swap2, dg_ori, prob1=0.5)
Hybridize two DG swaps.
We choose the first prob1% gates in dg_swap1 and the last (1-prob1)% gates in dg_swap2.
- 参数:
dg_swap1 -- First DG swap.
dg_swap2 -- Second DG swap.
dg_ori -- Original DG.
prob1 -- Probability for choosing from dg_swap1.
- 返回:
Hybridized DG swap.
- 返回类型:
- wy_qcos.transpiler.cmss.mapping.utils.dg_swap_opt.hybridization2(dg_swap1, dg_swap2, dg_ori, prob1=0.5)
Hybridize two DG swaps randomly.
For each exchange, we randomly accept (prob1%) in dg_swap1 or [(1-prob1)%] that in dg_swap2.
- 参数:
dg_swap1 -- First DG swap.
dg_swap2 -- Second DG swap.
dg_ori -- Original DG.
prob1 -- Probability for accepting from dg_swap1.
- 返回:
Hybridized DG swap.
- 返回类型:
- wy_qcos.transpiler.cmss.mapping.utils.dg_swap_opt.hybridization3(dg_swap1, dg_swap2, dg_ori)
For each exchange, we accept all exchanges in dg_swap1 and dg_swap2.
- wy_qcos.transpiler.cmss.mapping.utils.dg_swap_opt.hybridization4(dg_swap1, dg_swap2, dg_ori)
Hybridize two DG swaps with depth checking.
For each exchange, we use dg_swap1 and then try to exchange using dg_swap2 one-by-one and accept only that reducing depth.
- 参数:
dg_swap1 -- First DG swap.
dg_swap2 -- Second DG swap.
dg_ori -- Original DG.
- 返回:
Hybridized DG swap.
- 返回类型:
- class wy_qcos.transpiler.cmss.mapping.utils.dg_swap_opt.DGSwap(ag, cost_func='depth')
基类:
DG- clear_attrs()
- property depth
- property node_scores
- property cost
- property cost_depth
- property cost_depth_tie_break
- property depths
- get_score()
- add_to_exchange_log(exchange_nodes)
- from_qasm(file, path=None)
- add_depth_to_all_edges()
- add_depth_to_edge(edge)
- check_node_connectivity(node)
- exchangeable(node1, node2)
Unimplemented!
- random_mutation(mutate_time, max_try=None)
Randomly choose mutate_time node pairs to do exchanging.
- 返回:
The number of exchanges having been done.
- random_mutation2(max_try=None)
Randomly choose mutate_time node pairs to do exchanging.
Continue until depth is changed.
- 返回:
The number of exchanges having been done.
- random_mutation3(max_try)
Randomly choose mutate_time node pairs to do exchanging.
Accept this exchange only if cost is decreased. Try max_try times.
- exchange(node1, node2)
Exchange the positions of node1 and node2.
- cx_to_swap()
Try to combine all 3 consecutive CNOTs to 1 SWAP.
- swap_to_cx()
- get_node_cx_list(node)
If there existing SWAP, we decompose it into 3 CNOTs.
- qiskit_circuit(save_to_file=False, add_barrier=False, decompose_swap=False, file_name='circuit')
- depth_to_node_list()
Return 2 lists.
depth_to_node list, in which each indice indicates a specific depth and its value is also a list (length num_q), called qubit_to_node list. In qubit_to_node, each value, if not None, tells which node occupies that time slot.
node_to_depth list
Notice that in this mothod each node can contain more than one gate.
wy_qcos.transpiler.cmss.mapping.utils.estimate module
- class wy_qcos.transpiler.cmss.mapping.utils.estimate.NAEstimate(single_gate_duration=6, multi_gate_duration=2, move_duration=1000, single_gate_fidelity=0.995, multi_gate_fidelity=0.98, mov_fidelity=0.97)
基类:
object中性原子映射结果评估.
- 参数:
single_gate_duration (int, optional) -- 单比特门时间. Defaults to 6.
multi_gate_duration (int, optional) -- 两比特门时间. Defaults to 2.
move_duration (int, optional) -- 移动时间. Defaults to 1000.
single_gate_fidelity (float, optional) -- 单比特门保真度. 0.995.
multi_gate_fidelity (float, optional) -- 两比特门保真度. 0.98.
mov_fidelity (float, optional) -- 移动保真度. Defaults to 0.97.
- set_circuit(circuit)
- estimate_time()
估计运行时间.
- estimate_fidelity()
估计保真度.
- class wy_qcos.transpiler.cmss.mapping.utils.estimate.SCEstimate(single_gate_duration=10.0, multi_gate_duration=50.0, single_gate_fidelity=0.995, multi_gate_fidelity=0.98)
基类:
object基于swap的映射结果评估.
- 参数:
single_gate_duration (float, optional) -- 单比特门时间. Defaults to 10.0.
multi_gate_duration (float, optional) -- 两比特门时间. Defaults to 50.0.
single_gate_fidelity (float, optional) -- 单比特门保真度. 0.995.
multi_gate_fidelity (float, optional) -- 两比特门保真度. 0.98.
- set_circuit(circuit)
- estimate_time()
估计运行时间.
- estimate_fidelity()
估计保真度.
wy_qcos.transpiler.cmss.mapping.utils.front_circuit module
- wy_qcos.transpiler.cmss.mapping.utils.front_circuit.qubit_convert(q_list)
- class wy_qcos.transpiler.cmss.mapping.utils.front_circuit.FrontCircuit(DG, AG, front_cir_from=None)
基类:
object根据硬件拓扑、量子线路拓扑、映射表等来获取当前可执行的线路、可交换的比特等.
- 参数:
AG:硬件拓扑。
DG:量子线路拓扑。
num_q_log:逻辑比特数。
num_q_phy:物理比特数。
log_to_phy:逻辑比特到物理比特的映射表。
phy_to_log:物理比特到逻辑比特的映射表。
front_layer:量子线路拓扑中最前面一层的所有节点(门)。
- assign_mapping_from_list(map_list)
Here the indices in map_list represent logical qubits.
- assian_mapping_naive()
- swap(swap_phy)
交换门插入,此时需要更新映射表.
- copy()
- swap_new(swap_phy)
Use a SWAP to get a new FrontCircuit object.
- execute_front_layer()
Execute all gates in the front layer regardless of mapping.
However, we won't execute the following possible executable gates.
- execute_gates()
Find all executable gates and execute them.
- execute_gate_index(front_layer_i)
Execute specified gate without executing its successors.
- 参数:
front_layer_i -- Index of the gate in the front layer.
- execute_gate(node_DG)
Execute specified gate without executing its successors.
- 参数:
node_DG -- Node in the DG to be executed.
- execute_gate_remote(node_DG)
Execute a gate with remote CNOT and then execute all its successors.
- 参数:
node_DG -- Node in DG to be executed with remote CNOT.
- 返回:
- list1: [(cx1), cx2, ...] physical CNOTs needed
for remote gates. list2: [node1, node2, ...] newly executed nodes in DG excluding the input node_DG.
- 返回类型:
tuple[list, list]
- pertinent_swaps(score_layer)
Get available swap gates that can be inserted now.
- 参数:
score_layer -- Number of layers to consider for scoring each SWAP.
- 返回:
List of swap gates. h_scores: List of scores for each swap. h_scores_front: List of front scores for each swap.
- 返回类型:
swaps_phy
- print()
- print_front_layer_qubits()
Print the physical qubits in the front layer.
- print_front_layer_len()
Print the physical qubits in the front layer.
- get_future_cx_fix_num(num_cx)
Get a specific number of unexecuted cx info.
- 参数:
num_cx -- Number of CX gates to get.
- 返回:
List of first operand physical qubits. cx1: List of second operand physical qubits.
- 返回类型:
cx0
- get_future_cx_fix_num_with_single(num_cx)
Get a specific number of unexecuted cx info with single gate info.
- 参数:
num_cx -- Number of CX gates to get.
- 返回:
List of first operand physical qubits. cx1: List of second operand physical qubits. single_gate0: Number of single qubit gates for first qubit. single_gate1: Number of single qubit gates for second qubit.
- 返回类型:
cx0
- get_future_cx_fix_num2(num_cx)
Get a specific number of unexecuted cx info layer by layer.
- 参数:
num_cx -- Number of CX gates to get.
- 返回:
List of first operand physical qubits. cx1: List of second operand physical qubits.
- 返回类型:
cx0
- get_future_cx_fix_num3(num_cx)
Get a specific number of unexecuted cx info divided by layers.
This method obtains gates layer by layer and returns tuples dividing gates according their layers.
- 参数:
num_cx -- Number of CX gates to get.
- 返回:
- List of tuples where each tuple contains CX gates in one
layer.
- 返回类型:
list
- check_equal(cir2)
- get_cir_matrix(num_layer)
Create a numpy matrix representing the circuit with CNOT gates.
- 参数:
num_layer -- Number of layers.
- 返回:
Numpy matrix representing the circuit. i: Actual number of layers filled.
- 返回类型:
cir_map
wy_qcos.transpiler.cmss.mapping.utils.sabre_utils module
- wy_qcos.transpiler.cmss.mapping.utils.sabre_utils.normalize_topology(topology)
Normalize supported topology inputs into integer edge pairs.
- 参数:
topology (Topology) -- Topology edges, a networkx graph, or a qpu_cfg- style topology config.
- 返回:
Normalized physical coupling edges.
- 返回类型:
list[tuple[int, int]]