layout
¤
This module contains the Layout class, which is designed to select suitable layouts for quantum circuits on hardware backends.
Classes:
| Name | Description |
|---|---|
Layout |
Responsible for selecting suitable qubit layouts from a given chip for a quantum circuit. |
Layout(chip_backend: Backend)
¤
Responsible for selecting suitable qubit layouts from a given chip for a quantum circuit.
This class generates qubit layouts based on the required number of qubits, performance metrics, and the topology of the chip. It is designed to help map and execute quantum circuits on specific quantum hardware.
Initialize the Layout class with the required number of qubits and chip backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nqubits
|
int
|
The number of qubits needed in the layout. |
required |
chip_backend
|
Backend
|
An instance of the Backend class that contains the information |
required |
Methods:
| Name | Description |
|---|---|
get_one_node_subgraph |
Generates all possible subgraph combinations for a given node up to a specified number of nodes. |
collect_all_subgraph_in_parallel |
Collects all possible subgraph combinations for all nodes in the graph in parallel. |
get_one_subgraph_info |
Retrieves information about a specified subgraph. |
collect_all_subgraph_info_in_parallel |
Collects information about all subgraphs in parallel. |
classify_all_subgraph_according_topology |
Classify the collected subgraphs based on their topological structure into four categories. |
sort_subgraph_according_mean_fidelity |
Sort each of the four subgraph categories based on the main of fidelity on the edges (couplers), |
sort_subgraph_according_var_fidelity |
Sort each of the four subgraph categories based on the variance of fidelity on the edges (couplers), |
select_few_qubits_from_backend |
Select a qubit layout based on the given performance metric and topology. |
select_much_qubits_from_backend |
Perform a breadth-first search (BFS) on the graph starting from the start node, |
Source code in quark/circuit/layout.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
get_one_node_subgraph(node: int, nqubits: int)
¤
Generates all possible subgraph combinations for a given node up to a specified number of nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
int
|
The starting node for generating subgraph combinations. |
required |
Returns:
| Type | Description |
|---|---|
|
list[tuple]:A list of tuples, each representing a unique combination of nodes that form
a subgraph up to the specified |
Source code in quark/circuit/layout.py
85 86 87 88 89 90 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 | |
collect_all_subgraph_in_parallel(nqubits)
¤
Collects all possible subgraph combinations for all nodes in the graph in parallel.
Returns:
| Type | Description |
|---|---|
|
list[tuple]: A list of tuples, each representing a unique combination of nodes that form subgraphs for all nodes in the graph. |
Source code in quark/circuit/layout.py
127 128 129 130 131 132 133 134 135 136 137 138 139 | |
get_one_subgraph_info(nodes: tuple | list)
¤
Retrieves information about a specified subgraph.
This method generates a subgraph from the given list of nodes, calculates the degree of each node within the subgraph, and computes the mean and variance of the edge weights (fidelity) in the subgraph.It returns the subgraph information only if the mean fidelity meets the specified threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
tuple | list
|
A list of nodes that define the subgraph. |
required |
Returns:
| Type | Description |
|---|---|
|
tuple or None: A tuple containing the nodes, their degrees, mean fidelity, and variance of fidelity
if the mean fidelity is greater than or equal to |
Source code in quark/circuit/layout.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
collect_all_subgraph_info_in_parallel(nqubits: int)
¤
Collects information about all subgraphs in parallel.
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of results, where each entry corresponds to the information of a subgraph. |
Source code in quark/circuit/layout.py
194 195 196 197 198 199 200 201 202 203 | |
classify_all_subgraph_according_topology(nqubits: int) -> tuple[list, list, list, list]
¤
Classify the collected subgraphs based on their topological structure into four categories.
This function sorts the subgraphs into the following four categories: 1. Linear and connected, with all nodes in the same row of the chip. 2. Linear and connected, with nodes not in the same row. 3. Contains a cycle within the subgraph. 4. Non-linear and connected, where some nodes have more than three edges.
Returns:
| Type | Description |
|---|---|
list
|
tuple[list, list, list, list]: A tuple containing four lists, each corresponding |
list
|
to one of the four categories of subgraphs. |
Source code in quark/circuit/layout.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
sort_subgraph_according_mean_fidelity(nqubits: int, num: int = 1, printdetails: bool = True)
¤
Sort each of the four subgraph categories based on the main of fidelity on the edges (couplers), in ascending order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
printdetails
|
bool
|
If True, print details of the sorting process. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
|
tuple[list, list, list, list]: Four sorted lists, each corresponding to one of the four |
|
|
subgraph categories, with subgraphs sorted by edge fidelity variance. |
Source code in quark/circuit/layout.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
sort_subgraph_according_var_fidelity(nqubits: int, num: int = 1, printdetails: bool = True)
¤
Sort each of the four subgraph categories based on the variance of fidelity on the edges (couplers), in ascending order.
This function sorts the subgraphs within each category (from the previous classification) by the variance of fidelity across the edges in each subgraph, from lowest to highest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
printdetails
|
bool
|
If True, print details of the sorting process. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
|
tuple[list, list, list, list]: Four sorted lists, each corresponding to one of the four |
|
|
subgraph categories, with subgraphs sorted by edge fidelity variance. |
Source code in quark/circuit/layout.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
select_few_qubits_from_backend(nqubits: int, key: Literal['fidelity_mean', 'fidelity_var'] = 'fidelity_var', topology: Literal['linear', 'nonlinear'] = 'linear', printdetails: bool = False)
¤
Select a qubit layout based on the given performance metric and topology.
This function chooses a layout for the quantum circuit from the available subgraphs based on the specified key (performance metric) and topology type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Literal['fidelity_mean', 'fidelity_var']
|
The performance metric to use for selecting the layout. Either the mean fidelity ('fidelity_mean') or fidelity variance ('fidelity_var'). Defaults to 'fidelity_var'. |
'fidelity_var'
|
topology
|
Literal['cycle', 'linear1', 'linear', 'nonlinear']
|
The desired topology of the layout. It can be 'cycle', 'linear1' (connected, in the same row), 'linear' (connected, not necessarily in the same row), or 'nonlinear'. Defaults to 'linear1'. |
'linear'
|
printdetails
|
bool
|
If True, prints details about the selected layout. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of qubits representing the selected layout. |
Source code in quark/circuit/layout.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
select_much_qubits_from_backend(nqubits)
¤
Perform a breadth-first search (BFS) on the graph starting from the start node,
collecting up to nqubits unique nodes including the start node.
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of up to |
Source code in quark/circuit/layout.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |