routing
¤
A toolkit for the SABRE algorithm.
Classes:
| Name | Description |
|---|---|
SabreRouting |
SABRE-based routing pass for quantum circuit transpilation. |
Functions:
| Name | Description |
|---|---|
extract_qubits |
Extracts qubit indices from the node name string. |
update_v2p_and_p2v_mapping |
Update v2p and p2v mappings based on the given SWAP gate. |
SabreRouting(subgraph: nx.Graph, initial_mapping: Literal['random', 'trivial'] | list = 'trivial', do_random_choice: bool = False, iterations: int = 5, heuristic: Literal['basic', 'lookahead', 'basic_decay', 'lookahead_decay'] = 'lookahead_decay', max_extended_set_weight: float = 0.5)
¤
Bases: TranspilerPass
SABRE-based routing pass for quantum circuit transpilation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
TranspilerPass
|
class
|
The base class that provides the infrastructure for the transpiler pass functionality. |
required |
Initializes the SabreRouting class with the specified settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subgraph
|
Graph
|
A subgraph of the hardware's coupling graph, containing only the physical qubits relevant for the current circuit. |
required |
initial_mapping
|
Literal['random', 'trivial']
|
Strategy for initializing the virtual-to-physical qubit mapping. Options: - 'trivial': Maps virtual qubits to physical qubits sequentially. - 'random': Maps virtual qubits to physical qubits randomly. Defaults to 'trivial'. |
'trivial'
|
do_random_choice
|
bool
|
If True, randomly chooses a SWAP when multiple options have the same score. Defaults to False. |
False
|
iterations
|
int
|
The number of iterations for the SABRE routing process. Defaults to 5. |
5
|
heuristic
|
Literal['basic', 'lookahead', 'basic_decay', 'lookahead_decay']
|
The heuristic strategy used to evaluate candidate SWAP gates.Defaults to 'lookahead_decay'. |
'lookahead_decay'
|
max_extended_set_weight
|
float
|
The max weight of extended set. Defaults to 0.5. |
0.5
|
Methods:
| Name | Description |
|---|---|
run |
Routing based on the Sabre algorithm. |
Source code in quark/circuit/routing.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
run(qc: QuantumCircuit)
¤
Routing based on the Sabre algorithm. Args: iterations (int, optional): The number of iterations. Defaults to 1. Returns: Transpiler: Update self information.
Source code in quark/circuit/routing.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | |
extract_qubits(node_name: str)
¤
Extracts qubit indices from the node name string.
This function parses the node name to find all qubit indices specified within square brackets (e.g., "[0,1]"), using regular expressions. It provides a faster alternative to accessing the 'qubits' attribute from a DAG node (e.g., dag.nodes[node]['qubits']).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
str
|
The name of the node, expected to contain qubit information in square brackets. |
required |
Returns:
| Type | Description |
|---|---|
|
List[int]: A list of qubit indices as integers, extracted in order |
|
|
of appearance. Returns an empty list if no qubit information is found. |
Source code in quark/circuit/routing.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
update_v2p_and_p2v_mapping(v2p: dict, swap_gate_info: tuple) -> tuple[dict, dict]
¤
Update v2p and p2v mappings based on the given SWAP gate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v2p
|
dict
|
A dictionary mapping virtual qubits to physical qubits. |
required |
swap_gate_info
|
tuple
|
A tuple containing gate information. The format is (gate_name, vq1, vq2), where vq1 and vq2 are the virtual qubits being swapped. |
required |
Returns:
| Type | Description |
|---|---|
tuple[dict, dict]
|
tuple[dict, dict]: - Updated v2p mapping after applying the SWAP. - Updated p2v mapping. |
Source code in quark/circuit/routing.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |