quarkcircuit 0.3.0.dev1__tar.gz → 0.3.0.dev2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/PKG-INFO +2 -2
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/README.md +1 -1
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/pyproject.toml +1 -1
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/optimize.py +3 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/routing.py +103 -10
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/translate.py +6 -1
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quarkcircuit.egg-info/PKG-INFO +2 -2
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/__init__.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/backend.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/basepasses.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/dag.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/decompose.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/layout.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/matrix.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/quantumcircuit.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/quantumcircuit_helpers.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/test_transpiler.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/transpiler.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quark/circuit/utils.py +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quarkcircuit.egg-info/SOURCES.txt +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quarkcircuit.egg-info/dependency_links.txt +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quarkcircuit.egg-info/requires.txt +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quarkcircuit.egg-info/top_level.txt +0 -0
- {quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quarkcircuit
|
|
3
|
-
Version: 0.3.0.
|
|
3
|
+
Version: 0.3.0.dev2
|
|
4
4
|
Summary: Construction, visualization, and transpilation of quantum circuits
|
|
5
5
|
Author-email: Xiaoxiao Xiao <xiaoxx@baqis.ac.cn>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -38,7 +38,7 @@ pip install quarkcircuit
|
|
|
38
38
|
|
|
39
39
|
## First experience
|
|
40
40
|
|
|
41
|
-
See [quarkcircuit example](https://quarkstudio.readthedocs.io/en/latest/usage/code/
|
|
41
|
+
See [quarkcircuit example](https://quarkstudio.readthedocs.io/en/latest/usage/code/transpiler/)
|
|
42
42
|
|
|
43
43
|
## License
|
|
44
44
|
|
|
@@ -26,7 +26,7 @@ pip install quarkcircuit
|
|
|
26
26
|
|
|
27
27
|
## First experience
|
|
28
28
|
|
|
29
|
-
See [quarkcircuit example](https://quarkstudio.readthedocs.io/en/latest/usage/code/
|
|
29
|
+
See [quarkcircuit example](https://quarkstudio.readthedocs.io/en/latest/usage/code/transpiler/)
|
|
30
30
|
|
|
31
31
|
## License
|
|
32
32
|
|
|
@@ -40,6 +40,9 @@ from .basepasses import TranspilerPass
|
|
|
40
40
|
# 涉及大量dag读取操作,后期尝试rust加速
|
|
41
41
|
class GateCompressor(TranspilerPass):
|
|
42
42
|
"""A transpiler pass that merges or compresses adjacent gates in a quantum circuit.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
TranspilerPass (class): The base class that provides the structure for the transpiler pass.
|
|
43
46
|
"""
|
|
44
47
|
def __init__(self):
|
|
45
48
|
super().__init__()
|
|
@@ -91,8 +91,18 @@ def distance_matrix_element(qubit1:int,qubit2:int,coupling_graph:nx.Graph) -> in
|
|
|
91
91
|
return dis
|
|
92
92
|
|
|
93
93
|
def mapping_node_to_gate_info(node:str,
|
|
94
|
-
dag:
|
|
94
|
+
dag:nx.DiGraph,
|
|
95
95
|
v2p:dict) -> tuple:
|
|
96
|
+
"""Map a DAG node to its corresponding gate information.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
node (str): The identifier of the node in the DAG.
|
|
100
|
+
dag (nx.DiGraph): The DAG representing the quantum circuit.
|
|
101
|
+
v2p (dict): A dictionary mapping virtual qubits to physical qubits.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
tuple: A tuple containing gate information.
|
|
105
|
+
"""
|
|
96
106
|
gate = node.split('_')[0]
|
|
97
107
|
if gate in one_qubit_gates_available.keys():
|
|
98
108
|
qubit0 = dag.nodes[node]['qubits'][0]
|
|
@@ -131,7 +141,17 @@ def mapping_node_to_gate_info(node:str,
|
|
|
131
141
|
gate_info = (gate,v2p[qubit0])
|
|
132
142
|
return gate_info
|
|
133
143
|
|
|
134
|
-
def is_correlation_on_front_layer(node, front_layer,dag):
|
|
144
|
+
def is_correlation_on_front_layer(node:str, front_layer:list, dag:nx.DiGraph) -> bool:
|
|
145
|
+
"""Check if the given node in the DAG is correlated with any node in the front layer.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
node (str): The identifier of the node in the DAG.
|
|
149
|
+
front_layer (list): A list of node identifiers representing the front layer.
|
|
150
|
+
dag (nx.DiGraph): The directed acyclic graph (DAG) representing the quantum circuit.
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
bool: True if the node is correlated with any node in the front layer, otherwise False.
|
|
154
|
+
"""
|
|
135
155
|
qubitlst = []
|
|
136
156
|
for fnode in front_layer:
|
|
137
157
|
qubits = dag.nodes[fnode]['qubits']
|
|
@@ -144,7 +164,19 @@ def is_correlation_on_front_layer(node, front_layer,dag):
|
|
|
144
164
|
else:
|
|
145
165
|
return False
|
|
146
166
|
|
|
147
|
-
def update_v2p_and_p2v_mapping(v2p,swap_gate_info):
|
|
167
|
+
def update_v2p_and_p2v_mapping(v2p:dict,swap_gate_info:tuple) -> tuple[dict,dict]:
|
|
168
|
+
"""Update v2p and p2v mappings based on the given SWAP gate.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
v2p (dict): A dictionary mapping virtual qubits to physical qubits.
|
|
172
|
+
swap_gate_info (tuple): A tuple containing gate information. The format is
|
|
173
|
+
(gate_name, vq1, vq2), where vq1 and vq2 are the virtual qubits being swapped.
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
tuple[dict, dict]:
|
|
177
|
+
- Updated v2p mapping after applying the SWAP.
|
|
178
|
+
- Updated p2v mapping.
|
|
179
|
+
"""
|
|
148
180
|
v2p = copy.deepcopy(v2p)
|
|
149
181
|
vq1,vq2 = swap_gate_info[1:]
|
|
150
182
|
v2p[vq1],v2p[vq2] = v2p[vq2],v2p[vq1]
|
|
@@ -152,8 +184,8 @@ def update_v2p_and_p2v_mapping(v2p,swap_gate_info):
|
|
|
152
184
|
return v2p,p2v
|
|
153
185
|
|
|
154
186
|
def heuristic_function_parallel(swap_gate_info: tuple,
|
|
155
|
-
coupling_graph:
|
|
156
|
-
dag:
|
|
187
|
+
coupling_graph: nx.Graph,
|
|
188
|
+
dag: nx.DiGraph,
|
|
157
189
|
front_layer: list,
|
|
158
190
|
v2p:dict,
|
|
159
191
|
decay_parameter: list,
|
|
@@ -197,9 +229,16 @@ def heuristic_function_parallel(swap_gate_info: tuple,
|
|
|
197
229
|
#print('score',swap_gate_info,f_distance,size_F,W,e_distance,max_decay)
|
|
198
230
|
return H
|
|
199
231
|
|
|
200
|
-
def create_extended_successor_set(front_layer: list, dag:
|
|
201
|
-
"""
|
|
202
|
-
|
|
232
|
+
def create_extended_successor_set(front_layer: list, dag: nx.DiGraph) -> list:
|
|
233
|
+
"""Create an extended set for the front layer.
|
|
234
|
+
|
|
235
|
+
Args:
|
|
236
|
+
front_layer (list): A list of node identifiers representing the front layer.
|
|
237
|
+
dag (nx.DiGraph): The directed acyclic graph (DAG) representing the quantum circuit.
|
|
238
|
+
|
|
239
|
+
Returns:
|
|
240
|
+
list: A list of node identifiers representing the extended set of the front layer.
|
|
241
|
+
"""
|
|
203
242
|
E = []
|
|
204
243
|
for node in front_layer:
|
|
205
244
|
for node_successor in dag.successors(node):
|
|
@@ -208,7 +247,17 @@ def create_extended_successor_set(front_layer: list, dag: 'nx.DiGraph') -> list:
|
|
|
208
247
|
E.append(node_successor)
|
|
209
248
|
return list(set(E))
|
|
210
249
|
|
|
211
|
-
def update_decay_parameter(min_score_swap_gate_info: tuple, decay_parameter: list,v2p:dict) -> list:
|
|
250
|
+
def update_decay_parameter(min_score_swap_gate_info: tuple, decay_parameter: list, v2p:dict) -> list:
|
|
251
|
+
"""Update the decay parameter after applying the SWAP gate with the minimum score.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
min_score_swap_gate_info (tuple): A tuple representing the SWAP gate with the minimum score.
|
|
255
|
+
decay_parameter (list): A list of decay parameters, where each index corresponds to a physical qubit.
|
|
256
|
+
v2p (dict): A dictionary mapping virtual qubits to physical qubits.
|
|
257
|
+
|
|
258
|
+
Returns:
|
|
259
|
+
list: The updated list of decay parameters.
|
|
260
|
+
"""
|
|
212
261
|
min_score_swap_qubits = list(min_score_swap_gate_info[1:])
|
|
213
262
|
pq1 = v2p[min_score_swap_qubits[0]]
|
|
214
263
|
pq2 = v2p[min_score_swap_qubits[1]]
|
|
@@ -216,7 +265,31 @@ def update_decay_parameter(min_score_swap_gate_info: tuple, decay_parameter: lis
|
|
|
216
265
|
decay_parameter[pq2] = decay_parameter[pq2] + 0.01
|
|
217
266
|
return decay_parameter
|
|
218
267
|
|
|
219
|
-
def gates_sabre_routing_once(
|
|
268
|
+
def gates_sabre_routing_once(
|
|
269
|
+
dag:nx.DiGraph,
|
|
270
|
+
v2p:dict,
|
|
271
|
+
coupling_graph:nx.Graph,
|
|
272
|
+
largest_qubits_index:int,
|
|
273
|
+
map_node_to_gate:bool,
|
|
274
|
+
do_random_choice:bool=False
|
|
275
|
+
) -> tuple[list,dict]:
|
|
276
|
+
"""Perform a single iteration of SABRE routing to generate gates and update v2p.
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
dag (nx.DiGraph): The directed acyclic graph (DAG) representing the quantum circuit.
|
|
280
|
+
v2p (dict): A dictionary mapping virtual qubits to physical qubits.
|
|
281
|
+
coupling_graph (nx.Graph): The coupling graph selected from the hardware, representing
|
|
282
|
+
only the physical qubits involved in the current circuit.
|
|
283
|
+
largest_qubits_index (int): The index of the largest physical qubit in the coupling graph.
|
|
284
|
+
map_node_to_gate (bool): Whether to map nodes in the DAG to corresponding gate operations.
|
|
285
|
+
do_random_choice (bool, optional): Whether to randomly choose a SWAP when multiple options
|
|
286
|
+
have the same heuristic score. Defaults to False.
|
|
287
|
+
|
|
288
|
+
Returns:
|
|
289
|
+
tuple[list, dict]:
|
|
290
|
+
- list: The list of gates generated after applying the SWAP sequence.
|
|
291
|
+
- dict: The updated v2p mapping after the SWAP operations.
|
|
292
|
+
"""
|
|
220
293
|
if len(v2p)>1:
|
|
221
294
|
assert(len(coupling_graph.nodes)==len(v2p))
|
|
222
295
|
p2v = {p:v for v,p in v2p.items()}
|
|
@@ -310,7 +383,27 @@ def gates_sabre_routing_once(dag,v2p,coupling_graph,largest_qubits_index,map_nod
|
|
|
310
383
|
return new,v2p
|
|
311
384
|
|
|
312
385
|
class SabreRouting(TranspilerPass):
|
|
386
|
+
"""SABRE-based routing pass for quantum circuit transpilation.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
TranspilerPass (class): The base class that provides the infrastructure for
|
|
390
|
+
the transpiler pass functionality.
|
|
391
|
+
"""
|
|
313
392
|
def __init__(self,subgraph:nx.Graph,initial_mapping:Literal['random','trivial']='trivial',do_random_choice:bool=False,iterations: int = 5):
|
|
393
|
+
"""Initializes the SabreRouting class with the specified settings.
|
|
394
|
+
|
|
395
|
+
Args:
|
|
396
|
+
subgraph (nx.Graph): A subgraph of the hardware's coupling graph, containing
|
|
397
|
+
only the physical qubits relevant for the current circuit.
|
|
398
|
+
initial_mapping (Literal['random','trivial'], optional): Strategy for initializing
|
|
399
|
+
the virtual-to-physical qubit mapping. Options:
|
|
400
|
+
- 'trivial': Maps virtual qubits to physical qubits sequentially.
|
|
401
|
+
- 'random': Maps virtual qubits to physical qubits randomly.
|
|
402
|
+
Defaults to 'trivial'.
|
|
403
|
+
do_random_choice (bool, optional): If True, randomly chooses a SWAP when
|
|
404
|
+
multiple options have the same score. Defaults to False.
|
|
405
|
+
iterations (int, optional): The number of iterations for the SABRE routing process. Defaults to 5.
|
|
406
|
+
"""
|
|
314
407
|
super().__init__()
|
|
315
408
|
self.coupling_graph = subgraph
|
|
316
409
|
self.initial_mapping = initial_mapping
|
|
@@ -39,8 +39,13 @@ from .decompose import (cx_decompose,
|
|
|
39
39
|
from .basepasses import TranspilerPass
|
|
40
40
|
|
|
41
41
|
class TranslateToBasisGates(TranspilerPass):
|
|
42
|
+
"""Transpiler pass for converting quantum gates to hardware-specific basis gates.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
TranspilerPass (class): The base class that provides the structure for the transpiler pass.
|
|
46
|
+
"""
|
|
42
47
|
def __init__(self,convert_single_qubit_gate_to_u:bool=True, two_qubit_gate_basis: Literal['cz','cx']='cz'):
|
|
43
|
-
"""
|
|
48
|
+
"""Initializes the TranslateToBasisGates class with the specified settings.
|
|
44
49
|
|
|
45
50
|
Args:
|
|
46
51
|
convert_single_qubit_gate_to_u (bool, optional): If True, converts all single-qubit gates into U3 gates. Defaults to True.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quarkcircuit
|
|
3
|
-
Version: 0.3.0.
|
|
3
|
+
Version: 0.3.0.dev2
|
|
4
4
|
Summary: Construction, visualization, and transpilation of quantum circuits
|
|
5
5
|
Author-email: Xiaoxiao Xiao <xiaoxx@baqis.ac.cn>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -38,7 +38,7 @@ pip install quarkcircuit
|
|
|
38
38
|
|
|
39
39
|
## First experience
|
|
40
40
|
|
|
41
|
-
See [quarkcircuit example](https://quarkstudio.readthedocs.io/en/latest/usage/code/
|
|
41
|
+
See [quarkcircuit example](https://quarkstudio.readthedocs.io/en/latest/usage/code/transpiler/)
|
|
42
42
|
|
|
43
43
|
## License
|
|
44
44
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quarkcircuit-0.3.0.dev1 → quarkcircuit-0.3.0.dev2}/quarkcircuit.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|