diff --git a/app/partition.py b/app/partition.py index 0f44402..8f707fc 100644 --- a/app/partition.py +++ b/app/partition.py @@ -3,6 +3,8 @@ from qiskit.converters import circuit_to_dagdependency from qiskit.dagcircuit import DAGDependency +PATH_KAHYPAR_CONFIG = "./../kahypar.ini" + def dag_to_hypergraph(dag: DAGDependency, k=2): n = len(dag.qubits) @@ -50,7 +52,7 @@ def get_partitions(circuit_or_dag, num_partitions, max_partition_size, verbose=F raise TypeError("Input has to be either a QuantumCircuit or DAGDependency") hypergraph = dag_to_hypergraph(dag, num_partitions) context = kahypar.Context() - context.loadINIconfiguration("kahypar.ini") + context.loadINIconfiguration(PATH_KAHYPAR_CONFIG) context.setK(num_partitions) if isinstance(max_partition_size, int): max_partition_size = [max_partition_size for _ in range(num_partitions)] diff --git a/test/test_partition.py b/test/test_partition.py new file mode 100644 index 0000000..c42a495 --- /dev/null +++ b/test/test_partition.py @@ -0,0 +1,32 @@ +import unittest +import numpy as np +from qiskit.circuit.library import EfficientSU2 + +from app.partition import get_partitions + + +class PartitionTestCase(unittest.TestCase): + def test_get_partitions(self): + num_qubits = 7 + num_partitions = 2 + circuit = EfficientSU2( + num_qubits=num_qubits, + reps=2, + entanglement="full", + su2_gates=["ry"], + ) + circuit = circuit.decompose() + + params = [(np.pi * i) / 16 for i in range(len(circuit.parameters))] + circuit = circuit.bind_parameters(params) + partitions, partition_sizes = get_partitions( + circuit, + num_partitions=num_partitions, + max_partition_size=int(np.ceil(num_qubits / 2)), + ) + print(partitions) + print(partition_sizes) + self.assertEquals(len(partition_sizes), num_partitions) + self.assertTrue( + all([size <= np.ceil(num_qubits / 2) for size in partition_sizes]) + )