1 from typing
import Literal
6 from squander
import utils
8 from squander.partitioning.kahn
import kahn_partition
9 from squander.partitioning.ilp
import max_partitions
10 from squander.partitioning.tdag
import tdag_max_partitions
11 from squander.partitioning.tools
import (
12 translate_param_order,
13 get_qiskit_partitions,
14 get_qiskit_fusion_partitions,
15 get_bqskit_partitions,
18 PartitionStrategy = Literal[
32 PARTITION_FUNCTIONS = {
33 "kahn": kahn_partition,
34 "ilp": max_partitions,
35 "ilp-fusion": functools.partial(max_partitions, fusion_cost=
True),
36 "ilp-fusion-ca": functools.partial(
37 max_partitions, fusion_cost=
True, control_aware=
True 39 "tdag": tdag_max_partitions,
40 "gtqcp": functools.partial(tdag_max_partitions, use_gtqcp=
True),
41 "qiskit": get_qiskit_partitions,
42 "qiskit-fusion": get_qiskit_fusion_partitions,
43 "bqskit-Quick": functools.partial(get_bqskit_partitions, partitioner=
"Quick"),
44 "bqskit-Scan": functools.partial(get_bqskit_partitions, partitioner=
"Scan"),
45 "bqskit-Greedy": functools.partial(get_bqskit_partitions, partitioner=
"Greedy"),
46 "bqskit-Cluster": functools.partial(get_bqskit_partitions, partitioner=
"Cluster"),
52 parameters: np.ndarray,
53 max_partition_size: int,
54 strategy: PartitionStrategy =
"kahn",
56 ) -> tuple[Circuit, np.ndarray, list[int]]:
58 Call to partition a circuit 62 circ ( Circuit ) A circuit to be partitioned 64 parameters ( np.ndarray ) A parameter array associated with the input circuit 66 max_partition_size (int) : The maximal number of qubits in the partitions 68 strategy (PartitionStrategy, optional) Set to ILP (slow, but giving optimal result), TDAG, or KAHN (default) 72 Returns with the paritioned circuit and the associated parameter array. Partitions are organized into subcircuits of the resulting circuit 75 func = PARTITION_FUNCTIONS.get(strategy, kahn_partition)
84 parameters, partitioned_circ, param_order, L = func(
85 filename, max_partition_size
88 partitioned_circ, param_order, L = func(circ, max_partition_size)
91 return partitioned_circ, param_reordered, L
95 filename: str, max_partition_size: int, strategy: PartitionStrategy =
"kahn" 96 ) -> tuple[Circuit, np.ndarray, list[int]]:
98 Call to partition a circuit loaded from a qasm file 102 filename ( str ) A path to a qasm file to be imported 104 max_partition_size (int) : The maximal number of qubits in the partitions 106 strategy (PartitionStrategy, optional) Set to ilp (slow, but giving optimal result), tdag, or kahn (default) 110 Returns with the paritioned circuit and the associated parameter array. Partitions are organized into subcircuits of the resulting circuit 113 circ, parameters, _ = utils.qasm_to_squander_circuit(filename)
114 return PartitionCircuit(circ, parameters, max_partition_size, strategy, filename)
117 if __name__ ==
"__main__":