From 308752d1e506030e6a3a615d4ca28cf8653d640b Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 8 Jun 2022 08:45:32 +0200 Subject: [PATCH 001/231] =?UTF-8?q?=E2=9C=A8=20added=20helper=20functions?= =?UTF-8?q?=20and=20files=20for=20both=20qiskit=20and=20tket=20compiler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/qiskit_helper.py | 18 ++++++++++++++++++ mqt/bench/utils/tket_helper.py | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 mqt/bench/utils/qiskit_helper.py create mode 100644 mqt/bench/utils/tket_helper.py diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py new file mode 100644 index 000000000..29c5b355e --- /dev/null +++ b/mqt/bench/utils/qiskit_helper.py @@ -0,0 +1,18 @@ +def get_ibm_native_gates(): + ibm_gates = ["rz", "sx", "x", "cx", "measure"] + return ibm_gates + + +def get_rigetti_native_gates(): + rigetti_gates = ["rx", "rz", "cz", "measure"] + return rigetti_gates + + +def get_ionq_native_gates(): + ionq_gates = ["rxx", "rz", "ry", "rx", "measure"] + return ionq_gates + + +def get_oqc_native_gates(): + oqc_gates = ["rz", "sx", "x", "ecr", "measure"] + return oqc_gates \ No newline at end of file diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py new file mode 100644 index 000000000..f72b872a4 --- /dev/null +++ b/mqt/bench/utils/tket_helper.py @@ -0,0 +1,21 @@ +from pytket.passes import auto_rebase_pass +from pytket import OpType + +def get_ionq_rebase(): + ionq_rebase = auto_rebase_pass({OpType.Rz, OpType.Ry, OpType.Rx, OpType.XXPhase, OpType.Measure}) + return ionq_rebase + + +def get_oqc_rebase(): + oqc_rebase = auto_rebase_pass({OpType.Rz, OpType.SX, OpType.X, OpType.ECR, OpType.Measure}) + return oqc_rebase + + +def get_rigetti_rebase(): + rigetti_rebase = auto_rebase_pass({OpType.Rz, OpType.Rx, OpType.CZ, OpType.Measure}) + return rigetti_rebase + + +def get_ibm_rebase(): + ibm_rebase = auto_rebase_pass({OpType.Rz, OpType.SX, OpType.X, OpType.CX, OpType.Measure}) + return ibm_rebase \ No newline at end of file From f7b6544f227d70223d9255e80ee2183d5c1a2f01 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 8 Jun 2022 08:49:23 +0200 Subject: [PATCH 002/231] =?UTF-8?q?=E2=9C=A8=20removed=20characteristics?= =?UTF-8?q?=20funtionalities?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 105 +++++-------------------------- 1 file changed, 14 insertions(+), 91 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 7e3504002..212dc6611 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -22,6 +22,8 @@ ) from mqt.bench.benchmarks.qiskit_application_nature import groundstate, excitedstate +from qiskit_helper import * + def init_module_paths(): global benchmarks_module_paths_dict @@ -50,7 +52,6 @@ def init_module_paths(): def create_benchmarks_from_config(cfg_path: str): init_module_paths() - characteristics = [] with open(cfg_path, "r") as jsonfile: cfg = json.load(jsonfile) @@ -69,8 +70,8 @@ def create_benchmarks_from_config(cfg_path: str): for benchmark in cfg["benchmarks"]: print(benchmark["name"]) - characteristics.extend(generate_benchmark(benchmark)) - return characteristics + generate_benchmark(benchmark) + return def benchmark_generation_watcher(func, args): @@ -183,7 +184,6 @@ def timeout_handler(signum, frame): # Custom signal handler def generate_benchmark(benchmark): - characteristics = [] if benchmark["include"]: if benchmark["name"] == "grover" or benchmark["name"] == "qwalk": for anc_mode in benchmark["ancillary_mode"]: @@ -200,7 +200,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) elif benchmark["name"] == "shor": for choice in benchmark["instances"]: @@ -210,7 +209,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) elif benchmark["name"] == "hhl": for i in range(benchmark["min_index"], benchmark["max_index"]): @@ -220,7 +218,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) elif benchmark["name"] == "routing": for nodes in range(benchmark["min_nodes"], benchmark["max_nodes"]): @@ -230,7 +227,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) elif benchmark["name"] == "tsp": for nodes in range(benchmark["min_nodes"], benchmark["max_nodes"]): @@ -240,7 +236,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) elif benchmark["name"] == "groundstate": for choice in benchmark["instances"]: @@ -250,7 +245,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) elif benchmark["name"] == "excitedstate": for choice in benchmark["instances"]: @@ -260,7 +254,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) elif benchmark["name"] == "pricingcall": for nodes in range( @@ -272,7 +265,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) elif benchmark["name"] == "pricingput": for nodes in range( @@ -284,7 +276,6 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) else: for n in range( benchmark["min_qubits"], benchmark["max_qubits"], benchmark["stepsize"] @@ -300,60 +291,34 @@ def generate_benchmark(benchmark): res = generate_circuits_on_all_levels(*res_qc_creation) if len(res) == 0: break - characteristics.extend(res) - return characteristics + return def generate_circuits_on_all_levels(qc, num_qubits, file_precheck): - characteristics = [] - # filename_algo, depth = generate_algo_level_circuit(qc, n) - # characteristics.append([filename_algo, n, depth]) res_t_indep = generate_target_indep_level_circuit(qc, num_qubits, file_precheck) - - if res_t_indep: - characteristics.extend(res_t_indep) - else: - return characteristics + if not res_t_indep: + return False res_t_dep = generate_target_dep_level_circuit(qc, num_qubits, file_precheck) + if not res_t_dep: + return False - if res_t_dep: - characteristics.extend(res_t_dep) - else: - return characteristics - - return characteristics - - -def generate_algo_level_circuit( - qc: QuantumCircuit, - num_qubits: int, -): - characteristics = [] - res = benchmark_generation_watcher(utils.handle_algorithm_level, [qc, num_qubits]) - characteristics.append(res) + return - if res: - characteristics.append(res) - return characteristics - else: - return False def generate_target_indep_level_circuit( qc: QuantumCircuit, num_qubits: int, file_precheck ): - characteristics = [] res = benchmark_generation_watcher( utils.get_indep_level, [qc, num_qubits, file_precheck], ) if res: - characteristics.append(res) - return characteristics + return else: return False @@ -399,42 +364,13 @@ def generate_target_dep_level_circuit( gate_set_name, opt_level, n_actual, - True, - file_precheck, - ], - ) - - if res: - characteristics.append(res) - else: - break - res = benchmark_generation_watcher( - utils.get_mapped_level, - [ - qc, - gate_set, - gate_set_name, - opt_level, - n_actual, - False, file_precheck, ], ) - - if res: - characteristics.append(res) - else: + if not res: break - except Exception as e: - print( - "\n Problem occured in inner loop: ", - qc.name, - num_qubits, - gate_set_name, - e, - ) - return characteristics + return def create_scalable_qc(benchmark, num_qubits, ancillary_mode=None): @@ -576,18 +512,6 @@ def create_pricingput_qc(num_uncertainty: int): ) -def save_benchmark_hist(characteristics): - characteristics = np.array(characteristics) - plt.scatter( - x=characteristics[:, 2].astype(int), y=characteristics[:, 1].astype(int) - ) - plt.yscale("log") - plt.title("Depth and Width of generated Benchmarks") - plt.xlabel("# of Qubits") - plt.ylabel("Circuit Depth") - plt.savefig("benchmark_histogram") - - def get_one_benchmark( benchmark_name: str, level: Union[str, int], @@ -719,5 +643,4 @@ def get_one_benchmark( args = parser.parse_args() print(args.file_name) - characteristics = create_benchmarks_from_config(args.file_name) - save_benchmark_hist(characteristics) + create_benchmarks_from_config(args.file_name) From cbf7e4e564e8c8ac261cd2102f49b5c0544ed001 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 8 Jun 2022 10:13:04 +0200 Subject: [PATCH 003/231] =?UTF-8?q?=F0=9F=9A=A7=20progress=20on=20workflow?= =?UTF-8?q?=20adaption?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 391 ++++++++++++++++++------------- 1 file changed, 229 insertions(+), 162 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 212dc6611..980ba62a7 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -22,7 +22,9 @@ ) from mqt.bench.benchmarks.qiskit_application_nature import groundstate, excitedstate -from qiskit_helper import * +from pytket.extensions.qiskit import qiskit_to_tk + +import qiskit_helper def init_module_paths(): @@ -308,7 +310,6 @@ def generate_circuits_on_all_levels(qc, num_qubits, file_precheck): return - def generate_target_indep_level_circuit( qc: QuantumCircuit, num_qubits: int, file_precheck ): @@ -326,50 +327,109 @@ def generate_target_indep_level_circuit( def generate_target_dep_level_circuit( qc: QuantumCircuit, num_qubits: int, file_precheck ): - characteristics = [] - - ibm_native_gates = utils.FakeMontreal().configuration().basis_gates - rigetti_native_gates = utils.get_rigetti_native_gates() - gate_sets = [(ibm_native_gates, "ibm"), (rigetti_native_gates, "rigetti")] - - for gate_set, gate_set_name in gate_sets: - try: - for opt_level in range(4): - - # Creating the circuit on target-dependent: native gates level - - res = benchmark_generation_watcher( - utils.get_native_gates_level, - [ - qc, - gate_set, - gate_set_name, - opt_level, - num_qubits, - file_precheck, - ], - ) - if res: - characteristics.append(res) - else: - break - n_actual = res[2] - # Creating the circuit on target-dependent: mapped level for both mapping schemes - res = benchmark_generation_watcher( - utils.get_mapped_level, - [ - qc, - gate_set, - gate_set_name, - opt_level, - n_actual, - file_precheck, - ], - ) - if not res: - break + compilation_paths = [ + ("ibm", [("ibm_washington", 127), ("ibm_montreal", 27)]), + ("rigetti", [("aspen_m1", 80)]), + ("ionq", [("ionq11", 11)]), + ("oqc", [("lucy", 8)]), + ] + + for gate_set, devices in compilation_paths: + # Creating the circuit on both target-dependent levels for qiskit + for opt_level in range(4): + res = benchmark_generation_watcher( + qiskit_helper.get_native_gates_level, + [ + qc, + gate_set_name, + opt_level, + num_qubits, + file_precheck, + ], + ) + if not res: + break + n_actual = res[2] + for device, max_qubits in devices: + # Creating the circuit on target-dependent: mapped level for both mapping schemes + if max_qubits >= qc.num_qubits: + res = benchmark_generation_watcher( + qiskit_helper.get_mapped_level, + [ + qc, + gate_set_name, + device_name, + opt_level, + n_actual, + file_precheck, + ], + ) + if not res: + print( + "Mapped circuit failed for: ", + qc, + gate_set_name, + device_name, + opt_level, + n_actual, + file_precheck, + ) + + # Creating the circuit on both target-dependent levels for tket + + qc_tket = qiskit_to_tk(qc) + res = benchmark_generation_watcher( + tket_helper.get_native_gates_level, + [ + qc_tket.copy(), + gate_set, + gate_set_name, + opt_level, + num_qubits, + file_precheck, + ], + ) + if not res: + print( + "Mapped circuit failed for: ", + qc_tket.copy(), + gate_set, + gate_set_name, + opt_level, + num_qubits, + file_precheck, + ) + if not res: + break + n_actual = res[2] + + for device, max_qubits in devices: + if max_qubits >= qc.num_qubits: + for lineplacement in set(False, True): + # Creating the circuit on target-dependent: mapped level for both mapping schemes + res = benchmark_generation_watcher( + tket_helper.get_mapped_level, + [ + qc_tket.copy(), + gate_set_name, + device_name, + lineplacement, + n_actual, + file_precheck, + ], + ) + if not res: + print( + "Mapped circuit failed for: ", + qc_tket.copy(), + gate_set, + gate_set_name, + opt_level, + num_qubits, + file_precheck, + ) return @@ -512,124 +572,131 @@ def create_pricingput_qc(num_uncertainty: int): ) -def get_one_benchmark( - benchmark_name: str, - level: Union[str, int], - circuit_size: int = None, - benchmark_instance_name: str = None, - opt_level: int = 0, - gate_set_name: str = "ibm", - smallest_fitting_arch: bool = True, -): - """Returns one benchmark as a Qiskit::QuantumCircuit Object. - - Keyword arguments: - benchmark_name -- name of the to be generated benchmark - level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where - circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number - benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" - 0 corresponds to "alg" level and 3 to "mapped" level - opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) - gate_set_name -- Either "ibm" or "rigetti" - smallest_fitting_arch -- True->Smallest architecture is selected, False->Biggest one is selected (ibm: 127 qubits, - rigetti: 80 qubits) - - - Return values: - QuantumCircuit -- Representing the benchmark with the selected options - """ - init_module_paths() - ibm_native_gates = utils.FakeMontreal().configuration().basis_gates - rigetti_native_gates = utils.get_rigetti_native_gates() - - if gate_set_name and "ibm" in gate_set_name: - gate_set = ibm_native_gates - elif gate_set_name and "rigetti" in gate_set_name: - gate_set = rigetti_native_gates - else: - gate_set = None - - if "grover" in benchmark_name or "qwalk" in benchmark_name: - if "noancilla" in benchmark_name: - anc_mode = "noancilla" - elif "v-chain" in benchmark_name: - anc_mode = "v-chain" - - short_name = benchmark_name.split("-")[0] - lib = importlib.import_module(benchmarks_module_paths_dict[short_name]) - qc = lib.create_circuit(circuit_size, ancillary_mode=anc_mode) - qc.name = qc.name + "-" + anc_mode - - elif benchmark_name == "shor": - instances = { - "xsmall": [9, 4], # 18 qubits - "small": [15, 4], # 18 qubits - "medium": [821, 4], # 42 qubits - "large": [11777, 4], # 58 qubits - "xlarge": [201209, 4], # 74 qubits - } - - qc = shor.create_circuit(*instances[benchmark_instance_name]) - - elif benchmark_name == "hhl": - qc = hhl.create_circuit(circuit_size) - - elif benchmark_name == "routing": - qc = routing.create_circuit(circuit_size) - - elif benchmark_name == "tsp": - qc = tsp.create_circuit(circuit_size) - - elif benchmark_name == "groundstate": - molecule = utils.get_molecule(benchmark_instance_name) - qc = groundstate.create_circuit(molecule) - - elif benchmark_name == "excitedstate": - molecule = utils.get_molecule(benchmark_instance_name) - qc = excitedstate.create_circuit(molecule) - - elif benchmark_name == "pricingcall": - qc = pricingcall.create_circuit(circuit_size) - - elif benchmark_name == "pricingput": - qc = pricingput.create_circuit(circuit_size) - - else: - lib = importlib.import_module(benchmarks_module_paths_dict[benchmark_name]) - qc = lib.create_circuit(circuit_size) - - if level == "alg" or level == 0: - return qc - - elif level == "indep" or level == 1: - - qc_indep = transpile( - qc, - basis_gates=utils.get_openqasm_gates(), - optimization_level=1, - seed_transpiler=10, - ) - return qc_indep - - elif level == "nativegates" or level == 2: - qc_gates = utils.get_compiled_circuit_with_gateset( - qc=qc, opt_level=opt_level, basis_gates=gate_set - ) - return qc_gates - - elif level == "mapped" or level == 3: - c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( - gate_set_name, smallest_fitting_arch, circuit_size - ) - if c_map_found: - qc_mapped = utils.get_compiled_circuit_with_gateset( - qc=qc, opt_level=opt_level, basis_gates=gate_set, c_map=c_map - ) - return qc_mapped - else: - return print("No Hardware Architecture available for that config.") - else: - return print("Level specification was wrong.") +# def get_one_benchmark( +# benchmark_name: str, +# level: Union[str, int], +# circuit_size: int = None, +# benchmark_instance_name: str = None, +# opt_level: int = 0, +# gate_set_name: str = "ibm", +# smallest_fitting_arch: bool = True, +# ): +# """Returns one benchmark as a Qiskit::QuantumCircuit Object. +# +# Keyword arguments: +# benchmark_name -- name of the to be generated benchmark +# level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where +# circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number +# benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" +# 0 corresponds to "alg" level and 3 to "mapped" level +# opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) +# gate_set_name -- Either "ibm" or "rigetti" +# smallest_fitting_arch -- True->Smallest architecture is selected, False->Biggest one is selected (ibm: 127 qubits, +# rigetti: 80 qubits) +# +# +# Return values: +# QuantumCircuit -- Representing the benchmark with the selected options +# """ +# init_module_paths() +# ibm_native_gates = utils.FakeMontreal().configuration().basis_gates +# rigetti_native_gates = utils.get_rigetti_native_gates() +# +# if gate_set_name and "ibm" in gate_set_name: +# gate_set = ibm_native_gates +# elif gate_set_name and "rigetti" in gate_set_name: +# gate_set = rigetti_native_gates +# else: +# gate_set = None +# +# if "grover" in benchmark_name or "qwalk" in benchmark_name: +# if "noancilla" in benchmark_name: +# anc_mode = "noancilla" +# elif "v-chain" in benchmark_name: +# anc_mode = "v-chain" +# +# short_name = benchmark_name.split("-")[0] +# lib = importlib.import_module(benchmarks_module_paths_dict[short_name]) +# qc = lib.create_circuit(circuit_size, ancillary_mode=anc_mode) +# qc.name = qc.name + "-" + anc_mode +# +# elif benchmark_name == "shor": +# instances = { +# "xsmall": [9, 4], # 18 qubits +# "small": [15, 4], # 18 qubits +# "medium": [821, 4], # 42 qubits +# "large": [11777, 4], # 58 qubits +# "xlarge": [201209, 4], # 74 qubits +# } +# +# qc = shor.create_circuit(*instances[benchmark_instance_name]) +# +# elif benchmark_name == "hhl": +# qc = hhl.create_circuit(circuit_size) +# +# elif benchmark_name == "routing": +# qc = routing.create_circuit(circuit_size) +# +# elif benchmark_name == "tsp": +# qc = tsp.create_circuit(circuit_size) +# +# elif benchmark_name == "groundstate": +# molecule = utils.get_molecule(benchmark_instance_name) +# qc = groundstate.create_circuit(molecule) +# +# elif benchmark_name == "excitedstate": +# molecule = utils.get_molecule(benchmark_instance_name) +# qc = excitedstate.create_circuit(molecule) +# +# elif benchmark_name == "pricingcall": +# qc = pricingcall.create_circuit(circuit_size) +# +# elif benchmark_name == "pricingput": +# qc = pricingput.create_circuit(circuit_size) +# +# else: +# lib = importlib.import_module(benchmarks_module_paths_dict[benchmark_name]) +# qc = lib.create_circuit(circuit_size) +# +# if level == "alg" or level == 0: +# return qc +# +# elif level == "indep" or level == 1: +# +# qc_indep = transpile( +# qc, +# basis_gates=utils.get_openqasm_gates(), +# optimization_level=1, +# seed_transpiler=10, +# ) +# return qc_indep +# +# elif level == "nativegates" or level == 2: +# qc_gates = transpile( +# qc, +# basis_gates=gate_set, +# optimization_level=opt_level, +# seed_transpiler=10, +# ) +# return qc_gates +# +# elif level == "mapped" or level == 3: +# c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( +# gate_set_name, smallest_fitting_arch, circuit_size +# ) +# if c_map_found: +# qc_mapped = transpile( +# qc, +# basis_gates=gate_set, +# optimization_level=opt_level, +# coupling_map=c_map, +# seed_transpiler=10, +# ) +# return qc_mapped +# else: +# return print("No Hardware Architecture available for that config.") +# else: +# return print("Level specification was wrong.") if __name__ == "__main__": From 8c06553441932f7e71929ede6249e8012df77154 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 8 Jun 2022 10:13:17 +0200 Subject: [PATCH 004/231] =?UTF-8?q?=F0=9F=9A=A7=20progress=20on=20tket=20s?= =?UTF-8?q?pecific=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/qiskit_helper.py | 208 ++++++++++++++++++++++++++++++- 1 file changed, 207 insertions(+), 1 deletion(-) diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index 29c5b355e..f8fa2227b 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -1,3 +1,22 @@ +from qiskit import QuantumCircuit, __qiskit_version__ +from qiskit.compiler import transpile + +from os import path + +import utils + + +def get_native_gates(gate_set_name: str): + if gate_set_name == "ionq": + return get_ionq_native_gates() + elif gate_set_name == "oqc": + return get_oqc_native_gates() + elif gate_set_name == "ibm": + return get_ibm_native_gates() + elif gate_set_name == "rigetti": + return get_rigetti_native_gates() + + def get_ibm_native_gates(): ibm_gates = ["rz", "sx", "x", "cx", "measure"] return ibm_gates @@ -15,4 +34,191 @@ def get_ionq_native_gates(): def get_oqc_native_gates(): oqc_gates = ["rz", "sx", "x", "ecr", "measure"] - return oqc_gates \ No newline at end of file + return oqc_gates + + +def get_indep_level( + qc: QuantumCircuit, + num_qubits: int, + file_precheck: bool, +): + """Handles the creation of the benchmark on the target-independent level. + + Keyword arguments: + qc -- quantum circuit which the to be created benchmark circuit is based on + num_qubits -- number of qubits + file_precheck -- flag indicating whether to check whether the file already exists before creating it (again) + + Return values: + filename_indep -- the filename of the created and saved benchmark + depth -- circuit depth of created benchmark + num_qubits -- number of qubits of generated circuit + """ + + filename_indep = qc.name + "_indep_" + str(num_qubits) + qasm_output_folder = utils.get_qasm_output_path() + filepath = qasm_output_folder + filename_indep + ".qasm" + if not (path.isfile(filepath) and file_precheck): + print(filepath + " does not already exists and is newly created") + openqasm_gates = utils.get_openqasm_gates() + target_independent = transpile( + qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 + ) + utils.save_as_qasm(target_independent, filename_indep) + + return + + +def get_native_gates_level( + qc: QuantumCircuit, + gate_set_name: str, + opt_level: int, + num_qubits: int, + file_precheck: bool, +): + """Handles the creation of the benchmark on the target-dependent native gates level. + + Keyword arguments: + qc -- quantum circuit which the to be created benchmark circuit is based on + gate_set_name -- name of this gate set + opt_level -- optimization level + num_qubits -- number of qubits + file_precheck -- flag indicating whether to check whether the file already exists before creating it (again) + """ + + filename_nativegates = ( + qc.name + + "_nativegates_" + + gate_set_name + + "_opt" + + str(opt_level) + + "_" + + str(num_qubits) + ) + gate_set = get_native_gates(gate_set_name) + qasm_output_folder = utils.get_qasm_output_path() + if not ( + path.isfile(qasm_output_folder + filename_nativegates + ".qasm") + and file_precheck + ): + print( + qasm_output_folder + + filename_nativegates + + ".qasm" + + " does not already exists and is newly created" + ) + compiled_without_architecture = transpile( + qc, basis_gates=gate_set, optimization_level=opt_level, seed_transpiler=10 + ) + n_actual = compiled_without_architecture.num_qubits + filename_nativegates = ( + qc.name + + "_nativegates_" + + gate_set_name + + "_opt" + + str(opt_level) + + "_" + + str(n_actual) + ) + utils.save_as_qasm( + compiled_without_architecture, filename_nativegates, gate_set, opt_level + ) + return + + +def get_mapped_level( + qc: QuantumCircuit, + gate_set_name: str, + opt_level: int, + num_qubits: int, + smallest_fitting_arch: bool, + file_precheck: bool, +): + """Handles the creation of the benchmark on the target-dependent mapped level. + + Keyword arguments: + qc -- quantum circuit which the to be created benchmark circuit is based on + gate_set -- set of to be used gates + gate_set_name -- name of this gate set + opt_level -- optimization level + num_qubits -- number of qubits + smallest_fitting_arch -- flag indicating whether smallest fitting mapping scheme shall be used + file_precheck -- flag indicating whether to check whether the file already exists before creating it (again) + + Return values: + filename_mapped -- the filename of the created and saved benchmark + depth -- circuit depth of created benchmark + num_qubits -- number of qubits of generated circuit + """ + + gate_set = get_native_gates(gate_set_name) + c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( + gate_set_name, smallest_fitting_arch, num_qubits + ) + + if c_map_found: + filename_mapped = ( + qc.name + + "_mapped_" + + gate_set_name_mapped + + "_opt" + + str(opt_level) + + "_" + + str(num_qubits) + ) + qasm_output_folder = utils.get_qasm_output_path() + if not ( + path.isfile(qasm_output_folder + filename_mapped + ".qasm") + and file_precheck + ): + print( + qasm_output_folder + + filename_mapped + + ".qasm" + + " does not already exists and is newly created" + ) + compiled_with_architecture = utils.get_compiled_circuit_with_gateset( + qc=qc, opt_level=opt_level, basis_gates=gate_set, c_map=c_map + ) + utils.save_as_qasm( + compiled_with_architecture, + filename_mapped, + gate_set, + opt_level, + True, + c_map, + gate_set_name_mapped + "-" + backend_name, + ) + + return + + +def get_molecule(benchmark_instance_name: str): + """Returns a Molecule object depending on the parameter value.""" + try: + from qiskit_nature.drivers import Molecule + except: + print("Please install qiskit_nature.") + return None + m_1 = Molecule( + geometry=[["H", [0.0, 0.0, 0.0]], ["H", [0.0, 0.0, 0.735]]], + charge=0, + multiplicity=1, + ) + m_2 = Molecule( + geometry=[["Li", [0.0, 0.0, 0.0]], ["H", [0.0, 0.0, 2.5]]], + charge=0, + multiplicity=1, + ) + m_3 = Molecule( + geometry=[ + ["O", [0.0, 0.0, 0.0]], + ["H", [0.586, 0.757, 0.0]], + ["H", [0.586, -0.757, 0.0]], + ], + charge=0, + multiplicity=1, + ) + instances = {"small": m_1, "medium": m_2, "large": m_3} + + return instances[benchmark_instance_name] From 0334beef8705f8c5afd7103df35e3302caa509e6 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 8 Jun 2022 10:13:22 +0200 Subject: [PATCH 005/231] =?UTF-8?q?=F0=9F=9A=A7=20progress=20on=20tket=20s?= =?UTF-8?q?pecific=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/tket_helper.py | 113 +++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 4 deletions(-) diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index f72b872a4..8e0692251 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -1,13 +1,41 @@ from pytket.passes import auto_rebase_pass from pytket import OpType +from pytket.passes import ( + PlacementPass, + RoutingPass, + FullPeepholeOptimise, + auto_rebase_pass, +) +from pytket.placement import GraphPlacement, LinePlacement +from pytket.qasm import circuit_to_qasm_str, circuit_to_qasm +from pytket import architecture, circuit + +import utils +from os import path + + +def get_rebase(gate_set_name: str): + if gate_set_name == "ionq": + return get_ionq_rebase() + elif gate_set_name == "oqc": + return get_oqc_rebase() + elif gate_set_name == "ibm": + return get_ibm_rebase() + elif gate_set_name == "rigetti": + return get_rigetti_rebase() + def get_ionq_rebase(): - ionq_rebase = auto_rebase_pass({OpType.Rz, OpType.Ry, OpType.Rx, OpType.XXPhase, OpType.Measure}) + ionq_rebase = auto_rebase_pass( + {OpType.Rz, OpType.Ry, OpType.Rx, OpType.XXPhase, OpType.Measure} + ) return ionq_rebase def get_oqc_rebase(): - oqc_rebase = auto_rebase_pass({OpType.Rz, OpType.SX, OpType.X, OpType.ECR, OpType.Measure}) + oqc_rebase = auto_rebase_pass( + {OpType.Rz, OpType.SX, OpType.X, OpType.ECR, OpType.Measure} + ) return oqc_rebase @@ -17,5 +45,82 @@ def get_rigetti_rebase(): def get_ibm_rebase(): - ibm_rebase = auto_rebase_pass({OpType.Rz, OpType.SX, OpType.X, OpType.CX, OpType.Measure}) - return ibm_rebase \ No newline at end of file + ibm_rebase = auto_rebase_pass( + {OpType.Rz, OpType.SX, OpType.X, OpType.CX, OpType.Measure} + ) + return ibm_rebase + + +def get_indep_level( + qc: circuit, + num_qubits: int, + file_precheck: bool, +): + pass + + +def get_native_gates_level( + qc: circuit, + gate_set: list, + gate_set_name: str, + opt_level: int, + num_qubits: int, + file_precheck: bool, +): + pass + + +def get_mapped_level( + qc: circuit, + gate_set_name: str, + num_qubits: int, + lineplacement: bool, + device: str, + file_precheck: bool, +): + + qasm_output_folder = utils.get_qasm_output_path() + + if lineplacement: + placement = "line" + else: + placement = "graph" + + filename_mapped = ( + qc.name + + "_mapped_" + + device + + "_" + + gate_set_name + + "_tket_" + + placement + + "_" + + str(num_qubits) + ) + if not ( + path.isfile(qasm_output_folder + filename_mapped + ".qasm") and file_precheck + ): + cmap = utils.get_cmap_from_devicename(device) + print( + qasm_output_folder + + filename_mapped + + ".qasm" + + " does not already exists and is newly created" + ) + native_gate_set_rebase = get_rebase(gate_set_name) + arch = architecture.Architecture(cmap) + + native_gate_set_rebase.apply(qc) + FullPeepholeOptimise().apply(qc) + if gate_set_name != "ionq": + if lineplacement: + PlacementPass(LinePlacement(arch)).apply(qc) + else: + PlacementPass(GraphPlacement(arch)).apply(qc) + RoutingPass(arch).apply(qc) + native_gate_set_rebase.apply(qc) + utils.save_as_qasm( + circuit_to_qasm_str(qc), filename_mapped, native_gate_set_rebase + ) + + return qc From adba8993f25f3dfedb0e71384f2b0de5d93ac397 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 8 Jun 2022 10:13:34 +0200 Subject: [PATCH 006/231] =?UTF-8?q?=F0=9F=9A=A7=20adaption=20of=20generic?= =?UTF-8?q?=20util=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/utils.py | 567 +++++++++++---------------------------- 1 file changed, 150 insertions(+), 417 deletions(-) diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index 3da739235..7abd74a7a 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -1,7 +1,4 @@ from qiskit import QuantumCircuit, __qiskit_version__ -from qiskit.compiler import transpile -from qiskit.transpiler import CouplingMap -from qiskit.circuit import qpy_serialization from qiskit.algorithms import EstimationProblem from datetime import date @@ -32,98 +29,6 @@ def get_qasm_output_path(): return qasm_path -def get_compiled_circuit_with_gateset( - qc: QuantumCircuit, - opt_level: int = 1, - basis_gates=None, - c_map: CouplingMap = None, -): - """Returns a transpiled quantum circuit according to the given input parameters. - - Keyword arguments: - qc -- to be transpiled QuantumCircuit - opt_level -- optimization level - basis_gates -- used gates of resulting quantum circuit - c_map -- to be used coupling map - """ - - if basis_gates is None: - basis_gates = ["id", "rz", "sx", "x", "cx", "reset"] - - t_qc = transpile( - qc, - basis_gates=basis_gates, - optimization_level=opt_level, - coupling_map=c_map, - seed_transpiler=10, - ) - return t_qc - - -def get_rigetti_native_gates(): - return ["rx", "rz", "cz", "id", "reset"] - - -def save_as_qasm( - qc: QuantumCircuit, - filename: str, - gate_set: list = None, - opt_level: int = -1, - mapped: bool = False, - c_map=None, - arch_name: str = "", -): - """Saves a quantum circuit as a qasm file. - - Keyword arguments: - qc -- to be saved QuantumCircuit - filename -- filename - gate_set -- set of used gates - opt_level -- optimization level - mapped -- boolean indicating whether the quantum circuit is mapped to a specific hardware layout - c_map -- coupling map of used hardware layout - arch_name -- name of used hardware layout - """ - - if c_map is None: - c_map = [] - - qasm_output_folder = get_qasm_output_path() - print(qasm_output_folder) - with open(qasm_output_folder + filename + ".qasm", "w") as f: - f.write("// Benchmark was created by MQT Bench on " + str(date.today()) + "\n") - f.write( - "// For more information about MQT Bench, please visit https://www.cda.cit.tum.de/mqtbench/" - + "\n" - ) - f.write("// MQT Bench version: " + "0.1.0" + "\n") - f.write("// Qiskit version: " + str(__qiskit_version__) + "\n") - if gate_set: - f.write("// Used Gate Set: " + str(gate_set) + "\n") - if opt_level >= 0: - f.write("// Optimization Level: " + str(opt_level) + "\n") - if mapped: - f.write("// Coupling List: " + str(c_map) + "\n") - if arch_name: - f.write("// Compiled for architecture: " + arch_name + "\n") - f.write("\n") - f.write(qc.qasm()) - f.close() - - -def serialize_qc(qc: QuantumCircuit, filename: str): - """Saves a quantum circuit as a qpy file. - - Keyword arguments: - qc -- to be saved QuantumCircuit - filename -- filename - """ - - with open("qpy_output/" + filename + ".qpy", "wb") as f: - qpy_serialization.dump(qc, f) - f.close() - - def get_examplary_max_cut_qp(n_nodes: int, degree: int = 2): """Returns a quadratic problem formulation of a max cut problem of a random graph. @@ -264,300 +169,97 @@ def get_google_c_map(): return c_map_google -def handle_algorithm_level(qc: QuantumCircuit, num_qubits: int): - """Handles the creation of the benchmark on the algorithm level. - - Keyword arguments: - qc -- quantum circuit which shall be created - num_qubits -- number of qubits - - - Return values: - filename_algo -- the filename of the created and saved benchmark - depth -- circuit depth of created benchmark - num_qubits -- number of qubits of generated circuit - """ - filename_algo = qc.name + "_algorithm_" + str(num_qubits) - if path.isfile("qpy_output/" + filename_algo + ".qpy"): - filepath = "qpy_output/" + filename_algo + ".qpy" - print(filepath + " already exists") - with open(filepath, "rb") as fd: - qc = qpy_serialization.load(fd)[0] - depth = qc.depth() - else: - serialize_qc(qc, filename_algo) - depth = qc.depth() - - return filename_algo, depth, num_qubits - - -def get_indep_level( - qc: QuantumCircuit, - num_qubits: int, - file_precheck: bool, -): - """Handles the creation of the benchmark on the target-independent level. - - Keyword arguments: - qc -- quantum circuit which the to be created benchmark circuit is based on - num_qubits -- number of qubits - file_precheck -- flag indicating whether to check whether the file already exists before creating it (again) - - Return values: - filename_indep -- the filename of the created and saved benchmark - depth -- circuit depth of created benchmark - num_qubits -- number of qubits of generated circuit - """ - - filename_indep = qc.name + "_indep_" + str(num_qubits) - qasm_output_folder = get_qasm_output_path() - filepath = qasm_output_folder + filename_indep + ".qasm" - if path.isfile(filepath) and file_precheck: - print(filepath + " already exists") - qc = QuantumCircuit.from_qasm_file(filepath) - depth = qc.depth() - return filename_indep, depth, num_qubits - - else: - openqasm_gates = get_openqasm_gates() - target_independent = transpile( - qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 - ) - save_as_qasm(target_independent, filename_indep) - - depth = target_independent.depth() - return filename_indep, depth, qc.num_qubits - - -def get_native_gates_level( - qc: QuantumCircuit, - gate_set: list, - gate_set_name: str, - opt_level: int, - num_qubits: int, - file_precheck: bool, -): - """Handles the creation of the benchmark on the target-dependent native gates level. - - Keyword arguments: - qc -- quantum circuit which the to be created benchmark circuit is based on - gate_set -- set of to be used gates - gate_set_name -- name of this gate set - opt_level -- optimization level - num_qubits -- number of qubits - file_precheck -- flag indicating whether to check whether the file already exists before creating it (again) - - Return values: - filename_nativegates -- the filename of the created and saved benchmark - depth -- circuit depth of created benchmark - num_qubits/n_actual -- number of qubits of created benchmark - """ - - filename_nativegates = ( - qc.name - + "_nativegates_" - + gate_set_name - + "_opt" - + str(opt_level) - + "_" - + str(num_qubits) - ) - - qasm_output_folder = get_qasm_output_path() - if ( - path.isfile(qasm_output_folder + filename_nativegates + ".qasm") - and file_precheck - ): - print(qasm_output_folder + filename_nativegates + ".qasm" + " already exists") - qc = QuantumCircuit.from_qasm_file( - qasm_output_folder + filename_nativegates + ".qasm" - ) - depth = qc.depth() - return filename_nativegates, depth, num_qubits - - else: - compiled_without_architecture = get_compiled_circuit_with_gateset( - qc=qc, opt_level=opt_level, basis_gates=gate_set - ) - n_actual = compiled_without_architecture.num_qubits - filename_nativegates = ( - qc.name - + "_nativegates_" - + gate_set_name - + "_opt" - + str(opt_level) - + "_" - + str(n_actual) - ) - save_as_qasm( - compiled_without_architecture, filename_nativegates, gate_set, opt_level - ) - - depth = compiled_without_architecture.depth() - return filename_nativegates, depth, n_actual - - -def get_mapped_level( - qc: QuantumCircuit, - gate_set: list, - gate_set_name: str, - opt_level: int, - num_qubits: int, - smallest_fitting_arch: bool, - file_precheck: bool, -): - """Handles the creation of the benchmark on the target-dependent mapped level. - - Keyword arguments: - qc -- quantum circuit which the to be created benchmark circuit is based on - gate_set -- set of to be used gates - gate_set_name -- name of this gate set - opt_level -- optimization level - num_qubits -- number of qubits - smallest_fitting_arch -- flag indicating whether smallest fitting mapping scheme shall be used - file_precheck -- flag indicating whether to check whether the file already exists before creating it (again) - - Return values: - filename_mapped -- the filename of the created and saved benchmark - depth -- circuit depth of created benchmark - num_qubits -- number of qubits of generated circuit - """ - - c_map, backend_name, gate_set_name_mapped, c_map_found = select_c_map( - gate_set_name, smallest_fitting_arch, num_qubits - ) - - if c_map_found: - filename_mapped = ( - qc.name - + "_mapped_" - + gate_set_name_mapped - + "_opt" - + str(opt_level) - + "_" - + str(num_qubits) - ) - qasm_output_folder = get_qasm_output_path() - if ( - path.isfile(qasm_output_folder + filename_mapped + ".qasm") - and file_precheck - ): - print(qasm_output_folder + filename_mapped + ".qasm" + " already exists") - qc = QuantumCircuit.from_qasm_file( - qasm_output_folder + filename_mapped + ".qasm" - ) - depth = qc.depth() - else: - compiled_with_architecture = get_compiled_circuit_with_gateset( - qc=qc, opt_level=opt_level, basis_gates=gate_set, c_map=c_map - ) - save_as_qasm( - compiled_with_architecture, - filename_mapped, - gate_set, - opt_level, - True, - c_map, - gate_set_name_mapped + "-" + backend_name, - ) - - depth = compiled_with_architecture.depth() - return filename_mapped, depth, num_qubits - else: - return "", 0, 0 - - -def select_c_map(gate_set_name: str, smallest_fitting_arch: bool, num_qubits: int): - """Returns a suitable coupling map for input parameters - - Keyword arguments: - gate_set_name -- name of used gate set - smallest_fitting_arch -- flag indicating whether smallest fitting mapping scheme shall be used - num_qubits -- number of qubits - - Return values: - c_map -- coupling map for input parameters - backend_name -- name of the hardware layout for the respective coupling map - gate_set_name_mapped -- combination of gate_set_name and smallest_fitting_arch - c_map_found -- indicator whether a suitable coupling map has been found - """ - c_map_found = False - c_map = [] - backend_name = "" - gate_set_name_mapped = "" - - if gate_set_name == "rigetti": - c_map_found = True - if smallest_fitting_arch: - if num_qubits <= 8: - c_map = get_rigetti_c_map(1) - backend_name = "8 qubits" - elif num_qubits <= 16: - c_map = get_rigetti_c_map(2) - backend_name = "Aspen-3: 16 qubits" - elif num_qubits <= 32: - c_map = get_rigetti_c_map(4) - backend_name = "Aspen-10: 32 qubits" - elif num_qubits <= 40: - c_map = get_rigetti_c_map(5) - backend_name = "Aspen-11: 40 qubits" - elif num_qubits <= 80: - c_map = get_rigetti_c_map(10) - backend_name = "Aspen-M-1: 80 qubits" - else: - c_map_found = False - gate_set_name_mapped = gate_set_name + "-s" - - elif num_qubits <= 80: - c_map = get_rigetti_c_map(10) - backend_name = "Aspen-M-1: 80 qubits" - gate_set_name_mapped = gate_set_name + "-b" - else: - c_map_found = False - - elif gate_set_name == "ibm": - c_map_found = True - if smallest_fitting_arch: - if num_qubits <= 5: - backend = FakeBogota() - c_map = backend.configuration().coupling_map - backend_name = backend.name() - elif num_qubits <= 7: - backend = FakeCasablanca() - c_map = backend.configuration().coupling_map - backend_name = backend.name() - elif num_qubits <= 16: - backend = FakeGuadalupe() - c_map = backend.configuration().coupling_map - backend_name = backend.name() - elif num_qubits <= 27: - backend = FakeMontreal() - c_map = backend.configuration().coupling_map - backend_name = backend.name() - elif num_qubits <= 65: - backend = FakeManhattan() - c_map = backend.configuration().coupling_map - backend_name = backend.name() - elif num_qubits <= 127: - backend = FakeWashington() - c_map = backend.configuration().coupling_map - backend_name = backend.name() - else: - c_map_found = False - gate_set_name_mapped = gate_set_name + "-s" - - elif num_qubits <= 127: - backend = FakeWashington() - c_map = backend.configuration().coupling_map - backend_name = backend.name() - gate_set_name_mapped = gate_set_name + "-b" - else: - c_map_found = False - - if c_map_found: - return c_map, backend_name, gate_set_name_mapped, c_map_found - else: - return None, "", "", False +# def select_c_map(gate_set_name: str, smallest_fitting_arch: bool, num_qubits: int): +# """Returns a suitable coupling map for input parameters +# +# Keyword arguments: +# gate_set_name -- name of used gate set +# smallest_fitting_arch -- flag indicating whether smallest fitting mapping scheme shall be used +# num_qubits -- number of qubits +# +# Return values: +# c_map -- coupling map for input parameters +# backend_name -- name of the hardware layout for the respective coupling map +# gate_set_name_mapped -- combination of gate_set_name and smallest_fitting_arch +# c_map_found -- indicator whether a suitable coupling map has been found +# """ +# c_map_found = False +# c_map = [] +# backend_name = "" +# gate_set_name_mapped = "" +# +# if gate_set_name == "rigetti": +# c_map_found = True +# if smallest_fitting_arch: +# if num_qubits <= 8: +# c_map = get_rigetti_c_map(1) +# backend_name = "8 qubits" +# elif num_qubits <= 16: +# c_map = get_rigetti_c_map(2) +# backend_name = "Aspen-3: 16 qubits" +# elif num_qubits <= 32: +# c_map = get_rigetti_c_map(4) +# backend_name = "Aspen-10: 32 qubits" +# elif num_qubits <= 40: +# c_map = get_rigetti_c_map(5) +# backend_name = "Aspen-11: 40 qubits" +# elif num_qubits <= 80: +# c_map = get_rigetti_c_map(10) +# backend_name = "Aspen-M-1: 80 qubits" +# else: +# c_map_found = False +# gate_set_name_mapped = gate_set_name + "-s" +# +# elif num_qubits <= 80: +# c_map = get_rigetti_c_map(10) +# backend_name = "Aspen-M-1: 80 qubits" +# gate_set_name_mapped = gate_set_name + "-b" +# else: +# c_map_found = False +# +# elif gate_set_name == "ibm": +# c_map_found = True +# if smallest_fitting_arch: +# if num_qubits <= 5: +# backend = FakeBogota() +# c_map = backend.configuration().coupling_map +# backend_name = backend.name() +# elif num_qubits <= 7: +# backend = FakeCasablanca() +# c_map = backend.configuration().coupling_map +# backend_name = backend.name() +# elif num_qubits <= 16: +# backend = FakeGuadalupe() +# c_map = backend.configuration().coupling_map +# backend_name = backend.name() +# elif num_qubits <= 27: +# backend = FakeMontreal() +# c_map = backend.configuration().coupling_map +# backend_name = backend.name() +# elif num_qubits <= 65: +# backend = FakeManhattan() +# c_map = backend.configuration().coupling_map +# backend_name = backend.name() +# elif num_qubits <= 127: +# backend = FakeWashington() +# c_map = backend.configuration().coupling_map +# backend_name = backend.name() +# else: +# c_map_found = False +# gate_set_name_mapped = gate_set_name + "-s" +# +# elif num_qubits <= 127: +# backend = FakeWashington() +# c_map = backend.configuration().coupling_map +# backend_name = backend.name() +# gate_set_name_mapped = gate_set_name + "-b" +# else: +# c_map_found = False +# +# if c_map_found: +# return c_map, backend_name, gate_set_name_mapped, c_map_found +# else: +# return None, "", "", False def get_openqasm_gates(): @@ -610,32 +312,63 @@ def get_openqasm_gates(): return gate_list -def get_molecule(benchmark_instance_name: str): - """Returns a Molecule object depending on the parameter value.""" - try: - from qiskit_nature.drivers import Molecule - except: - print("Please install qiskit_nature.") - return None - m_1 = Molecule( - geometry=[["H", [0.0, 0.0, 0.0]], ["H", [0.0, 0.0, 0.735]]], - charge=0, - multiplicity=1, - ) - m_2 = Molecule( - geometry=[["Li", [0.0, 0.0, 0.0]], ["H", [0.0, 0.0, 2.5]]], - charge=0, - multiplicity=1, - ) - m_3 = Molecule( - geometry=[ - ["O", [0.0, 0.0, 0.0]], - ["H", [0.586, 0.757, 0.0]], - ["H", [0.586, -0.757, 0.0]], - ], - charge=0, - multiplicity=1, - ) - instances = {"small": m_1, "medium": m_2, "large": m_3} +def save_as_qasm( + qc_str: str, + filename: str, + gate_set: list = None, + mapped: bool = False, + c_map=None, +): + """Saves a quantum circuit as a qasm file. + + Keyword arguments: + qc_str -- Quantum circuit to be stored as a string + filename -- filename + gate_set -- set of used gates + mapped -- boolean indicating whether the quantum circuit is mapped to a specific hardware layout + c_map -- coupling map of used hardware layout + """ + + if c_map is None: + c_map = [] + + qasm_output_folder = get_qasm_output_path() + print(qasm_output_folder) + with open(qasm_output_folder + filename + ".qasm", "w") as f: + f.write("// Benchmark was created by MQT Bench on " + str(date.today()) + "\n") + f.write( + "// For more information about MQT Bench, please visit https://www.cda.cit.tum.de/mqtbench/" + + "\n" + ) + f.write("// MQT Bench version: " + "0.1.0" + "\n") + f.write("// Qiskit version: " + str(__qiskit_version__) + "\n") + if gate_set: + f.write("// Used Gate Set: " + str(gate_set) + "\n") + if mapped: + f.write("// Coupling List: " + str(c_map) + "\n") + f.write("\n") + f.write(qc_str) + f.close() + + +def get_cmap_oqc_lucy(): + """Returns the coupling map of the OQC Lucy quantum computer.""" + # source: https://github.com/aws/amazon-braket-examples/blob/main/examples/braket_features/Verbatim_Compilation.ipynb - return instances[benchmark_instance_name] + # Connections are NOT bidirectional, this is not an accident + c_map_oqc_lucy = [[0, 1], [0, 7], [1, 2], [2, 3], [7, 6], [6, 5], [4, 3], [4, 5]] + + return c_map_oqc_lucy + + +def get_cmap_from_devicename(device: str): + if device == "ibm_washington": + return FakeWashington().configuration().coupling_map + elif device == "ibm_montreal": + return FakeMontreal().configuration().coupling_map + elif device == "aspen_m1": + return get_rigetti_c_map(10) + elif device == "lucy": + return get_cmap_oqc_lucy() + else: + return False From c4bf21fabd4708cb52d95a3a7007c73f4686ca0b Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 8 Jun 2022 14:16:46 +0200 Subject: [PATCH 007/231] progress predictor compilation paths are now integrated in a naive way, timeout conditions are not adapted yet --- mqt/bench/benchmark_generator.py | 551 +++++++++++++++---------------- mqt/bench/utils/qiskit_helper.py | 122 +++---- mqt/bench/utils/tket_helper.py | 88 ++++- mqt/bench/utils/utils.py | 32 +- 4 files changed, 413 insertions(+), 380 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 980ba62a7..103a49591 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -10,7 +10,6 @@ from typing import Union from os import path, mkdir, remove -from mqt.bench.utils import utils from mqt.bench.benchmarks import ( shor, hhl, @@ -22,9 +21,8 @@ ) from mqt.bench.benchmarks.qiskit_application_nature import groundstate, excitedstate -from pytket.extensions.qiskit import qiskit_to_tk -import qiskit_helper +from utils import qiskit_helper, tket_helper, utils def init_module_paths(): @@ -88,75 +86,71 @@ def timeout_handler(signum, frame): # Custom signal handler signal.alarm(timeout) try: - filename, depth, num_qubits = func(*args) + res = func(*args) except Exception as e: # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) - print("Exception: ", e, func, args[1:]) - if func == utils.get_indep_level: - qc = args[0] - num_qubits = args[1] - filename_indep = qc.name + "_t-indep_" + str(num_qubits) - file_path = qasm_output_folder + filename_indep + ".qasm" - - if path.isfile(file_path): - remove(file_path) - # print("removed file: ", path) - - elif func == utils.get_native_gates_level: - qc = args[0] - gate_set_name = args[2] - opt_level = args[3] - num_qubits = args[4] - - filename_nativegates = ( - qc.name - + "_nativegates_" - + gate_set_name - + "_opt" - + str(opt_level) - + "_" - + str(num_qubits) - ) - - file_path = qasm_output_folder + filename_nativegates + ".qasm" - if path.isfile(file_path): - remove(file_path) - - elif func == utils.get_mapped_level: - qc = args[0] - gate_set_name_mapped = args[2] - opt_level = args[3] - num_qubits = args[4] - smallest_arch = args[5] - if smallest_arch: - gate_set_name_mapped += "-s" - else: - gate_set_name_mapped += "-b" - - filename_mapped = ( - qc.name - + "_mapped_" - + gate_set_name_mapped - + "_opt" - + str(opt_level) - + "_" - + str(num_qubits) - ) - - file_path = qasm_output_folder + filename_mapped + ".qasm" - if path.isfile(file_path): - remove(file_path) + print("Exception: ", e, func, args[0].name, args[1:]) + # if func == qiskit_helper.get_indep_level or func == tket_helper.get_indep_level: + # qc = args[0] + # num_qubits = args[1] + # filename_indep = qc.name + "_t-indep_" + str(num_qubits) + # file_path = qasm_output_folder + filename_indep + ".qasm" + # + # if path.isfile(file_path): + # remove(file_path) + # # print("removed file: ", path) + # + # elif func == qiskit_helper.get_native_gates_level or func == tket_helper.get_native_gates_level: + # qc = args[0] + # gate_set_name = args[2] + # opt_level = args[3] + # num_qubits = args[4] + # + # filename_nativegates = ( + # qc.name + # + "_nativegates_" + # + gate_set_name + # + "_opt" + # + str(opt_level) + # + "_" + # + str(num_qubits) + # ) + # + # file_path = qasm_output_folder + filename_nativegates + ".qasm" + # if path.isfile(file_path): + # remove(file_path) + # + # elif func == qiskit_helper.get_mapped_level or func == tket_helper.get_mapped_level: + # qc = args[0] + # gate_set_name_mapped = args[2] + # opt_level = args[3] + # num_qubits = args[4] + # smallest_arch = args[5] + # if smallest_arch: + # gate_set_name_mapped += "-s" + # else: + # gate_set_name_mapped += "-b" + # + # filename_mapped = ( + # qc.name + # + "_mapped_" + # + gate_set_name_mapped + # + "_opt" + # + str(opt_level) + # + "_" + # + str(num_qubits) + # ) + # + # file_path = qasm_output_folder + filename_mapped + ".qasm" + # if path.isfile(file_path): + # remove(file_path) return False else: # Reset the alarm signal.alarm(0) - if depth > max_depth: - print("Depth of generated circuit is too large: ", depth) - return False - - return filename, depth, num_qubits + return res def qc_creation_watcher(func, args): @@ -200,7 +194,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break elif benchmark["name"] == "shor": @@ -209,7 +203,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break elif benchmark["name"] == "hhl": @@ -218,7 +212,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break elif benchmark["name"] == "routing": @@ -227,7 +221,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break elif benchmark["name"] == "tsp": @@ -236,7 +230,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break elif benchmark["name"] == "groundstate": @@ -245,7 +239,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break elif benchmark["name"] == "excitedstate": @@ -254,7 +248,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break elif benchmark["name"] == "pricingcall": @@ -265,7 +259,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break elif benchmark["name"] == "pricingput": @@ -276,7 +270,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: break else: for n in range( @@ -291,7 +285,8 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if len(res) == 0: + if res == 0: + print("####### FAIL") break return @@ -299,29 +294,43 @@ def generate_benchmark(benchmark): def generate_circuits_on_all_levels(qc, num_qubits, file_precheck): - res_t_indep = generate_target_indep_level_circuit(qc, num_qubits, file_precheck) - if not res_t_indep: - return False + num_generated_circuits_t_indep = generate_target_indep_level_circuit( + qc, num_qubits, file_precheck + ) + num_generated_circuits_t_dep = generate_target_dep_level_circuit( + qc, num_qubits, file_precheck + ) - res_t_dep = generate_target_dep_level_circuit(qc, num_qubits, file_precheck) - if not res_t_dep: - return False + print(num_generated_circuits_t_indep, num_generated_circuits_t_dep) - return + return num_generated_circuits_t_indep + num_generated_circuits_t_dep def generate_target_indep_level_circuit( qc: QuantumCircuit, num_qubits: int, file_precheck ): - res = benchmark_generation_watcher( - utils.get_indep_level, - [qc, num_qubits, file_precheck], - ) - if res: - return - else: - return False + num_generated_circuits = 0 + # res = benchmark_generation_watcher( + # qiskit_helper.get_indep_level, + # [qc, num_qubits, file_precheck], + # ) + res = qiskit_helper.get_indep_level(qc, num_qubits, file_precheck) + if not res: + return num_generated_circuits + + num_generated_circuits += 1 + + # res = benchmark_generation_watcher( + # tket_helper.get_indep_level, + # [qc, num_qubits, file_precheck], + # ) + res = tket_helper.get_indep_level(qc, num_qubits, file_precheck) + if not res: + return num_generated_circuits + + num_generated_circuits += 1 + return num_generated_circuits def generate_target_dep_level_circuit( @@ -334,8 +343,8 @@ def generate_target_dep_level_circuit( ("ionq", [("ionq11", 11)]), ("oqc", [("lucy", 8)]), ] - - for gate_set, devices in compilation_paths: + num_generated_benchmarks = 0 + for gate_set_name, devices in compilation_paths: # Creating the circuit on both target-dependent levels for qiskit for opt_level in range(4): res = benchmark_generation_watcher( @@ -343,94 +352,66 @@ def generate_target_dep_level_circuit( [ qc, gate_set_name, - opt_level, num_qubits, + opt_level, file_precheck, ], ) if not res: break - n_actual = res[2] - - for device, max_qubits in devices: - # Creating the circuit on target-dependent: mapped level for both mapping schemes - if max_qubits >= qc.num_qubits: - res = benchmark_generation_watcher( - qiskit_helper.get_mapped_level, - [ - qc, - gate_set_name, - device_name, - opt_level, - n_actual, - file_precheck, - ], - ) - if not res: - print( - "Mapped circuit failed for: ", - qc, - gate_set_name, - device_name, - opt_level, - n_actual, - file_precheck, + num_generated_benchmarks += 1 + n_actual = res + + if gate_set_name != "ionq": + for device_name, max_qubits in devices: + # Creating the circuit on target-dependent: mapped level qiskit + if max_qubits >= qc.num_qubits: + res = benchmark_generation_watcher( + qiskit_helper.get_mapped_level, + [ + qc, + gate_set_name, + n_actual, + device_name, + opt_level, + file_precheck, + ], ) + num_generated_benchmarks += 1 + # Creating the circuit on both target-dependent levels for tket - qc_tket = qiskit_to_tk(qc) res = benchmark_generation_watcher( tket_helper.get_native_gates_level, [ - qc_tket.copy(), - gate_set, + qc, gate_set_name, - opt_level, num_qubits, file_precheck, ], ) - if not res: - print( - "Mapped circuit failed for: ", - qc_tket.copy(), - gate_set, - gate_set_name, - opt_level, - num_qubits, - file_precheck, - ) - if not res: - break - n_actual = res[2] - - for device, max_qubits in devices: - if max_qubits >= qc.num_qubits: - for lineplacement in set(False, True): - # Creating the circuit on target-dependent: mapped level for both mapping schemes - res = benchmark_generation_watcher( - tket_helper.get_mapped_level, - [ - qc_tket.copy(), - gate_set_name, - device_name, - lineplacement, - n_actual, - file_precheck, - ], - ) - if not res: - print( - "Mapped circuit failed for: ", - qc_tket.copy(), - gate_set, - gate_set_name, - opt_level, - num_qubits, - file_precheck, + num_generated_benchmarks += 1 + n_actual = res + + if gate_set_name != "ionq": + for device_name, max_qubits in devices: + if max_qubits >= qc.num_qubits: + for lineplacement in (False, True): + # Creating the circuit on target-dependent: mapped level tket + res = benchmark_generation_watcher( + tket_helper.get_mapped_level, + [ + qc, + gate_set_name, + n_actual, + device_name, + lineplacement, + file_precheck, + ], ) - return + num_generated_benchmarks += 1 + return num_generated_benchmarks def create_scalable_qc(benchmark, num_qubits, ancillary_mode=None): @@ -572,131 +553,131 @@ def create_pricingput_qc(num_uncertainty: int): ) -# def get_one_benchmark( -# benchmark_name: str, -# level: Union[str, int], -# circuit_size: int = None, -# benchmark_instance_name: str = None, -# opt_level: int = 0, -# gate_set_name: str = "ibm", -# smallest_fitting_arch: bool = True, -# ): -# """Returns one benchmark as a Qiskit::QuantumCircuit Object. -# -# Keyword arguments: -# benchmark_name -- name of the to be generated benchmark -# level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where -# circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number -# benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" -# 0 corresponds to "alg" level and 3 to "mapped" level -# opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) -# gate_set_name -- Either "ibm" or "rigetti" -# smallest_fitting_arch -- True->Smallest architecture is selected, False->Biggest one is selected (ibm: 127 qubits, -# rigetti: 80 qubits) -# -# -# Return values: -# QuantumCircuit -- Representing the benchmark with the selected options -# """ -# init_module_paths() -# ibm_native_gates = utils.FakeMontreal().configuration().basis_gates -# rigetti_native_gates = utils.get_rigetti_native_gates() -# -# if gate_set_name and "ibm" in gate_set_name: -# gate_set = ibm_native_gates -# elif gate_set_name and "rigetti" in gate_set_name: -# gate_set = rigetti_native_gates -# else: -# gate_set = None -# -# if "grover" in benchmark_name or "qwalk" in benchmark_name: -# if "noancilla" in benchmark_name: -# anc_mode = "noancilla" -# elif "v-chain" in benchmark_name: -# anc_mode = "v-chain" -# -# short_name = benchmark_name.split("-")[0] -# lib = importlib.import_module(benchmarks_module_paths_dict[short_name]) -# qc = lib.create_circuit(circuit_size, ancillary_mode=anc_mode) -# qc.name = qc.name + "-" + anc_mode -# -# elif benchmark_name == "shor": -# instances = { -# "xsmall": [9, 4], # 18 qubits -# "small": [15, 4], # 18 qubits -# "medium": [821, 4], # 42 qubits -# "large": [11777, 4], # 58 qubits -# "xlarge": [201209, 4], # 74 qubits -# } -# -# qc = shor.create_circuit(*instances[benchmark_instance_name]) -# -# elif benchmark_name == "hhl": -# qc = hhl.create_circuit(circuit_size) -# -# elif benchmark_name == "routing": -# qc = routing.create_circuit(circuit_size) -# -# elif benchmark_name == "tsp": -# qc = tsp.create_circuit(circuit_size) -# -# elif benchmark_name == "groundstate": -# molecule = utils.get_molecule(benchmark_instance_name) -# qc = groundstate.create_circuit(molecule) -# -# elif benchmark_name == "excitedstate": -# molecule = utils.get_molecule(benchmark_instance_name) -# qc = excitedstate.create_circuit(molecule) -# -# elif benchmark_name == "pricingcall": -# qc = pricingcall.create_circuit(circuit_size) -# -# elif benchmark_name == "pricingput": -# qc = pricingput.create_circuit(circuit_size) -# -# else: -# lib = importlib.import_module(benchmarks_module_paths_dict[benchmark_name]) -# qc = lib.create_circuit(circuit_size) -# -# if level == "alg" or level == 0: -# return qc -# -# elif level == "indep" or level == 1: -# -# qc_indep = transpile( -# qc, -# basis_gates=utils.get_openqasm_gates(), -# optimization_level=1, -# seed_transpiler=10, -# ) -# return qc_indep -# -# elif level == "nativegates" or level == 2: -# qc_gates = transpile( -# qc, -# basis_gates=gate_set, -# optimization_level=opt_level, -# seed_transpiler=10, -# ) -# return qc_gates -# -# elif level == "mapped" or level == 3: -# c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( -# gate_set_name, smallest_fitting_arch, circuit_size -# ) -# if c_map_found: -# qc_mapped = transpile( -# qc, -# basis_gates=gate_set, -# optimization_level=opt_level, -# coupling_map=c_map, -# seed_transpiler=10, -# ) -# return qc_mapped -# else: -# return print("No Hardware Architecture available for that config.") -# else: -# return print("Level specification was wrong.") +def get_one_benchmark( + benchmark_name: str, + level: Union[str, int], + circuit_size: int = None, + benchmark_instance_name: str = None, + opt_level: int = 0, + gate_set_name: str = "ibm", + smallest_fitting_arch: bool = True, +): + """Returns one benchmark as a Qiskit::QuantumCircuit Object. + + Keyword arguments: + benchmark_name -- name of the to be generated benchmark + level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where + circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number + benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" + 0 corresponds to "alg" level and 3 to "mapped" level + opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) + gate_set_name -- Either "ibm" or "rigetti" + smallest_fitting_arch -- True->Smallest architecture is selected, False->Biggest one is selected (ibm: 127 qubits, + rigetti: 80 qubits) + + + Return values: + QuantumCircuit -- Representing the benchmark with the selected options + """ + init_module_paths() + ibm_native_gates = utils.FakeMontreal().configuration().basis_gates + rigetti_native_gates = utils.get_rigetti_native_gates() + + if gate_set_name and "ibm" in gate_set_name: + gate_set = ibm_native_gates + elif gate_set_name and "rigetti" in gate_set_name: + gate_set = rigetti_native_gates + else: + gate_set = None + + if "grover" in benchmark_name or "qwalk" in benchmark_name: + if "noancilla" in benchmark_name: + anc_mode = "noancilla" + elif "v-chain" in benchmark_name: + anc_mode = "v-chain" + + short_name = benchmark_name.split("-")[0] + lib = importlib.import_module(benchmarks_module_paths_dict[short_name]) + qc = lib.create_circuit(circuit_size, ancillary_mode=anc_mode) + qc.name = qc.name + "-" + anc_mode + + elif benchmark_name == "shor": + instances = { + "xsmall": [9, 4], # 18 qubits + "small": [15, 4], # 18 qubits + "medium": [821, 4], # 42 qubits + "large": [11777, 4], # 58 qubits + "xlarge": [201209, 4], # 74 qubits + } + + qc = shor.create_circuit(*instances[benchmark_instance_name]) + + elif benchmark_name == "hhl": + qc = hhl.create_circuit(circuit_size) + + elif benchmark_name == "routing": + qc = routing.create_circuit(circuit_size) + + elif benchmark_name == "tsp": + qc = tsp.create_circuit(circuit_size) + + elif benchmark_name == "groundstate": + molecule = utils.get_molecule(benchmark_instance_name) + qc = groundstate.create_circuit(molecule) + + elif benchmark_name == "excitedstate": + molecule = utils.get_molecule(benchmark_instance_name) + qc = excitedstate.create_circuit(molecule) + + elif benchmark_name == "pricingcall": + qc = pricingcall.create_circuit(circuit_size) + + elif benchmark_name == "pricingput": + qc = pricingput.create_circuit(circuit_size) + + else: + lib = importlib.import_module(benchmarks_module_paths_dict[benchmark_name]) + qc = lib.create_circuit(circuit_size) + + if level == "alg" or level == 0: + return qc + + elif level == "indep" or level == 1: + + qc_indep = transpile( + qc, + basis_gates=utils.get_openqasm_gates(), + optimization_level=1, + seed_transpiler=10, + ) + return qc_indep + + elif level == "nativegates" or level == 2: + qc_gates = transpile( + qc, + basis_gates=gate_set, + optimization_level=opt_level, + seed_transpiler=10, + ) + return qc_gates + + elif level == "mapped" or level == 3: + c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( + gate_set_name, smallest_fitting_arch, circuit_size + ) + if c_map_found: + qc_mapped = transpile( + qc, + basis_gates=gate_set, + optimization_level=opt_level, + coupling_map=c_map, + seed_transpiler=10, + ) + return qc_mapped + else: + return print("No Hardware Architecture available for that config.") + else: + return print("Level specification was wrong.") if __name__ == "__main__": diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index f8fa2227b..0750a47b7 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -3,7 +3,7 @@ from os import path -import utils +from utils import utils def get_native_gates(gate_set_name: str): @@ -55,7 +55,7 @@ def get_indep_level( num_qubits -- number of qubits of generated circuit """ - filename_indep = qc.name + "_indep_" + str(num_qubits) + filename_indep = qc.name + "_indep_qiskit_" + str(num_qubits) qasm_output_folder = utils.get_qasm_output_path() filepath = qasm_output_folder + filename_indep + ".qasm" if not (path.isfile(filepath) and file_precheck): @@ -64,16 +64,16 @@ def get_indep_level( target_independent = transpile( qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 ) - utils.save_as_qasm(target_independent, filename_indep) + utils.save_as_qasm(target_independent.qasm(), filename_indep) - return + return 1 def get_native_gates_level( qc: QuantumCircuit, gate_set_name: str, - opt_level: int, num_qubits: int, + opt_level: int, file_precheck: bool, ): """Handles the creation of the benchmark on the target-dependent native gates level. @@ -90,7 +90,7 @@ def get_native_gates_level( qc.name + "_nativegates_" + gate_set_name - + "_opt" + + "_qiskit_opt" + str(opt_level) + "_" + str(num_qubits) @@ -115,23 +115,26 @@ def get_native_gates_level( qc.name + "_nativegates_" + gate_set_name - + "_opt" + + "_qiskit_opt" + str(opt_level) + "_" + str(n_actual) ) utils.save_as_qasm( - compiled_without_architecture, filename_nativegates, gate_set, opt_level + compiled_without_architecture.qasm(), + filename_nativegates, + gate_set, + opt_level, ) - return + return qc.num_qubits def get_mapped_level( qc: QuantumCircuit, gate_set_name: str, - opt_level: int, num_qubits: int, - smallest_fitting_arch: bool, + device_name: str, + opt_level: int, file_precheck: bool, ): """Handles the creation of the benchmark on the target-dependent mapped level. @@ -152,73 +155,38 @@ def get_mapped_level( """ gate_set = get_native_gates(gate_set_name) - c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( - gate_set_name, smallest_fitting_arch, num_qubits - ) + c_map = utils.get_cmap_from_devicename(device_name) - if c_map_found: - filename_mapped = ( - qc.name - + "_mapped_" - + gate_set_name_mapped - + "_opt" - + str(opt_level) - + "_" - + str(num_qubits) + filename_mapped = ( + qc.name + + "_mapped_" + + device_name + + "_" + + gate_set_name + + "_qiskit_opt" + + str(opt_level) + + "_" + + str(num_qubits) + ) + qasm_output_folder = utils.get_qasm_output_path() + if not ( + path.isfile(qasm_output_folder + filename_mapped + ".qasm") and file_precheck + ): + print( + qasm_output_folder + + filename_mapped + + ".qasm" + + " does not already exists and is newly created" + ) + compiled_with_architecture = transpile( + qc, + optimization_level=opt_level, + basis_gates=gate_set, + coupling_map=c_map, + seed_transpiler=10, + ) + utils.save_as_qasm( + compiled_with_architecture.qasm(), filename_mapped, gate_set, True, c_map ) - qasm_output_folder = utils.get_qasm_output_path() - if not ( - path.isfile(qasm_output_folder + filename_mapped + ".qasm") - and file_precheck - ): - print( - qasm_output_folder - + filename_mapped - + ".qasm" - + " does not already exists and is newly created" - ) - compiled_with_architecture = utils.get_compiled_circuit_with_gateset( - qc=qc, opt_level=opt_level, basis_gates=gate_set, c_map=c_map - ) - utils.save_as_qasm( - compiled_with_architecture, - filename_mapped, - gate_set, - opt_level, - True, - c_map, - gate_set_name_mapped + "-" + backend_name, - ) return - - -def get_molecule(benchmark_instance_name: str): - """Returns a Molecule object depending on the parameter value.""" - try: - from qiskit_nature.drivers import Molecule - except: - print("Please install qiskit_nature.") - return None - m_1 = Molecule( - geometry=[["H", [0.0, 0.0, 0.0]], ["H", [0.0, 0.0, 0.735]]], - charge=0, - multiplicity=1, - ) - m_2 = Molecule( - geometry=[["Li", [0.0, 0.0, 0.0]], ["H", [0.0, 0.0, 2.5]]], - charge=0, - multiplicity=1, - ) - m_3 = Molecule( - geometry=[ - ["O", [0.0, 0.0, 0.0]], - ["H", [0.586, 0.757, 0.0]], - ["H", [0.586, -0.757, 0.0]], - ], - charge=0, - multiplicity=1, - ) - instances = {"small": m_1, "medium": m_2, "large": m_3} - - return instances[benchmark_instance_name] diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index 8e0692251..10e94b935 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -1,4 +1,5 @@ from pytket.passes import auto_rebase_pass + from pytket import OpType from pytket.passes import ( PlacementPass, @@ -10,8 +11,11 @@ from pytket.qasm import circuit_to_qasm_str, circuit_to_qasm from pytket import architecture, circuit -import utils +from utils import utils from os import path +from pytket.extensions.qiskit import qiskit_to_tk + +from qiskit import transpile def get_rebase(gate_set_name: str): @@ -56,26 +60,71 @@ def get_indep_level( num_qubits: int, file_precheck: bool, ): - pass + qasm_output_folder = utils.get_qasm_output_path() + + filename_native = qc.name + "_indep_tket_" + str(num_qubits) + + if not ( + path.isfile(qasm_output_folder + filename_native + ".qasm") and file_precheck + ): + print( + qasm_output_folder + + filename_native + + ".qasm" + + " does not already exists and is newly created" + ) + openqasm_gates = utils.get_openqasm_gates() + target_independent_qiskit = transpile( + qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 + ) + qc_tket = qiskit_to_tk(target_independent_qiskit) + FullPeepholeOptimise().apply(qc_tket) + utils.save_as_qasm(circuit_to_qasm_str(qc_tket), filename_native) def get_native_gates_level( qc: circuit, - gate_set: list, gate_set_name: str, - opt_level: int, num_qubits: int, file_precheck: bool, ): - pass + qasm_output_folder = utils.get_qasm_output_path() + + filename_native = ( + qc.name + "_nativegates_" + gate_set_name + "_tket_" + str(num_qubits) + ) + if not ( + path.isfile(qasm_output_folder + filename_native + ".qasm") and file_precheck + ): + print( + qasm_output_folder + + filename_native + + ".qasm" + + " does not already exists and is newly created" + ) + openqasm_gates = utils.get_openqasm_gates() + target_independent_qiskit = transpile( + qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 + ) + qc_tket = qiskit_to_tk(target_independent_qiskit) + native_gate_set_rebase = get_rebase(gate_set_name) + native_gate_set_rebase.apply(qc_tket) + FullPeepholeOptimise().apply(qc_tket) + native_gate_set_rebase.apply(qc_tket) + utils.save_as_qasm( + circuit_to_qasm_str(qc_tket), filename_native, native_gate_set_rebase + ) + + return qc_tket.n_qubits + return True def get_mapped_level( qc: circuit, gate_set_name: str, num_qubits: int, - lineplacement: bool, device: str, + lineplacement: bool, file_precheck: bool, ): @@ -107,20 +156,25 @@ def get_mapped_level( + ".qasm" + " does not already exists and is newly created" ) + openqasm_gates = utils.get_openqasm_gates() + target_independent_qiskit = transpile( + qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 + ) + qc_tket = qiskit_to_tk(target_independent_qiskit) + native_gate_set_rebase = get_rebase(gate_set_name) arch = architecture.Architecture(cmap) - native_gate_set_rebase.apply(qc) - FullPeepholeOptimise().apply(qc) - if gate_set_name != "ionq": - if lineplacement: - PlacementPass(LinePlacement(arch)).apply(qc) - else: - PlacementPass(GraphPlacement(arch)).apply(qc) - RoutingPass(arch).apply(qc) - native_gate_set_rebase.apply(qc) + native_gate_set_rebase.apply(qc_tket) + FullPeepholeOptimise().apply(qc_tket) + if lineplacement: + PlacementPass(LinePlacement(arch)).apply(qc_tket) + else: + PlacementPass(GraphPlacement(arch)).apply(qc_tket) + RoutingPass(arch).apply(qc_tket) + native_gate_set_rebase.apply(qc_tket) utils.save_as_qasm( - circuit_to_qasm_str(qc), filename_mapped, native_gate_set_rebase + circuit_to_qasm_str(qc_tket), filename_mapped, native_gate_set_rebase ) - return qc + return diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index 7abd74a7a..95093950e 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -333,7 +333,6 @@ def save_as_qasm( c_map = [] qasm_output_folder = get_qasm_output_path() - print(qasm_output_folder) with open(qasm_output_folder + filename + ".qasm", "w") as f: f.write("// Benchmark was created by MQT Bench on " + str(date.today()) + "\n") f.write( @@ -372,3 +371,34 @@ def get_cmap_from_devicename(device: str): return get_cmap_oqc_lucy() else: return False + + +def get_molecule(benchmark_instance_name: str): + """Returns a Molecule object depending on the parameter value.""" + try: + from qiskit_nature.drivers import Molecule + except: + print("Please install qiskit_nature.") + return None + m_1 = Molecule( + geometry=[["H", [0.0, 0.0, 0.0]], ["H", [0.0, 0.0, 0.735]]], + charge=0, + multiplicity=1, + ) + m_2 = Molecule( + geometry=[["Li", [0.0, 0.0, 0.0]], ["H", [0.0, 0.0, 2.5]]], + charge=0, + multiplicity=1, + ) + m_3 = Molecule( + geometry=[ + ["O", [0.0, 0.0, 0.0]], + ["H", [0.586, 0.757, 0.0]], + ["H", [0.586, -0.757, 0.0]], + ], + charge=0, + multiplicity=1, + ) + instances = {"small": m_1, "medium": m_2, "large": m_3} + + return instances[benchmark_instance_name] From 0713478a8e35a1d7f964523a53076d9fcee77d42 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 8 Jun 2022 15:16:39 +0200 Subject: [PATCH 008/231] =?UTF-8?q?=F0=9F=9A=A7=20adjusted=20return=20valu?= =?UTF-8?q?es=20and=20tests=20accordingly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/tests/test_all.py | 148 +++++++++---------------------- mqt/bench/utils/qiskit_helper.py | 8 +- mqt/bench/utils/tket_helper.py | 1 + 3 files changed, 47 insertions(+), 110 deletions(-) diff --git a/mqt/bench/tests/test_all.py b/mqt/bench/tests/test_all.py index 39e41ecae..7b0be6ffd 100644 --- a/mqt/bench/tests/test_all.py +++ b/mqt/bench/tests/test_all.py @@ -1,4 +1,4 @@ -from mqt.bench.utils import utils +from mqt.bench.utils import utils, qiskit_helper, tket_helper from mqt.bench.benchmarks import ( ghz, dj, @@ -43,39 +43,6 @@ def test_configure_begin(): assert utils.get_qasm_output_path() == test_qasm_output_path -@pytest.mark.skip(reason="Algo Level Errors are known when reading in existing files") -@pytest.mark.parametrize( - "benchmark, num_qubits", - [ - (ae, 8), - (ghz, 5), - (dj, 5), - (graphstate, 8), - (grover, 5), - (hhl, 2), - (qaoa, 5), - (qft, 8), - (qftentangled, 8), - (qpeexact, 8), - (qpeinexact, 8), - (qwalk, 5), - (vqe, 5), - (realamprandom, 9), - (su2random, 7), - (twolocalrandom, 8), - (wstate, 8), - (shor, 15), - ], -) -def test_quantumcircuit_algo_level(benchmark, num_qubits): - qc = benchmark.create_circuit(num_qubits) - filename_algo, depth, num_qubits = utils.handle_algorithm_level( - qc, - num_qubits, - ) - assert depth > 0 - - @pytest.mark.parametrize( "benchmark, input_value, scalable", [ @@ -112,14 +79,10 @@ def test_quantumcircuit_indep_level(benchmark, input_value, scalable): qc = benchmark.create_circuit(input_value) if scalable: assert qc.num_qubits == input_value - filename_indep, depth, num_qubits = utils.get_indep_level( - qc, input_value, file_precheck=False - ) - assert depth > 0 - filename_indep, depth, num_qubits = utils.get_indep_level( - qc, input_value, file_precheck=True - ) - assert depth > 0 + num_qubits = qiskit_helper.get_indep_level(qc, input_value, file_precheck=False) + assert num_qubits > 0 + num_qubits = qiskit_helper.get_indep_level(qc, input_value, file_precheck=True) + assert num_qubits == 0 @pytest.mark.parametrize( @@ -158,49 +121,53 @@ def test_quantumcircuit_native_and_mapped_levels(benchmark, input_value, scalabl qc = benchmark.create_circuit(input_value) if scalable: assert qc.num_qubits == input_value - ibm_native_gates = ["id", "rz", "sx", "x", "cx", "reset"] - rigetti_native_gates = utils.get_rigetti_native_gates() - gate_sets = [(ibm_native_gates, "ibm"), (rigetti_native_gates, "rigetti")] - for (gate_set, gate_set_name) in gate_sets: + + compilation_paths = [ + ("ibm", [("ibm_washington", 127), ("ibm_montreal", 27)]), + ("rigetti", [("aspen_m1", 80)]), + ("ionq", [("ionq11", 11)]), + ("oqc", [("lucy", 8)]), + ] + for gate_set_name, devices in compilation_paths: opt_level = 1 - filename_indep, depth_native, n_actual = utils.get_native_gates_level( - qc, - gate_set, - gate_set_name, - opt_level, - input_value, - file_precheck=False, - ) - assert depth_native > 0 - filename_indep, depth_native, n_actual = utils.get_native_gates_level( + n_actual = qiskit_helper.get_native_gates_level( qc, - gate_set, gate_set_name, + qc.num_qubits, opt_level, - input_value, - file_precheck=True, - ) - assert depth_native > 0 - filename_mapped, depth_mapped, num_qubits = utils.get_mapped_level( - qc, - gate_set, - gate_set_name, - opt_level, - n_actual, - False, file_precheck=False, ) - assert depth_mapped > 0 - filename_mapped, depth_mapped, num_qubits = utils.get_mapped_level( + assert n_actual > 0 + n_actual = qiskit_helper.get_native_gates_level( qc, - gate_set, gate_set_name, + qc.num_qubits, opt_level, - n_actual, - False, file_precheck=True, ) - assert depth_mapped > 0 + assert n_actual == 0 + if gate_set_name != "ionq": + for device_name, max_qubits in devices: + # Creating the circuit on target-dependent: mapped level qiskit + if max_qubits >= qc.num_qubits: + num_qubits = qiskit_helper.get_mapped_level( + qc, + gate_set_name, + n_actual, + device_name, + opt_level, + file_precheck=False, + ) + assert num_qubits > 0 + num_qubits = qiskit_helper.get_mapped_level( + qc, + gate_set_name, + n_actual, + device_name, + opt_level, + file_precheck=True, + ) + assert num_qubits == 0 def test_openqasm_gates(): @@ -208,39 +175,6 @@ def test_openqasm_gates(): assert len(openqasm_gates) == 42 -@pytest.mark.parametrize( - "gate_set_name, smallest_fitting_arch, num_qubits, c_map_found_result", - [ - ("ibm", False, 120, True), - ("ibm", False, 130, False), - ("ibm", True, 4, True), - ("ibm", True, 6, True), - ("ibm", True, 15, True), - ("ibm", True, 27, True), - ("ibm", True, 65, True), - ("ibm", True, 125, True), - ("rigetti", False, 79, True), - ("rigetti", False, 82, False), - ("rigetti", True, 7, True), - ("rigetti", True, 15, True), - ("rigetti", True, 31, True), - ("rigetti", True, 39, True), - ("rigetti", True, 79, True), - ("google", True, 20, False), - ], -) -def test_cmap_selection( - gate_set_name: str, - smallest_fitting_arch: bool, - num_qubits: int, - c_map_found_result: bool, -): - c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( - gate_set_name, smallest_fitting_arch, num_qubits - ) - assert c_map_found == c_map_found_result - - @pytest.mark.parametrize("num_circles", [2, 3, 4, 5, 10]) def test_rigetti_cmap_generator(num_circles: int): if num_circles != 10: diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index 0750a47b7..833368d61 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -66,7 +66,8 @@ def get_indep_level( ) utils.save_as_qasm(target_independent.qasm(), filename_indep) - return 1 + return target_independent.num_qubits + return 0 def get_native_gates_level( @@ -127,6 +128,7 @@ def get_native_gates_level( opt_level, ) return qc.num_qubits + return 0 def get_mapped_level( @@ -188,5 +190,5 @@ def get_mapped_level( utils.save_as_qasm( compiled_with_architecture.qasm(), filename_mapped, gate_set, True, c_map ) - - return + return compiled_with_architecture.num_qubits + return 0 diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index 10e94b935..596e1b1c6 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -177,4 +177,5 @@ def get_mapped_level( circuit_to_qasm_str(qc_tket), filename_mapped, native_gate_set_rebase ) + return qc_tket.n_qubits return From 42ff823fc52098759acf8613dd56d8e19a76d13f Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Mon, 8 Aug 2022 11:07:12 +0200 Subject: [PATCH 009/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20return=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 107 ++++++++----------------------- mqt/bench/utils/qiskit_helper.py | 22 ++++--- mqt/bench/utils/tket_helper.py | 19 ++++-- 3 files changed, 50 insertions(+), 98 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 103a49591..8bdfcd53c 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -90,61 +90,6 @@ def timeout_handler(signum, frame): # Custom signal handler except Exception as e: # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) print("Exception: ", e, func, args[0].name, args[1:]) - # if func == qiskit_helper.get_indep_level or func == tket_helper.get_indep_level: - # qc = args[0] - # num_qubits = args[1] - # filename_indep = qc.name + "_t-indep_" + str(num_qubits) - # file_path = qasm_output_folder + filename_indep + ".qasm" - # - # if path.isfile(file_path): - # remove(file_path) - # # print("removed file: ", path) - # - # elif func == qiskit_helper.get_native_gates_level or func == tket_helper.get_native_gates_level: - # qc = args[0] - # gate_set_name = args[2] - # opt_level = args[3] - # num_qubits = args[4] - # - # filename_nativegates = ( - # qc.name - # + "_nativegates_" - # + gate_set_name - # + "_opt" - # + str(opt_level) - # + "_" - # + str(num_qubits) - # ) - # - # file_path = qasm_output_folder + filename_nativegates + ".qasm" - # if path.isfile(file_path): - # remove(file_path) - # - # elif func == qiskit_helper.get_mapped_level or func == tket_helper.get_mapped_level: - # qc = args[0] - # gate_set_name_mapped = args[2] - # opt_level = args[3] - # num_qubits = args[4] - # smallest_arch = args[5] - # if smallest_arch: - # gate_set_name_mapped += "-s" - # else: - # gate_set_name_mapped += "-b" - # - # filename_mapped = ( - # qc.name - # + "_mapped_" - # + gate_set_name_mapped - # + "_opt" - # + str(opt_level) - # + "_" - # + str(num_qubits) - # ) - # - # file_path = qasm_output_folder + filename_mapped + ".qasm" - # if path.isfile(file_path): - # remove(file_path) - return False else: # Reset the alarm @@ -194,7 +139,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break elif benchmark["name"] == "shor": @@ -203,7 +148,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break elif benchmark["name"] == "hhl": @@ -212,7 +157,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break elif benchmark["name"] == "routing": @@ -221,7 +166,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break elif benchmark["name"] == "tsp": @@ -230,7 +175,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break elif benchmark["name"] == "groundstate": @@ -239,7 +184,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break elif benchmark["name"] == "excitedstate": @@ -248,7 +193,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break elif benchmark["name"] == "pricingcall": @@ -259,7 +204,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break elif benchmark["name"] == "pricingput": @@ -270,7 +215,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: break else: for n in range( @@ -285,7 +230,7 @@ def generate_benchmark(benchmark): if not res_qc_creation: break res = generate_circuits_on_all_levels(*res_qc_creation) - if res == 0: + if not res: print("####### FAIL") break @@ -311,25 +256,18 @@ def generate_target_indep_level_circuit( ): num_generated_circuits = 0 - # res = benchmark_generation_watcher( - # qiskit_helper.get_indep_level, - # [qc, num_qubits, file_precheck], - # ) res = qiskit_helper.get_indep_level(qc, num_qubits, file_precheck) if not res: return num_generated_circuits + else: + num_generated_circuits += 1 - num_generated_circuits += 1 - - # res = benchmark_generation_watcher( - # tket_helper.get_indep_level, - # [qc, num_qubits, file_precheck], - # ) res = tket_helper.get_indep_level(qc, num_qubits, file_precheck) if not res: return num_generated_circuits + else: + num_generated_circuits += 1 - num_generated_circuits += 1 return num_generated_circuits @@ -359,10 +297,12 @@ def generate_target_dep_level_circuit( ) if not res: break - num_generated_benchmarks += 1 + else: + num_generated_benchmarks += 1 n_actual = res - if gate_set_name != "ionq": + if gate_set_name != "ionq": + for opt_level in range(4): for device_name, max_qubits in devices: # Creating the circuit on target-dependent: mapped level qiskit if max_qubits >= qc.num_qubits: @@ -377,8 +317,10 @@ def generate_target_dep_level_circuit( file_precheck, ], ) - - num_generated_benchmarks += 1 + if not res: + continue + else: + num_generated_benchmarks += 1 # Creating the circuit on both target-dependent levels for tket @@ -410,7 +352,10 @@ def generate_target_dep_level_circuit( file_precheck, ], ) - num_generated_benchmarks += 1 + if not res: + continue + else: + num_generated_benchmarks += 1 return num_generated_benchmarks diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index 833368d61..77b8a38f6 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -64,10 +64,11 @@ def get_indep_level( target_independent = transpile( qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 ) - utils.save_as_qasm(target_independent.qasm(), filename_indep) + res = utils.save_as_qasm(target_independent.qasm(), filename_indep) - return target_independent.num_qubits - return 0 + return res + else: + return True def get_native_gates_level( @@ -121,14 +122,14 @@ def get_native_gates_level( + "_" + str(n_actual) ) - utils.save_as_qasm( + res = utils.save_as_qasm( compiled_without_architecture.qasm(), filename_nativegates, gate_set, - opt_level, ) - return qc.num_qubits - return 0 + return res + else: + return True def get_mapped_level( @@ -187,8 +188,9 @@ def get_mapped_level( coupling_map=c_map, seed_transpiler=10, ) - utils.save_as_qasm( + res = utils.save_as_qasm( compiled_with_architecture.qasm(), filename_mapped, gate_set, True, c_map ) - return compiled_with_architecture.num_qubits - return 0 + return res + else: + return True diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index 596e1b1c6..019c8eb55 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -79,7 +79,10 @@ def get_indep_level( ) qc_tket = qiskit_to_tk(target_independent_qiskit) FullPeepholeOptimise().apply(qc_tket) - utils.save_as_qasm(circuit_to_qasm_str(qc_tket), filename_native) + res = utils.save_as_qasm(circuit_to_qasm_str(qc_tket), filename_native) + return res + else: + return True def get_native_gates_level( @@ -111,12 +114,13 @@ def get_native_gates_level( native_gate_set_rebase.apply(qc_tket) FullPeepholeOptimise().apply(qc_tket) native_gate_set_rebase.apply(qc_tket) - utils.save_as_qasm( + res = utils.save_as_qasm( circuit_to_qasm_str(qc_tket), filename_native, native_gate_set_rebase ) + return res + else: + return True - return qc_tket.n_qubits - return True def get_mapped_level( @@ -173,9 +177,10 @@ def get_mapped_level( PlacementPass(GraphPlacement(arch)).apply(qc_tket) RoutingPass(arch).apply(qc_tket) native_gate_set_rebase.apply(qc_tket) - utils.save_as_qasm( + res = utils.save_as_qasm( circuit_to_qasm_str(qc_tket), filename_mapped, native_gate_set_rebase ) + return res + else: + return True - return qc_tket.n_qubits - return From 1611d47445540b04f3129310ac80b923767ce813 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Mon, 8 Aug 2022 11:07:27 +0200 Subject: [PATCH 010/231] =?UTF-8?q?=E2=9C=A8=20added=20tket=20version=20nu?= =?UTF-8?q?mber=20in=20file=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index 95093950e..9838a6778 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -1,6 +1,8 @@ from qiskit import QuantumCircuit, __qiskit_version__ from qiskit.algorithms import EstimationProblem +from pytket import * + from datetime import date import networkx as nx @@ -340,7 +342,11 @@ def save_as_qasm( + "\n" ) f.write("// MQT Bench version: " + "0.1.0" + "\n") - f.write("// Qiskit version: " + str(__qiskit_version__) + "\n") + if "qiskit" in filename: + f.write("// Qiskit version: " + str(__qiskit_version__) + "\n") + elif "tket" in filename: + f.write("// TKET version: " + str(pytket.__version__) + "\n") + if gate_set: f.write("// Used Gate Set: " + str(gate_set) + "\n") if mapped: @@ -348,6 +354,7 @@ def save_as_qasm( f.write("\n") f.write(qc_str) f.close() + return True def get_cmap_oqc_lucy(): From 73ba6f1eb7b07c7cc53a52b3f8453f904ee3a376 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Mon, 8 Aug 2022 13:21:47 +0200 Subject: [PATCH 011/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20import=20stateme?= =?UTF-8?q?nts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 237 ++++++++++++++++--------------- mqt/bench/utils/qiskit_helper.py | 2 +- mqt/bench/utils/tket_helper.py | 4 +- 3 files changed, 122 insertions(+), 121 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 8bdfcd53c..8ad8b1a12 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -22,7 +22,7 @@ from mqt.bench.benchmarks.qiskit_application_nature import groundstate, excitedstate -from utils import qiskit_helper, tket_helper, utils +from mqt.bench.utils import qiskit_helper, tket_helper, utils def init_module_paths(): @@ -507,122 +507,125 @@ def get_one_benchmark( gate_set_name: str = "ibm", smallest_fitting_arch: bool = True, ): - """Returns one benchmark as a Qiskit::QuantumCircuit Object. - - Keyword arguments: - benchmark_name -- name of the to be generated benchmark - level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where - circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number - benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" - 0 corresponds to "alg" level and 3 to "mapped" level - opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) - gate_set_name -- Either "ibm" or "rigetti" - smallest_fitting_arch -- True->Smallest architecture is selected, False->Biggest one is selected (ibm: 127 qubits, - rigetti: 80 qubits) - - - Return values: - QuantumCircuit -- Representing the benchmark with the selected options - """ - init_module_paths() - ibm_native_gates = utils.FakeMontreal().configuration().basis_gates - rigetti_native_gates = utils.get_rigetti_native_gates() - - if gate_set_name and "ibm" in gate_set_name: - gate_set = ibm_native_gates - elif gate_set_name and "rigetti" in gate_set_name: - gate_set = rigetti_native_gates - else: - gate_set = None - - if "grover" in benchmark_name or "qwalk" in benchmark_name: - if "noancilla" in benchmark_name: - anc_mode = "noancilla" - elif "v-chain" in benchmark_name: - anc_mode = "v-chain" - - short_name = benchmark_name.split("-")[0] - lib = importlib.import_module(benchmarks_module_paths_dict[short_name]) - qc = lib.create_circuit(circuit_size, ancillary_mode=anc_mode) - qc.name = qc.name + "-" + anc_mode - - elif benchmark_name == "shor": - instances = { - "xsmall": [9, 4], # 18 qubits - "small": [15, 4], # 18 qubits - "medium": [821, 4], # 42 qubits - "large": [11777, 4], # 58 qubits - "xlarge": [201209, 4], # 74 qubits - } - - qc = shor.create_circuit(*instances[benchmark_instance_name]) - - elif benchmark_name == "hhl": - qc = hhl.create_circuit(circuit_size) - - elif benchmark_name == "routing": - qc = routing.create_circuit(circuit_size) - - elif benchmark_name == "tsp": - qc = tsp.create_circuit(circuit_size) - - elif benchmark_name == "groundstate": - molecule = utils.get_molecule(benchmark_instance_name) - qc = groundstate.create_circuit(molecule) - - elif benchmark_name == "excitedstate": - molecule = utils.get_molecule(benchmark_instance_name) - qc = excitedstate.create_circuit(molecule) - - elif benchmark_name == "pricingcall": - qc = pricingcall.create_circuit(circuit_size) - - elif benchmark_name == "pricingput": - qc = pricingput.create_circuit(circuit_size) - - else: - lib = importlib.import_module(benchmarks_module_paths_dict[benchmark_name]) - qc = lib.create_circuit(circuit_size) - - if level == "alg" or level == 0: - return qc - - elif level == "indep" or level == 1: - - qc_indep = transpile( - qc, - basis_gates=utils.get_openqasm_gates(), - optimization_level=1, - seed_transpiler=10, - ) - return qc_indep - - elif level == "nativegates" or level == 2: - qc_gates = transpile( - qc, - basis_gates=gate_set, - optimization_level=opt_level, - seed_transpiler=10, - ) - return qc_gates - - elif level == "mapped" or level == 3: - c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( - gate_set_name, smallest_fitting_arch, circuit_size - ) - if c_map_found: - qc_mapped = transpile( - qc, - basis_gates=gate_set, - optimization_level=opt_level, - coupling_map=c_map, - seed_transpiler=10, - ) - return qc_mapped - else: - return print("No Hardware Architecture available for that config.") - else: - return print("Level specification was wrong.") + return True + + +# """Returns one benchmark as a Qiskit::QuantumCircuit Object. +# +# Keyword arguments: +# benchmark_name -- name of the to be generated benchmark +# level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where +# circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number +# benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" +# 0 corresponds to "alg" level and 3 to "mapped" level +# opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) +# gate_set_name -- Either "ibm" or "rigetti" +# smallest_fitting_arch -- True->Smallest architecture is selected, False->Biggest one is selected (ibm: 127 qubits, +# rigetti: 80 qubits) +# +# +# Return values: +# QuantumCircuit -- Representing the benchmark with the selected options +# """ +# init_module_paths() +# ibm_native_gates = utils.FakeMontreal().configuration().basis_gates +# rigetti_native_gates = utils.get_rigetti_native_gates() +# +# if gate_set_name and "ibm" in gate_set_name: +# gate_set = ibm_native_gates +# elif gate_set_name and "rigetti" in gate_set_name: +# gate_set = rigetti_native_gates +# else: +# gate_set = None +# +# if "grover" in benchmark_name or "qwalk" in benchmark_name: +# if "noancilla" in benchmark_name: +# anc_mode = "noancilla" +# elif "v-chain" in benchmark_name: +# anc_mode = "v-chain" +# +# short_name = benchmark_name.split("-")[0] +# lib = importlib.import_module(benchmarks_module_paths_dict[short_name]) +# qc = lib.create_circuit(circuit_size, ancillary_mode=anc_mode) +# qc.name = qc.name + "-" + anc_mode +# +# elif benchmark_name == "shor": +# instances = { +# "xsmall": [9, 4], # 18 qubits +# "small": [15, 4], # 18 qubits +# "medium": [821, 4], # 42 qubits +# "large": [11777, 4], # 58 qubits +# "xlarge": [201209, 4], # 74 qubits +# } +# +# qc = shor.create_circuit(*instances[benchmark_instance_name]) +# +# elif benchmark_name == "hhl": +# qc = hhl.create_circuit(circuit_size) +# +# elif benchmark_name == "routing": +# qc = routing.create_circuit(circuit_size) +# +# elif benchmark_name == "tsp": +# qc = tsp.create_circuit(circuit_size) +# +# elif benchmark_name == "groundstate": +# molecule = utils.get_molecule(benchmark_instance_name) +# qc = groundstate.create_circuit(molecule) +# +# elif benchmark_name == "excitedstate": +# molecule = utils.get_molecule(benchmark_instance_name) +# qc = excitedstate.create_circuit(molecule) +# +# elif benchmark_name == "pricingcall": +# qc = pricingcall.create_circuit(circuit_size) +# +# elif benchmark_name == "pricingput": +# qc = pricingput.create_circuit(circuit_size) +# +# else: +# lib = importlib.import_module(benchmarks_module_paths_dict[benchmark_name]) +# qc = lib.create_circuit(circuit_size) +# +# if level == "alg" or level == 0: +# return qc +# +# elif level == "indep" or level == 1: +# +# qc_indep = transpile( +# qc, +# basis_gates=utils.get_openqasm_gates(), +# optimization_level=1, +# seed_transpiler=10, +# ) +# return qc_indep +# +# elif level == "nativegates" or level == 2: +# qc_gates = transpile( +# qc, +# basis_gates=gate_set, +# optimization_level=opt_level, +# seed_transpiler=10, +# ) +# return qc_gates +# +# elif level == "mapped" or level == 3: +# c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( +# gate_set_name, smallest_fitting_arch, circuit_size +# ) +# if c_map_found: +# qc_mapped = transpile( +# qc, +# basis_gates=gate_set, +# optimization_level=opt_level, +# coupling_map=c_map, +# seed_transpiler=10, +# ) +# return qc_mapped +# else: +# return print("No Hardware Architecture available for that config.") +# else: +# return print("Level specification was wrong.") if __name__ == "__main__": diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index 77b8a38f6..9aff061b2 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -3,7 +3,7 @@ from os import path -from utils import utils +from mqt.bench.utils import utils def get_native_gates(gate_set_name: str): diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index 019c8eb55..ee838d33d 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -11,7 +11,7 @@ from pytket.qasm import circuit_to_qasm_str, circuit_to_qasm from pytket import architecture, circuit -from utils import utils +from mqt.bench.utils import utils from os import path from pytket.extensions.qiskit import qiskit_to_tk @@ -122,7 +122,6 @@ def get_native_gates_level( return True - def get_mapped_level( qc: circuit, gate_set_name: str, @@ -183,4 +182,3 @@ def get_mapped_level( return res else: return True - From 94275a1618c6855224a258d05fbf5326cf7ef017 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Mon, 8 Aug 2022 13:21:53 +0200 Subject: [PATCH 012/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/tests/test_all.py | 76 +++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/mqt/bench/tests/test_all.py b/mqt/bench/tests/test_all.py index 7b0be6ffd..437f64200 100644 --- a/mqt/bench/tests/test_all.py +++ b/mqt/bench/tests/test_all.py @@ -74,15 +74,20 @@ def test_configure_begin(): ) def test_quantumcircuit_indep_level(benchmark, input_value, scalable): if benchmark == grover or benchmark == qwalk: - qc = benchmark.create_circuit(input_value, ancillary_mode="v-chain") + qc = benchmark.create_circuit(input_value, ancillary_mode="noancilla") else: qc = benchmark.create_circuit(input_value) if scalable: assert qc.num_qubits == input_value - num_qubits = qiskit_helper.get_indep_level(qc, input_value, file_precheck=False) - assert num_qubits > 0 - num_qubits = qiskit_helper.get_indep_level(qc, input_value, file_precheck=True) - assert num_qubits == 0 + res = qiskit_helper.get_indep_level(qc, input_value, file_precheck=False) + assert res + res = qiskit_helper.get_indep_level(qc, input_value, file_precheck=True) + assert res + + res = tket_helper.get_indep_level(qc, input_value, file_precheck=False) + assert res + res = tket_helper.get_indep_level(qc, input_value, file_precheck=True) + assert res @pytest.mark.parametrize( @@ -116,7 +121,7 @@ def test_quantumcircuit_indep_level(benchmark, input_value, scalable): ) def test_quantumcircuit_native_and_mapped_levels(benchmark, input_value, scalable): if benchmark == grover or benchmark == qwalk: - qc = benchmark.create_circuit(input_value, ancillary_mode="v-chain") + qc = benchmark.create_circuit(input_value, ancillary_mode="noancilla") else: qc = benchmark.create_circuit(input_value) if scalable: @@ -130,44 +135,82 @@ def test_quantumcircuit_native_and_mapped_levels(benchmark, input_value, scalabl ] for gate_set_name, devices in compilation_paths: opt_level = 1 - n_actual = qiskit_helper.get_native_gates_level( + res = qiskit_helper.get_native_gates_level( qc, gate_set_name, qc.num_qubits, opt_level, file_precheck=False, ) - assert n_actual > 0 - n_actual = qiskit_helper.get_native_gates_level( + assert res + res = qiskit_helper.get_native_gates_level( qc, gate_set_name, qc.num_qubits, opt_level, file_precheck=True, ) - assert n_actual == 0 + assert res if gate_set_name != "ionq": for device_name, max_qubits in devices: # Creating the circuit on target-dependent: mapped level qiskit if max_qubits >= qc.num_qubits: - num_qubits = qiskit_helper.get_mapped_level( + res = qiskit_helper.get_mapped_level( qc, gate_set_name, - n_actual, + qc.num_qubits, device_name, opt_level, file_precheck=False, ) - assert num_qubits > 0 - num_qubits = qiskit_helper.get_mapped_level( + assert res + res = qiskit_helper.get_mapped_level( qc, gate_set_name, - n_actual, + qc.num_qubits, device_name, opt_level, file_precheck=True, ) - assert num_qubits == 0 + assert res + + for gate_set_name, devices in compilation_paths: + res = tket_helper.get_native_gates_level( + qc, + gate_set_name, + qc.num_qubits, + file_precheck=False, + ) + assert res + res = tket_helper.get_native_gates_level( + qc, + gate_set_name, + qc.num_qubits, + file_precheck=True, + ) + assert res + if gate_set_name != "ionq": + for device_name, max_qubits in devices: + # Creating the circuit on target-dependent: mapped level qiskit + if max_qubits >= qc.num_qubits: + res = tket_helper.get_mapped_level( + qc, + gate_set_name, + qc.num_qubits, + device_name, + True, + file_precheck=False, + ) + assert res + res = tket_helper.get_mapped_level( + qc, + gate_set_name, + qc.num_qubits, + device_name, + False, + file_precheck=True, + ) + assert res def test_openqasm_gates(): @@ -214,6 +257,7 @@ def test_routing(): assert qc.depth() > 0 +@pytest.mark.skip(reason="method not adjusted yet") @pytest.mark.parametrize( "benchmark_name, level, input_number, instance, opt_level, gate_set_name, smallest_fitting_arch", [ From 768dff856b40d394549a1f0147a6d9ddc96948be Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Mon, 8 Aug 2022 14:28:49 +0200 Subject: [PATCH 013/231] =?UTF-8?q?=E2=9C=A8=20implemented=20get=5Fone=5Fb?= =?UTF-8?q?ench=20function=20in=20a=20more=20efficient=20way?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 239 +++++++++++++++---------------- mqt/bench/tests/test_all.py | 55 ++++--- mqt/bench/utils/qiskit_helper.py | 42 ++++-- mqt/bench/utils/tket_helper.py | 34 +++-- mqt/bench/utils/utils.py | 11 ++ 5 files changed, 219 insertions(+), 162 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 8ad8b1a12..c8a5fad58 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -503,129 +503,126 @@ def get_one_benchmark( level: Union[str, int], circuit_size: int = None, benchmark_instance_name: str = None, - opt_level: int = 0, + compiler: str = "qiskit", + compiler_settings: Union[str, int] = 0, gate_set_name: str = "ibm", - smallest_fitting_arch: bool = True, + device_name: str = "ibm_washington", ): - return True - - -# """Returns one benchmark as a Qiskit::QuantumCircuit Object. -# -# Keyword arguments: -# benchmark_name -- name of the to be generated benchmark -# level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where -# circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number -# benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" -# 0 corresponds to "alg" level and 3 to "mapped" level -# opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) -# gate_set_name -- Either "ibm" or "rigetti" -# smallest_fitting_arch -- True->Smallest architecture is selected, False->Biggest one is selected (ibm: 127 qubits, -# rigetti: 80 qubits) -# -# -# Return values: -# QuantumCircuit -- Representing the benchmark with the selected options -# """ -# init_module_paths() -# ibm_native_gates = utils.FakeMontreal().configuration().basis_gates -# rigetti_native_gates = utils.get_rigetti_native_gates() -# -# if gate_set_name and "ibm" in gate_set_name: -# gate_set = ibm_native_gates -# elif gate_set_name and "rigetti" in gate_set_name: -# gate_set = rigetti_native_gates -# else: -# gate_set = None -# -# if "grover" in benchmark_name or "qwalk" in benchmark_name: -# if "noancilla" in benchmark_name: -# anc_mode = "noancilla" -# elif "v-chain" in benchmark_name: -# anc_mode = "v-chain" -# -# short_name = benchmark_name.split("-")[0] -# lib = importlib.import_module(benchmarks_module_paths_dict[short_name]) -# qc = lib.create_circuit(circuit_size, ancillary_mode=anc_mode) -# qc.name = qc.name + "-" + anc_mode -# -# elif benchmark_name == "shor": -# instances = { -# "xsmall": [9, 4], # 18 qubits -# "small": [15, 4], # 18 qubits -# "medium": [821, 4], # 42 qubits -# "large": [11777, 4], # 58 qubits -# "xlarge": [201209, 4], # 74 qubits -# } -# -# qc = shor.create_circuit(*instances[benchmark_instance_name]) -# -# elif benchmark_name == "hhl": -# qc = hhl.create_circuit(circuit_size) -# -# elif benchmark_name == "routing": -# qc = routing.create_circuit(circuit_size) -# -# elif benchmark_name == "tsp": -# qc = tsp.create_circuit(circuit_size) -# -# elif benchmark_name == "groundstate": -# molecule = utils.get_molecule(benchmark_instance_name) -# qc = groundstate.create_circuit(molecule) -# -# elif benchmark_name == "excitedstate": -# molecule = utils.get_molecule(benchmark_instance_name) -# qc = excitedstate.create_circuit(molecule) -# -# elif benchmark_name == "pricingcall": -# qc = pricingcall.create_circuit(circuit_size) -# -# elif benchmark_name == "pricingput": -# qc = pricingput.create_circuit(circuit_size) -# -# else: -# lib = importlib.import_module(benchmarks_module_paths_dict[benchmark_name]) -# qc = lib.create_circuit(circuit_size) -# -# if level == "alg" or level == 0: -# return qc -# -# elif level == "indep" or level == 1: -# -# qc_indep = transpile( -# qc, -# basis_gates=utils.get_openqasm_gates(), -# optimization_level=1, -# seed_transpiler=10, -# ) -# return qc_indep -# -# elif level == "nativegates" or level == 2: -# qc_gates = transpile( -# qc, -# basis_gates=gate_set, -# optimization_level=opt_level, -# seed_transpiler=10, -# ) -# return qc_gates -# -# elif level == "mapped" or level == 3: -# c_map, backend_name, gate_set_name_mapped, c_map_found = utils.select_c_map( -# gate_set_name, smallest_fitting_arch, circuit_size -# ) -# if c_map_found: -# qc_mapped = transpile( -# qc, -# basis_gates=gate_set, -# optimization_level=opt_level, -# coupling_map=c_map, -# seed_transpiler=10, -# ) -# return qc_mapped -# else: -# return print("No Hardware Architecture available for that config.") -# else: -# return print("Level specification was wrong.") + """Returns one benchmark as a Qiskit::QuantumCircuit Object. + + Keyword arguments: + benchmark_name -- name of the to be generated benchmark + level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where + circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number + benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" + 0 corresponds to "alg" level and 3 to "mapped" level + opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) + gate_set_name -- Either "ibm" or "rigetti" + + + Return values: + QuantumCircuit -- Representing the benchmark with the selected options + """ + init_module_paths() + + if "grover" in benchmark_name or "qwalk" in benchmark_name: + if "noancilla" in benchmark_name: + anc_mode = "noancilla" + elif "v-chain" in benchmark_name: + anc_mode = "v-chain" + + short_name = benchmark_name.split("-")[0] + lib = importlib.import_module(benchmarks_module_paths_dict[short_name]) + qc = lib.create_circuit(circuit_size, ancillary_mode=anc_mode) + qc.name = qc.name + "-" + anc_mode + + elif benchmark_name == "shor": + instances = { + "xsmall": [9, 4], # 18 qubits + "small": [15, 4], # 18 qubits + "medium": [821, 4], # 42 qubits + "large": [11777, 4], # 58 qubits + "xlarge": [201209, 4], # 74 qubits + } + + qc = shor.create_circuit(*instances[benchmark_instance_name]) + + elif benchmark_name == "hhl": + qc = hhl.create_circuit(circuit_size) + + elif benchmark_name == "routing": + qc = routing.create_circuit(circuit_size) + + elif benchmark_name == "tsp": + qc = tsp.create_circuit(circuit_size) + + elif benchmark_name == "groundstate": + molecule = utils.get_molecule(benchmark_instance_name) + qc = groundstate.create_circuit(molecule) + + elif benchmark_name == "excitedstate": + molecule = utils.get_molecule(benchmark_instance_name) + qc = excitedstate.create_circuit(molecule) + + elif benchmark_name == "pricingcall": + qc = pricingcall.create_circuit(circuit_size) + + elif benchmark_name == "pricingput": + qc = pricingput.create_circuit(circuit_size) + + else: + lib = importlib.import_module(benchmarks_module_paths_dict[benchmark_name]) + qc = lib.create_circuit(circuit_size) + + if level == "alg" or level == 0: + return qc + + elif level == "indep" or level == 1: + + if compiler == "qiskit": + qc_indep = qiskit_helper.get_indep_level(qc, circuit_size, False, True) + elif compiler == "tket": + qc_indep = tket_helper.get_indep_level(qc, circuit_size, False, True) + + return qc_indep + + elif level == "nativegates" or level == 2: + + if compiler == "qiskit": + qc_gates = qiskit_helper.get_native_gates_level( + qc, gate_set_name, circuit_size, compiler_settings, False, True + ) + elif compiler == "tket": + qc_gates = tket_helper.get_native_gates_level( + qc, gate_set_name, circuit_size, False, True + ) + + return qc_gates + + elif level == "mapped" or level == 3: + if compiler == "qiskit": + qc_mapped = qiskit_helper.get_mapped_level( + qc, + gate_set_name, + circuit_size, + device_name, + compiler_settings, + False, + True, + ) + elif compiler == "tket": + qc_mapped = tket_helper.get_mapped_level( + qc, + gate_set_name, + circuit_size, + device_name, + compiler_settings, + False, + True, + ) + return qc_mapped + else: + return print("Level specification was wrong.") if __name__ == "__main__": diff --git a/mqt/bench/tests/test_all.py b/mqt/bench/tests/test_all.py index 437f64200..72b9bb133 100644 --- a/mqt/bench/tests/test_all.py +++ b/mqt/bench/tests/test_all.py @@ -257,38 +257,57 @@ def test_routing(): assert qc.depth() > 0 -@pytest.mark.skip(reason="method not adjusted yet") @pytest.mark.parametrize( - "benchmark_name, level, input_number, instance, opt_level, gate_set_name, smallest_fitting_arch", + "benchmark_name, level, circuit_size, benchmark_instance_name, compiler, compiler_settings, gate_set_name, device_name,", [ - ("dj", "alg", 5, None, None, None, None), - ("wstate", 0, 6, None, None, None, None), - ("ghz", "indep", 5, None, None, None, None), - ("graphstate", 1, 4, None, None, None, None), - ("dj", "nativegates", 5, None, 2, "ibm", None), - ("qft", 2, 6, None, 3, "rigetti", None), - ("qpeexact", "mapped", 5, None, 0, "ibm", True), - ("qpeinexact", 3, 4, None, None, "rigetti", False), + ("dj", "alg", 5, None, "qiskit", 1, None, None), + ("wstate", 0, 6, None, "qiskit", 2, None, None), + ("ghz", "indep", 5, None, "qiskit", 3, None, None), + ("graphstate", 1, 4, None, "qiskit", 0, None, None), + ("groundstate", 1, 4, "small", "qiskit", 1, None, None), + ("dj", "nativegates", 5, None, "qiskit", 2, "ionq", None), + ("dj", "nativegates", 5, None, "qiskit", 2, "ibm", None), + ("dj", "nativegates", 5, None, "qiskit", 2, "rigetti", None), + ("dj", "nativegates", 5, None, "qiskit", 2, "oqc", None), + ("qft", 2, 6, None, "qiskit", 3, "ionq", None), + ("qft", 2, 6, None, "qiskit", 3, "qiskit", None), + ("qft", 2, 6, None, "tket", False, "rigetti", None), + ("qft", 2, 6, None, "tket", True, "oqc", None), + ("qpeexact", "mapped", 5, None, "qiskit", 1, "ibm", "ibm_washington"), + ("qpeexact", "mapped", 5, None, "qiskit", 1, "ibm", "ibm_montreal"), + ("qpeexact", "mapped", 5, None, "qiskit", 1, "rigetti", "aspen_m1"), + ("qpeexact", "mapped", 5, None, "qiskit", 1, "ionq", "ionq11"), + ("qpeexact", "mapped", 5, None, "qiskit", 1, "oqc", "lucy"), + ("qpeinexact", 3, 4, None, "qiskit", 1, "ibm", "ibm_washington"), + ("qpeinexact", 3, 4, None, "tket", True, "ibm", "ibm_washington"), + ("qpeinexact", 3, 4, None, "qiskit", 1, "ibm", "ibm_montreal"), + ("qpeinexact", 3, 4, None, "tket", False, "ibm", "ibm_montreal"), + ("qpeinexact", 3, 4, None, "qiskit", 1, "rigetti", "aspen_m1"), + ("qpeinexact", 3, 4, None, "tket", True, "rigetti", "aspen_m1"), + ("qpeinexact", 3, 4, None, "qiskit", 1, "oqc", "lucy"), + ("qpeinexact", 3, 4, None, "tket", False, "oqc", "lucy"), ], ) def test_get_one_benchmark( benchmark_name, level, - input_number, - instance, - opt_level, + circuit_size, + benchmark_instance_name, + compiler, + compiler_settings, gate_set_name, - smallest_fitting_arch, + device_name, ): qc = get_one_benchmark( benchmark_name, level, - input_number, - instance, - opt_level, + circuit_size, + benchmark_instance_name, + compiler, + compiler_settings, gate_set_name, - smallest_fitting_arch, + device_name, ) assert qc.depth() > 0 diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index 9aff061b2..149f7015a 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -41,6 +41,7 @@ def get_indep_level( qc: QuantumCircuit, num_qubits: int, file_precheck: bool, + return_qc: bool = False, ): """Handles the creation of the benchmark on the target-independent level. @@ -64,9 +65,12 @@ def get_indep_level( target_independent = transpile( qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 ) - res = utils.save_as_qasm(target_independent.qasm(), filename_indep) - return res + if return_qc: + return target_independent + else: + res = utils.save_as_qasm(target_independent.qasm(), filename_indep) + return res else: return True @@ -77,6 +81,7 @@ def get_native_gates_level( num_qubits: int, opt_level: int, file_precheck: bool, + return_qc: bool = False, ): """Handles the creation of the benchmark on the target-dependent native gates level. @@ -122,12 +127,16 @@ def get_native_gates_level( + "_" + str(n_actual) ) - res = utils.save_as_qasm( - compiled_without_architecture.qasm(), - filename_nativegates, - gate_set, - ) - return res + + if return_qc: + return compiled_without_architecture + else: + res = utils.save_as_qasm( + compiled_without_architecture.qasm(), + filename_nativegates, + gate_set, + ) + return res else: return True @@ -139,6 +148,7 @@ def get_mapped_level( device_name: str, opt_level: int, file_precheck: bool, + return_qc: bool = False, ): """Handles the creation of the benchmark on the target-dependent mapped level. @@ -148,7 +158,6 @@ def get_mapped_level( gate_set_name -- name of this gate set opt_level -- optimization level num_qubits -- number of qubits - smallest_fitting_arch -- flag indicating whether smallest fitting mapping scheme shall be used file_precheck -- flag indicating whether to check whether the file already exists before creating it (again) Return values: @@ -188,9 +197,16 @@ def get_mapped_level( coupling_map=c_map, seed_transpiler=10, ) - res = utils.save_as_qasm( - compiled_with_architecture.qasm(), filename_mapped, gate_set, True, c_map - ) - return res + if return_qc: + return compiled_with_architecture + else: + res = utils.save_as_qasm( + compiled_with_architecture.qasm(), + filename_mapped, + gate_set, + True, + c_map, + ) + return res else: return True diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index ee838d33d..b75ef0e64 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -59,6 +59,7 @@ def get_indep_level( qc: circuit, num_qubits: int, file_precheck: bool, + return_qc: bool = False, ): qasm_output_folder = utils.get_qasm_output_path() @@ -79,8 +80,12 @@ def get_indep_level( ) qc_tket = qiskit_to_tk(target_independent_qiskit) FullPeepholeOptimise().apply(qc_tket) - res = utils.save_as_qasm(circuit_to_qasm_str(qc_tket), filename_native) - return res + if return_qc: + return qc_tket + else: + + res = utils.save_as_qasm(circuit_to_qasm_str(qc_tket), filename_native) + return res else: return True @@ -90,6 +95,7 @@ def get_native_gates_level( gate_set_name: str, num_qubits: int, file_precheck: bool, + return_qc: bool = False, ): qasm_output_folder = utils.get_qasm_output_path() @@ -114,10 +120,14 @@ def get_native_gates_level( native_gate_set_rebase.apply(qc_tket) FullPeepholeOptimise().apply(qc_tket) native_gate_set_rebase.apply(qc_tket) - res = utils.save_as_qasm( - circuit_to_qasm_str(qc_tket), filename_native, native_gate_set_rebase - ) - return res + + if return_qc: + return qc_tket + else: + res = utils.save_as_qasm( + circuit_to_qasm_str(qc_tket), filename_native, native_gate_set_rebase + ) + return res else: return True @@ -129,6 +139,7 @@ def get_mapped_level( device: str, lineplacement: bool, file_precheck: bool, + return_qc: bool = False, ): qasm_output_folder = utils.get_qasm_output_path() @@ -176,9 +187,12 @@ def get_mapped_level( PlacementPass(GraphPlacement(arch)).apply(qc_tket) RoutingPass(arch).apply(qc_tket) native_gate_set_rebase.apply(qc_tket) - res = utils.save_as_qasm( - circuit_to_qasm_str(qc_tket), filename_mapped, native_gate_set_rebase - ) - return res + if return_qc: + return qc_tket + else: + res = utils.save_as_qasm( + circuit_to_qasm_str(qc_tket), filename_mapped, native_gate_set_rebase + ) + return res else: return True diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index 9838a6778..3c972e1dd 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -150,6 +150,15 @@ def get_rigetti_c_map(circles: int = 4): return c_map_rigetti +def get_ionq11_c_map(): + ionq11_c_map = [] + for i in range(0, 11): + for j in range(0, 11): + if i != j: + ionq11_c_map.append([i, j]) + return ionq11_c_map + + def get_google_c_map(): """Returns a coupling map of the hardware layout scheme used by Google's Sycamore chip.""" c_map_google = [] @@ -376,6 +385,8 @@ def get_cmap_from_devicename(device: str): return get_rigetti_c_map(10) elif device == "lucy": return get_cmap_oqc_lucy() + elif device == "ionq11": + return get_ionq11_c_map() else: return False From bfa09381210444f7929155102649aaa5ffa7b401 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Mon, 8 Aug 2022 15:36:13 +0200 Subject: [PATCH 014/231] =?UTF-8?q?=E2=9C=A8=20added=20some=20more=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/tests/test_all.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mqt/bench/tests/test_all.py b/mqt/bench/tests/test_all.py index 72b9bb133..082a1f123 100644 --- a/mqt/bench/tests/test_all.py +++ b/mqt/bench/tests/test_all.py @@ -262,8 +262,12 @@ def test_routing(): [ ("dj", "alg", 5, None, "qiskit", 1, None, None), ("wstate", 0, 6, None, "qiskit", 2, None, None), + ("wstate", 0, 6, None, "tket", True, None, None), + ("wstate", 0, 6, None, "tket", False, None, None), ("ghz", "indep", 5, None, "qiskit", 3, None, None), ("graphstate", 1, 4, None, "qiskit", 0, None, None), + ("graphstate", 1, 4, None, "tket", True, None, None), + ("graphstate", 1, 4, None, "tket", False, None, None), ("groundstate", 1, 4, "small", "qiskit", 1, None, None), ("dj", "nativegates", 5, None, "qiskit", 2, "ionq", None), ("dj", "nativegates", 5, None, "qiskit", 2, "ibm", None), From 6ad79253be7499402ce415ca0a24b2f3e33d4682 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Mon, 8 Aug 2022 15:57:18 +0200 Subject: [PATCH 015/231] =?UTF-8?q?=E2=9C=A8=20adjustments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 91 +++++++++++++++---------------- mqt/bench/utils/qiskit_helper.py | 11 ++-- mqt/bench/utils/utils.py | 93 -------------------------------- 3 files changed, 50 insertions(+), 145 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index c8a5fad58..032e49cbf 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -299,28 +299,26 @@ def generate_target_dep_level_circuit( break else: num_generated_benchmarks += 1 - n_actual = res - - if gate_set_name != "ionq": - for opt_level in range(4): - for device_name, max_qubits in devices: - # Creating the circuit on target-dependent: mapped level qiskit - if max_qubits >= qc.num_qubits: - res = benchmark_generation_watcher( - qiskit_helper.get_mapped_level, - [ - qc, - gate_set_name, - n_actual, - device_name, - opt_level, - file_precheck, - ], - ) - if not res: - continue - else: - num_generated_benchmarks += 1 + + for opt_level in range(4): + for device_name, max_qubits in devices: + # Creating the circuit on target-dependent: mapped level qiskit + if max_qubits >= qc.num_qubits: + res = benchmark_generation_watcher( + qiskit_helper.get_mapped_level, + [ + qc, + gate_set_name, + qc.num_qubits, + device_name, + opt_level, + file_precheck, + ], + ) + if not res: + continue + else: + num_generated_benchmarks += 1 # Creating the circuit on both target-dependent levels for tket @@ -334,28 +332,26 @@ def generate_target_dep_level_circuit( ], ) num_generated_benchmarks += 1 - n_actual = res - if gate_set_name != "ionq": - for device_name, max_qubits in devices: - if max_qubits >= qc.num_qubits: - for lineplacement in (False, True): - # Creating the circuit on target-dependent: mapped level tket - res = benchmark_generation_watcher( - tket_helper.get_mapped_level, - [ - qc, - gate_set_name, - n_actual, - device_name, - lineplacement, - file_precheck, - ], - ) - if not res: - continue - else: - num_generated_benchmarks += 1 + for device_name, max_qubits in devices: + if max_qubits >= qc.num_qubits: + for lineplacement in (False, True): + # Creating the circuit on target-dependent: mapped level tket + res = benchmark_generation_watcher( + tket_helper.get_mapped_level, + [ + qc, + gate_set_name, + qc.num_qubits, + device_name, + lineplacement, + file_precheck, + ], + ) + if not res: + continue + else: + num_generated_benchmarks += 1 return num_generated_benchmarks @@ -516,12 +512,13 @@ def get_one_benchmark( circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" 0 corresponds to "alg" level and 3 to "mapped" level - opt_level -- Level of optimization (relevant to "gates" and "mapped" levels) - gate_set_name -- Either "ibm" or "rigetti" - + compiler -- "qiskit" or "tket" + compiler_settings -- Optimization level for if compiler is qiskit (0-3), Line Placement or Graph Placement if compiler is tket (True or False) + gate_set_name -- "ibm", "rigetti", "ionq", or "oqc" + device_name -- "ibm_washington", "ibm_montreal", "aspen_m1", "ionq11", ""lucy"" Return values: - QuantumCircuit -- Representing the benchmark with the selected options + QuantumCircuit -- Representing the benchmark with the selected options, either as Qiskit::QuantumCircuit or Pytket::Circuit object """ init_module_paths() diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index 149f7015a..4c4fac7f9 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -154,16 +154,17 @@ def get_mapped_level( Keyword arguments: qc -- quantum circuit which the to be created benchmark circuit is based on - gate_set -- set of to be used gates - gate_set_name -- name of this gate set + gate_set_name -- name of the gate set + num_qubits -- number of qubits + device_name -- -- name of the target device opt_level -- optimization level num_qubits -- number of qubits file_precheck -- flag indicating whether to check whether the file already exists before creating it (again) + return_qc -- flag indicating whether the actual circuit object is returned Return values: - filename_mapped -- the filename of the created and saved benchmark - depth -- circuit depth of created benchmark - num_qubits -- number of qubits of generated circuit + if return_qc == True -- quantum circuit object + else -- True/False indicating whether the function call was successful or not """ gate_set = get_native_gates(gate_set_name) diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index 3c972e1dd..a381c68ec 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -180,99 +180,6 @@ def get_google_c_map(): return c_map_google -# def select_c_map(gate_set_name: str, smallest_fitting_arch: bool, num_qubits: int): -# """Returns a suitable coupling map for input parameters -# -# Keyword arguments: -# gate_set_name -- name of used gate set -# smallest_fitting_arch -- flag indicating whether smallest fitting mapping scheme shall be used -# num_qubits -- number of qubits -# -# Return values: -# c_map -- coupling map for input parameters -# backend_name -- name of the hardware layout for the respective coupling map -# gate_set_name_mapped -- combination of gate_set_name and smallest_fitting_arch -# c_map_found -- indicator whether a suitable coupling map has been found -# """ -# c_map_found = False -# c_map = [] -# backend_name = "" -# gate_set_name_mapped = "" -# -# if gate_set_name == "rigetti": -# c_map_found = True -# if smallest_fitting_arch: -# if num_qubits <= 8: -# c_map = get_rigetti_c_map(1) -# backend_name = "8 qubits" -# elif num_qubits <= 16: -# c_map = get_rigetti_c_map(2) -# backend_name = "Aspen-3: 16 qubits" -# elif num_qubits <= 32: -# c_map = get_rigetti_c_map(4) -# backend_name = "Aspen-10: 32 qubits" -# elif num_qubits <= 40: -# c_map = get_rigetti_c_map(5) -# backend_name = "Aspen-11: 40 qubits" -# elif num_qubits <= 80: -# c_map = get_rigetti_c_map(10) -# backend_name = "Aspen-M-1: 80 qubits" -# else: -# c_map_found = False -# gate_set_name_mapped = gate_set_name + "-s" -# -# elif num_qubits <= 80: -# c_map = get_rigetti_c_map(10) -# backend_name = "Aspen-M-1: 80 qubits" -# gate_set_name_mapped = gate_set_name + "-b" -# else: -# c_map_found = False -# -# elif gate_set_name == "ibm": -# c_map_found = True -# if smallest_fitting_arch: -# if num_qubits <= 5: -# backend = FakeBogota() -# c_map = backend.configuration().coupling_map -# backend_name = backend.name() -# elif num_qubits <= 7: -# backend = FakeCasablanca() -# c_map = backend.configuration().coupling_map -# backend_name = backend.name() -# elif num_qubits <= 16: -# backend = FakeGuadalupe() -# c_map = backend.configuration().coupling_map -# backend_name = backend.name() -# elif num_qubits <= 27: -# backend = FakeMontreal() -# c_map = backend.configuration().coupling_map -# backend_name = backend.name() -# elif num_qubits <= 65: -# backend = FakeManhattan() -# c_map = backend.configuration().coupling_map -# backend_name = backend.name() -# elif num_qubits <= 127: -# backend = FakeWashington() -# c_map = backend.configuration().coupling_map -# backend_name = backend.name() -# else: -# c_map_found = False -# gate_set_name_mapped = gate_set_name + "-s" -# -# elif num_qubits <= 127: -# backend = FakeWashington() -# c_map = backend.configuration().coupling_map -# backend_name = backend.name() -# gate_set_name_mapped = gate_set_name + "-b" -# else: -# c_map_found = False -# -# if c_map_found: -# return c_map, backend_name, gate_set_name_mapped, c_map_found -# else: -# return None, "", "", False - - def get_openqasm_gates(): """Returns a list of all quantum gates within the openQASM 2.0 standard header.""" # according to https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/qasm/libs/qelib1.inc From c664abbc6f25870b4a3d511fadcef2fa30858b08 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Mon, 8 Aug 2022 17:38:34 +0200 Subject: [PATCH 016/231] =?UTF-8?q?=E2=9C=A8=20parallelization=20and=20adj?= =?UTF-8?q?ustment=20of=20timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 3 +-- mqt/bench/benchmark_generator.py | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/config.json b/config.json index abd381310..21674177b 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,5 @@ { -"timeout": 300, -"max_depth": 1000000, +"timeout": 1, "save_png": false, "save_hist": false, "benchmarks": [ diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 032e49cbf..bf377ef0e 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -58,8 +58,6 @@ def create_benchmarks_from_config(cfg_path: str): print("Read config successful") # global seetings - global max_depth - max_depth = cfg["max_depth"] global timeout timeout = cfg["timeout"] @@ -68,9 +66,13 @@ def create_benchmarks_from_config(cfg_path: str): if not path.isdir(qasm_output_folder): mkdir(qasm_output_folder) - for benchmark in cfg["benchmarks"]: - print(benchmark["name"]) - generate_benchmark(benchmark) + + #for benchmark in cfg["benchmarks"]: + #print(benchmark["name"]) + #generate_benchmark(benchmark) + + from joblib import Parallel, delayed + Parallel(n_jobs=-1, verbose=1)(delayed(generate_benchmark)(benchmark) for benchmark in cfg["benchmarks"]) return @@ -87,6 +89,14 @@ def timeout_handler(signum, frame): # Custom signal handler signal.alarm(timeout) try: res = func(*args) + except TimeoutException: + print( + "Calculation/Generation exceeded timeout limit for ", + func, + args[0].name, + args[1:], + ) + return False except Exception as e: # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) print("Exception: ", e, func, args[0].name, args[1:]) From 4296e9c76f1408115aad363056661696f970ab18 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 08:16:27 +0200 Subject: [PATCH 017/231] =?UTF-8?q?=E2=9C=A8=20checked=20and=20adjusted=20?= =?UTF-8?q?timeout=20criterion=20to=20abort=20benchmark=20generation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index bf377ef0e..6d3f42b79 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -66,13 +66,15 @@ def create_benchmarks_from_config(cfg_path: str): if not path.isdir(qasm_output_folder): mkdir(qasm_output_folder) - - #for benchmark in cfg["benchmarks"]: - #print(benchmark["name"]) - #generate_benchmark(benchmark) + # for benchmark in cfg["benchmarks"]: + # print(benchmark["name"]) + # generate_benchmark(benchmark) from joblib import Parallel, delayed - Parallel(n_jobs=-1, verbose=1)(delayed(generate_benchmark)(benchmark) for benchmark in cfg["benchmarks"]) + + Parallel(n_jobs=-1, verbose=1)( + delayed(generate_benchmark)(benchmark) for benchmark in cfg["benchmarks"] + ) return @@ -252,10 +254,16 @@ def generate_circuits_on_all_levels(qc, num_qubits, file_precheck): num_generated_circuits_t_indep = generate_target_indep_level_circuit( qc, num_qubits, file_precheck ) + if not num_generated_circuits_t_indep: + return False + num_generated_circuits_t_dep = generate_target_dep_level_circuit( qc, num_qubits, file_precheck ) + if not num_generated_circuits_t_dep: + return False + print(num_generated_circuits_t_indep, num_generated_circuits_t_dep) return num_generated_circuits_t_indep + num_generated_circuits_t_dep @@ -268,13 +276,13 @@ def generate_target_indep_level_circuit( num_generated_circuits = 0 res = qiskit_helper.get_indep_level(qc, num_qubits, file_precheck) if not res: - return num_generated_circuits + return False else: num_generated_circuits += 1 res = tket_helper.get_indep_level(qc, num_qubits, file_precheck) if not res: - return num_generated_circuits + return False else: num_generated_circuits += 1 @@ -310,8 +318,8 @@ def generate_target_dep_level_circuit( else: num_generated_benchmarks += 1 - for opt_level in range(4): - for device_name, max_qubits in devices: + for device_name, max_qubits in devices: + for opt_level in range(4): # Creating the circuit on target-dependent: mapped level qiskit if max_qubits >= qc.num_qubits: res = benchmark_generation_watcher( @@ -326,7 +334,7 @@ def generate_target_dep_level_circuit( ], ) if not res: - continue + break else: num_generated_benchmarks += 1 @@ -341,6 +349,8 @@ def generate_target_dep_level_circuit( file_precheck, ], ) + if not res: + continue num_generated_benchmarks += 1 for device_name, max_qubits in devices: @@ -362,6 +372,8 @@ def generate_target_dep_level_circuit( continue else: num_generated_benchmarks += 1 + if num_generated_benchmarks == 0: + return False return num_generated_benchmarks From ba8474c4322533f9e631047db43859745021a5a5 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 09:07:59 +0200 Subject: [PATCH 018/231] =?UTF-8?q?=F0=9F=92=A1=20renamed=20devices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 4 ++-- mqt/bench/utils/utils.py | 25 ++----------------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 6d3f42b79..b64011d4e 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -295,9 +295,9 @@ def generate_target_dep_level_circuit( compilation_paths = [ ("ibm", [("ibm_washington", 127), ("ibm_montreal", 27)]), - ("rigetti", [("aspen_m1", 80)]), + ("rigetti", [("rigetti_aspen_m1", 80)]), ("ionq", [("ionq11", 11)]), - ("oqc", [("lucy", 8)]), + ("oqc", [("oqc_lucy", 8)]), ] num_generated_benchmarks = 0 for gate_set_name, devices in compilation_paths: diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index a381c68ec..eac02404a 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -159,27 +159,6 @@ def get_ionq11_c_map(): return ionq11_c_map -def get_google_c_map(): - """Returns a coupling map of the hardware layout scheme used by Google's Sycamore chip.""" - c_map_google = [] - # iterate through each second line of qubits in sycamore architecture - for j in range(1, 8, 2): - for i in range(6): - # connect qubit to upper left und lower left qubits - c_map_google.append([i + 6 * j, i + 6 * j + 5]) - c_map_google.append([i + 6 * j, i + 6 * j - 6]) - - # as long as it is not the most right qubit: connect it to upper right and lower right qubit - if i != 5: - c_map_google.append([i + 6 * j, i + 6 * j - 5]) - c_map_google.append([i + 6 * j, i + 6 * j + 7]) - - inverted = [[item[1], item[0]] for item in c_map_google] - c_map_google = c_map_google + inverted - - return c_map_google - - def get_openqasm_gates(): """Returns a list of all quantum gates within the openQASM 2.0 standard header.""" # according to https://github.com/Qiskit/qiskit-terra/blob/main/qiskit/qasm/libs/qelib1.inc @@ -288,9 +267,9 @@ def get_cmap_from_devicename(device: str): return FakeWashington().configuration().coupling_map elif device == "ibm_montreal": return FakeMontreal().configuration().coupling_map - elif device == "aspen_m1": + elif device == "rigetti_aspen_m1": return get_rigetti_c_map(10) - elif device == "lucy": + elif device == "oqc_lucy": return get_cmap_oqc_lucy() elif device == "ionq11": return get_ionq11_c_map() From ede8c5e3e5601da1f6beb4c2d57e6ae2f4c645b6 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 09:08:08 +0200 Subject: [PATCH 019/231] =?UTF-8?q?=E2=9C=A8adjusted=20timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 21674177b..237334b5e 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { -"timeout": 1, +"timeout": 10, "save_png": false, "save_hist": false, "benchmarks": [ From cf3aeae1bf3d0c3d8a4e4d1f680534f61c8da12c Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 09:08:37 +0200 Subject: [PATCH 020/231] =?UTF-8?q?=E2=9C=A8adjusted=20compilation=20path?= =?UTF-8?q?=20generations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/qiskit_helper.py | 2 - mqt/bench/utils/tket_helper.py | 80 ++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index 4c4fac7f9..82460a441 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -174,8 +174,6 @@ def get_mapped_level( qc.name + "_mapped_" + device_name - + "_" - + gate_set_name + "_qiskit_opt" + str(opt_level) + "_" diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index b75ef0e64..ac789174e 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -18,41 +18,55 @@ from qiskit import transpile -def get_rebase(gate_set_name: str): +def get_rebase(gate_set_name: str, get_gatenames: bool = False): if gate_set_name == "ionq": - return get_ionq_rebase() + return get_ionq_rebase(get_gatenames) elif gate_set_name == "oqc": - return get_oqc_rebase() + return get_oqc_rebase(get_gatenames) elif gate_set_name == "ibm": - return get_ibm_rebase() + return get_ibm_rebase(get_gatenames) elif gate_set_name == "rigetti": - return get_rigetti_rebase() + return get_rigetti_rebase(get_gatenames) -def get_ionq_rebase(): - ionq_rebase = auto_rebase_pass( - {OpType.Rz, OpType.Ry, OpType.Rx, OpType.XXPhase, OpType.Measure} - ) - return ionq_rebase +def get_ionq_rebase(get_gatenames: bool = False): + if get_gatenames: + return ["rz", "ry", "rx", "rxx", "measure"] + else: + ionq_rebase = auto_rebase_pass( + {OpType.Rz, OpType.Ry, OpType.Rx, OpType.XXPhase, OpType.Measure} + ) + return ionq_rebase -def get_oqc_rebase(): - oqc_rebase = auto_rebase_pass( - {OpType.Rz, OpType.SX, OpType.X, OpType.ECR, OpType.Measure} - ) - return oqc_rebase +def get_oqc_rebase(get_gatenames: bool = False): + if get_gatenames: + return ["rz", "sx", "x", "ecr", "measure"] + else: + oqc_rebase = auto_rebase_pass( + {OpType.Rz, OpType.SX, OpType.X, OpType.ECR, OpType.Measure} + ) + return oqc_rebase -def get_rigetti_rebase(): - rigetti_rebase = auto_rebase_pass({OpType.Rz, OpType.Rx, OpType.CZ, OpType.Measure}) - return rigetti_rebase +def get_rigetti_rebase(get_gatenames: bool = False): + if get_gatenames: + return ["rz", "rx", "cz", "measure"] + else: + rigetti_rebase = auto_rebase_pass( + {OpType.Rz, OpType.Rx, OpType.CZ, OpType.Measure} + ) + return rigetti_rebase -def get_ibm_rebase(): - ibm_rebase = auto_rebase_pass( - {OpType.Rz, OpType.SX, OpType.X, OpType.CX, OpType.Measure} - ) - return ibm_rebase +def get_ibm_rebase(get_gatenames: bool = False): + if get_gatenames: + return ["rz", "sx", "x", "cx", "measure"] + else: + ibm_rebase = auto_rebase_pass( + {OpType.Rz, OpType.SX, OpType.X, OpType.CX, OpType.Measure} + ) + return ibm_rebase def get_indep_level( @@ -116,6 +130,7 @@ def get_native_gates_level( qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 ) qc_tket = qiskit_to_tk(target_independent_qiskit) + native_gatenames = get_rebase(gate_set_name, True) native_gate_set_rebase = get_rebase(gate_set_name) native_gate_set_rebase.apply(qc_tket) FullPeepholeOptimise().apply(qc_tket) @@ -125,7 +140,7 @@ def get_native_gates_level( return qc_tket else: res = utils.save_as_qasm( - circuit_to_qasm_str(qc_tket), filename_native, native_gate_set_rebase + circuit_to_qasm_str(qc_tket), filename_native, native_gatenames ) return res else: @@ -150,15 +165,7 @@ def get_mapped_level( placement = "graph" filename_mapped = ( - qc.name - + "_mapped_" - + device - + "_" - + gate_set_name - + "_tket_" - + placement - + "_" - + str(num_qubits) + qc.name + "_mapped_" + device + "_tket_" + placement + "_" + str(num_qubits) ) if not ( path.isfile(qasm_output_folder + filename_mapped + ".qasm") and file_precheck @@ -176,6 +183,7 @@ def get_mapped_level( ) qc_tket = qiskit_to_tk(target_independent_qiskit) + native_gatenames = get_rebase(gate_set_name, True) native_gate_set_rebase = get_rebase(gate_set_name) arch = architecture.Architecture(cmap) @@ -191,7 +199,11 @@ def get_mapped_level( return qc_tket else: res = utils.save_as_qasm( - circuit_to_qasm_str(qc_tket), filename_mapped, native_gate_set_rebase + circuit_to_qasm_str(qc_tket), + filename_mapped, + native_gatenames, + True, + cmap, ) return res else: From 8f17d3b4896ccacf2c2f26364a1c11fbe64980ba Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 13:02:26 +0200 Subject: [PATCH 021/231] =?UTF-8?q?=F0=9F=90=9B=20adjusted=20device=20nami?= =?UTF-8?q?ng=20also=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/tests/test_all.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/mqt/bench/tests/test_all.py b/mqt/bench/tests/test_all.py index 082a1f123..5fd4450b4 100644 --- a/mqt/bench/tests/test_all.py +++ b/mqt/bench/tests/test_all.py @@ -29,6 +29,7 @@ from mqt.bench.benchmarks.qiskit_application_nature import groundstate, excitedstate from mqt.bench.benchmarks.qiskit_application_optimization import tsp, routing from qiskit_nature.drivers import Molecule +from qiskit import QuantumCircuit from mqt.bench.benchmark_generator import get_one_benchmark import pytest @@ -129,9 +130,9 @@ def test_quantumcircuit_native_and_mapped_levels(benchmark, input_value, scalabl compilation_paths = [ ("ibm", [("ibm_washington", 127), ("ibm_montreal", 27)]), - ("rigetti", [("aspen_m1", 80)]), + ("rigetti", [("rigetti_aspen_m1", 80)]), ("ionq", [("ionq11", 11)]), - ("oqc", [("lucy", 8)]), + ("oqc", [("oqc_lucy", 8)]), ] for gate_set_name, devices in compilation_paths: opt_level = 1 @@ -229,10 +230,6 @@ def test_rigetti_cmap_generator(num_circles: int): assert len(utils.get_rigetti_c_map(num_circles)) == 212 -def test_get_google_c_map(): - assert len(utils.get_google_c_map()) == 176 - - def test_dj_constant_oracle(): qc = dj.create_circuit(5, False) assert qc.depth() > 0 @@ -279,17 +276,17 @@ def test_routing(): ("qft", 2, 6, None, "tket", True, "oqc", None), ("qpeexact", "mapped", 5, None, "qiskit", 1, "ibm", "ibm_washington"), ("qpeexact", "mapped", 5, None, "qiskit", 1, "ibm", "ibm_montreal"), - ("qpeexact", "mapped", 5, None, "qiskit", 1, "rigetti", "aspen_m1"), + ("qpeexact", "mapped", 5, None, "qiskit", 1, "rigetti", "rigetti_aspen_m1"), ("qpeexact", "mapped", 5, None, "qiskit", 1, "ionq", "ionq11"), - ("qpeexact", "mapped", 5, None, "qiskit", 1, "oqc", "lucy"), + ("qpeexact", "mapped", 5, None, "qiskit", 1, "oqc", "oqc_lucy"), ("qpeinexact", 3, 4, None, "qiskit", 1, "ibm", "ibm_washington"), ("qpeinexact", 3, 4, None, "tket", True, "ibm", "ibm_washington"), ("qpeinexact", 3, 4, None, "qiskit", 1, "ibm", "ibm_montreal"), ("qpeinexact", 3, 4, None, "tket", False, "ibm", "ibm_montreal"), - ("qpeinexact", 3, 4, None, "qiskit", 1, "rigetti", "aspen_m1"), - ("qpeinexact", 3, 4, None, "tket", True, "rigetti", "aspen_m1"), - ("qpeinexact", 3, 4, None, "qiskit", 1, "oqc", "lucy"), - ("qpeinexact", 3, 4, None, "tket", False, "oqc", "lucy"), + ("qpeinexact", 3, 4, None, "qiskit", 1, "rigetti", "rigetti_aspen_m1"), + ("qpeinexact", 3, 4, None, "tket", True, "rigetti", "rigetti_aspen_m1"), + ("qpeinexact", 3, 4, None, "qiskit", 1, "oqc", "oqc_lucy"), + ("qpeinexact", 3, 4, None, "tket", False, "oqc", "oqc_lucy"), ], ) def test_get_one_benchmark( @@ -322,3 +319,12 @@ def test_configure_end(): os.remove(os.path.join(test_qasm_output_path, f)) os.rmdir(test_qasm_output_path) utils.set_qasm_output_path() + + +# def test_generated_files(): +# directory = os.fsencode(utils.get_qasm_output_path()) +# +# for f in os.listdir(directory): +# if f.endswith(".qasm"): +# qc = QuantumCircuit.from_qasm_str(os.path.join(directory, f)) +# assert qc From 0cc7d77195b44366482f157fc23ad25842a0c668 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 14:26:47 +0200 Subject: [PATCH 022/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20tests=20and=20im?= =?UTF-8?q?plemented=20postprocessing=20from=20oqc=20qasm=20dumps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/tests/test_all.py | 25 +++++++++++++----- mqt/bench/utils/utils.py | 52 +++++++++++++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/mqt/bench/tests/test_all.py b/mqt/bench/tests/test_all.py index 5fd4450b4..fb408fa86 100644 --- a/mqt/bench/tests/test_all.py +++ b/mqt/bench/tests/test_all.py @@ -321,10 +321,21 @@ def test_configure_end(): utils.set_qasm_output_path() -# def test_generated_files(): -# directory = os.fsencode(utils.get_qasm_output_path()) -# -# for f in os.listdir(directory): -# if f.endswith(".qasm"): -# qc = QuantumCircuit.from_qasm_str(os.path.join(directory, f)) -# assert qc +def test_generated_files(): + + utils.postprocess_ocr_qasm_files() + + directory = utils.get_qasm_output_path() + failed_files = [] + for f in os.listdir(directory): + if f.endswith(".qasm"): + path = os.path.join(directory, f) + try: + qc = QuantumCircuit.from_qasm_file(path) + except: + failed_files.append(path) + + with open("failed_files.txt", "w") as f: + for fail in failed_files: + f.write(str(fail) + "\n") + assert "oqc" in str(fail) diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index eac02404a..c6c58b887 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -7,14 +7,10 @@ import networkx as nx import numpy as np -from os import path +import os from qiskit.test.mock import ( - FakeBogota, - FakeCasablanca, - FakeGuadalupe, FakeMontreal, - FakeManhattan, FakeWashington, ) @@ -306,3 +302,49 @@ def get_molecule(benchmark_instance_name: str): instances = {"small": m_1, "medium": m_2, "large": m_3} return instances[benchmark_instance_name] + + +def postprocess_ocr_qasm_files(): + directory = get_qasm_output_path() + for filename in os.listdir(directory): + f = os.path.join(directory, filename) + # checking if it is a file + if "oqc_lucy_qiskit" in f or "oqc_qiskit" in f: + with open(f, "r") as f: + lines = f.readlines() + new_name = os.path.join(directory + "qasm_compiled_postprocessed", filename) + with open(new_name, "w") as f: + for line in lines: + if not ( + "gate rzx" in line.strip("\n") or "gate ecr" in line.strip("\n") + ): + f.write(line) + if "gate ecr" in line.strip("\n"): + f.write( + "gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }\n" + ) + f.write( + "gate ecr q0,q1 { rzx(pi/4) q0,q1; x q0; rzx(-pi/4) q0,q1; }\n" + ) + + qc = QuantumCircuit.from_qasm_file(new_name) + print("New qasm file for: ", new_name) + + elif "oqc_lucy_tket" in f or "oqc_tket" in f: + with open(f, "r") as f: + lines = f.readlines() + new_name = os.path.join(directory + "qasm_compiled_postprocessed", filename) + with open(new_name, "w") as f: + count = 0 + for line in lines: + f.write(line) + count += 1 + if count == 9: + f.write( + "gate rzx(param0) q0,q1 { h q1; cx q0,q1; rz(param0) q1; cx q0,q1; h q1; }\n" + ) + f.write( + "gate ecr q0,q1 { rzx(pi/4) q0,q1; x q0; rzx(-pi/4) q0,q1; }\n" + ) + qc = QuantumCircuit.from_qasm_file(new_name) + print("New qasm file for: ", new_name) From 40d7d475486a6c03d97af9716e56e185844bbdc7 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 14:54:21 +0200 Subject: [PATCH 023/231] =?UTF-8?q?=E2=9C=A8=20added=20test=20to=20check?= =?UTF-8?q?=20the=20gates=20of=20a=20compiled=20quantum=20circuit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/tests/test_all.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/mqt/bench/tests/test_all.py b/mqt/bench/tests/test_all.py index fb408fa86..b22e4c108 100644 --- a/mqt/bench/tests/test_all.py +++ b/mqt/bench/tests/test_all.py @@ -30,6 +30,7 @@ from mqt.bench.benchmarks.qiskit_application_optimization import tsp, routing from qiskit_nature.drivers import Molecule from qiskit import QuantumCircuit +from pytket.qasm import circuit_to_qasm_str from mqt.bench.benchmark_generator import get_one_benchmark import pytest @@ -271,7 +272,7 @@ def test_routing(): ("dj", "nativegates", 5, None, "qiskit", 2, "rigetti", None), ("dj", "nativegates", 5, None, "qiskit", 2, "oqc", None), ("qft", 2, 6, None, "qiskit", 3, "ionq", None), - ("qft", 2, 6, None, "qiskit", 3, "qiskit", None), + ("qft", 2, 6, None, "qiskit", 3, "ibm", None), ("qft", 2, 6, None, "tket", False, "rigetti", None), ("qft", 2, 6, None, "tket", True, "oqc", None), ("qpeexact", "mapped", 5, None, "qiskit", 1, "ibm", "ibm_washington"), @@ -311,6 +312,15 @@ def test_get_one_benchmark( device_name, ) assert qc.depth() > 0 + if gate_set_name and "oqc" not in gate_set_name: + if compiler == "tket": + qc = QuantumCircuit.from_qasm_str(circuit_to_qasm_str(qc)) + for instruction, qargs, cargs in qc.data: + gate_type = instruction.name + assert ( + gate_type in qiskit_helper.get_native_gates(gate_set_name) + or gate_type == "barrier" + ) def test_configure_end(): @@ -322,10 +332,13 @@ def test_configure_end(): def test_generated_files(): + directory = utils.get_qasm_output_path() + directory_postprocessing = directory + "qasm_compiled_postprocessed/" + for f in os.listdir(directory_postprocessing): + os.remove(os.path.join(directory_postprocessing, f)) utils.postprocess_ocr_qasm_files() - directory = utils.get_qasm_output_path() failed_files = [] for f in os.listdir(directory): if f.endswith(".qasm"): From 0da1671fd794591328aa74c588440d7d10bdcefe Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 16:19:07 +0200 Subject: [PATCH 024/231] =?UTF-8?q?=E2=9C=A8=20added=20database=20parser?= =?UTF-8?q?=20prototype=20for=20new=20compilation=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adjusted_database_parser.ipynb | 1091 ++++++++++++++++++++++++++++++++ 1 file changed, 1091 insertions(+) create mode 100644 adjusted_database_parser.ipynb diff --git a/adjusted_database_parser.ipynb b/adjusted_database_parser.ipynb new file mode 100644 index 000000000..868435849 --- /dev/null +++ b/adjusted_database_parser.ipynb @@ -0,0 +1,1091 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "0b4f01e5", + "metadata": {}, + "outputs": [], + "source": [ + "def get_opt_level(filename: str):\n", + " \"\"\"Extracts the optimization level based on a filename.\n", + "\n", + " Keyword arguments:\n", + " filename -- filename of a benchmark\n", + "\n", + " Return values:\n", + " num -- optimization level\n", + " \"\"\"\n", + "\n", + " pat = re.compile(r\"opt\\d\")\n", + " m = pat.search(filename)\n", + " if m:\n", + " num = m.group()[-1:]\n", + " else:\n", + " num = -1\n", + " return int(num)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "cd66bb9e", + "metadata": {}, + "outputs": [], + "source": [ + "def get_num_qubits(filename: str):\n", + " \"\"\"Extracts the number of qubits based on a filename.\n", + "\n", + " Keyword arguments:\n", + " filename -- filename of a benchmark\n", + "\n", + " Return values:\n", + " num -- optimization level\n", + " \"\"\"\n", + "\n", + " pat = re.compile(r\"(\\d+)\\.\")\n", + " m = pat.search(filename)\n", + " if m:\n", + " num = m.group()[0:-1]\n", + " else:\n", + " num = -1\n", + " return int(num)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "6b8feed9", + "metadata": {}, + "outputs": [], + "source": [ + "def get_tket_settings(filename: str):\n", + " if \"line\" in filename:\n", + " return \"line\"\n", + " elif \"graph\" in filename:\n", + " return \"graph\"\n", + "\n", + "def get_gate_set(filename: str):\n", + " if \"oqc\" in filename:\n", + " return \"oqc\"\n", + " elif \"ionq\" in filename:\n", + " return \"ionq\"\n", + " elif \"ibm\" in filename:\n", + " return \"ibm\"\n", + " elif \"oqc\" in filename:\n", + " return \"oqc\"\n", + " \n", + " \n", + "def get_target_device(filename: str):\n", + " if \"ibm_washington\" in filename:\n", + " return \"ibm_washington\"\n", + " elif \"ibm_montreal\" in filename:\n", + " return \"ibm_montreal\"\n", + " elif \"rigetti_aspen_m1\" in filename:\n", + " return \"rigetti_aspen_m1\"\n", + " elif \"ionq11\" in filename:\n", + " return \"ionq11\"\n", + " elif \"oqc_lucy\" in filename:\n", + " return \"oqc_lucy\"" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "0dcb1760", + "metadata": {}, + "outputs": [], + "source": [ + "def get_compiler_and_settings(filename:str):\n", + " if \"qiskit\" in filename:\n", + " return (\"qiskit\", get_opt_level(filename))\n", + " elif \"tket\" in filename:\n", + " return (\"tket\", get_tket_settings(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "f133dfb1", + "metadata": {}, + "outputs": [], + "source": [ + "def parse_data(filename: str):\n", + " \"\"\"Extracts the necessary information from a given filename.\n", + "\n", + " Keyword arguments:\n", + " filename -- name of file\n", + "\n", + " Return values:\n", + " parsed_data -- parsed data extracted from filename\n", + " \"\"\"\n", + " benchmark = filename.split(\"_\")[1].lower().split(\"/\")[-1]\n", + " num_qubits = get_num_qubits(filename)\n", + " indep_flag = \"indep\" in filename\n", + " nativegates_flag = \"nativegates\" in filename\n", + " mapped_flag = \"mapped\" in filename\n", + " compiler, compiler_settings = get_compiler_and_settings(filename)\n", + " gate_set = get_gate_set(filename)\n", + " target_device = get_target_device(filename)\n", + "\n", + " path = os.path.join(filename)\n", + " parsed_data = [\n", + " benchmark,\n", + " num_qubits,\n", + " indep_flag,\n", + " nativegates_flag,\n", + " mapped_flag,\n", + " compiler,\n", + " compiler_settings,\n", + " gate_set,\n", + " target_device,\n", + " path,\n", + " ]\n", + " return parsed_data" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "a16ae36f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
benchmarknum_qubitsindep_flagnativegates_flagmapped_flagcompilercompiler_settingsgate_settarget_devicepath
0ae27FalseTrueFalseqiskit0ionqNone./benchviewer/static/files/qasm_output/ae_nati...
1graphstate24FalseTrueFalseqiskit3oqcNone./benchviewer/static/files/qasm_output/graphst...
2dj41FalseFalseTrueqiskit2ibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
3qft8TrueFalseFalsetketNoneNoneNone./benchviewer/static/files/qasm_output/qft_ind...
4graphstate19FalseTrueFalseqiskit1oqcNone./benchviewer/static/files/qasm_output/graphst...
5qaoa3FalseFalseTruetketlineoqcoqc_lucy./benchviewer/static/files/qasm_output/qaoa_ma...
6graphstate4FalseTrueFalseqiskit0ibmNone./benchviewer/static/files/qasm_output/graphst...
7qftentangled16FalseFalseTrueqiskit2Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/qftenta...
8qpeinexact25FalseTrueFalseqiskit2ibmNone./benchviewer/static/files/qasm_output/qpeinex...
9qpeinexact18FalseTrueFalseqiskit0ibmNone./benchviewer/static/files/qasm_output/qpeinex...
10dj112FalseFalseTrueqiskit2ibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
11qftentangled19FalseTrueFalsetketNoneionqNone./benchviewer/static/files/qasm_output/qftenta...
12qftentangled18FalseFalseTrueqiskit2ibmibm_washington./benchviewer/static/files/qasm_output/qftenta...
13qpeinexact7FalseFalseTrueqiskit1Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/qpeinex...
14qftentangled25FalseFalseTrueqiskit0ibmibm_washington./benchviewer/static/files/qasm_output/qftenta...
15qwalk-noancilla3FalseFalseTruetketgraphionqionq11./benchviewer/static/files/qasm_output/qwalk-n...
16dj30FalseTrueFalseqiskit1ibmNone./benchviewer/static/files/qasm_output/dj_nati...
17dj62FalseTrueFalseqiskit0oqcNone./benchviewer/static/files/qasm_output/dj_nati...
18pricingput5FalseFalseTruetketlineoqcoqc_lucy./benchviewer/static/files/qasm_output/pricing...
19qpeexact22FalseFalseTrueqiskit0ibmibm_montreal./benchviewer/static/files/qasm_output/qpeexac...
20qpeexact17FalseTrueFalseqiskit0NoneNone./benchviewer/static/files/qasm_output/qpeexac...
21ghz34FalseFalseTrueqiskit3Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/ghz_map...
22ae11FalseFalseTruetketgraphNonerigetti_aspen_m1./benchviewer/static/files/qasm_output/ae_mapp...
23realamprandom10FalseTrueFalseqiskit3oqcNone./benchviewer/static/files/qasm_output/realamp...
24qaoa17FalseFalseTrueqiskit2ibmibm_washington./benchviewer/static/files/qasm_output/qaoa_ma...
25qpeinexact15FalseFalseTrueqiskit0Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/qpeinex...
26dj42FalseTrueFalsetketNoneionqNone./benchviewer/static/files/qasm_output/dj_nati...
27qwalk-noancilla6FalseTrueFalseqiskit0NoneNone./benchviewer/static/files/qasm_output/qwalk-n...
28pricingcall5FalseFalseTrueqiskit0ionqionq11./benchviewer/static/files/qasm_output/pricing...
29ghz49FalseTrueFalsetketNoneionqNone./benchviewer/static/files/qasm_output/ghz_nat...
30dj56FalseTrueFalseqiskit0NoneNone./benchviewer/static/files/qasm_output/dj_nati...
31dj112FalseFalseTrueqiskit3ibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
32grover-noancilla2FalseFalseTrueqiskit0Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/grover-...
33ae17FalseFalseTrueqiskit2Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/ae_mapp...
34graphstate52FalseFalseTrueqiskit0ibmibm_washington./benchviewer/static/files/qasm_output/graphst...
35qftentangled10FalseTrueFalseqiskit0ionqNone./benchviewer/static/files/qasm_output/qftenta...
36realamprandom13FalseFalseTrueqiskit2Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/realamp...
37graphstate28TrueFalseFalsetketgraphNoneNone./benchviewer/static/files/qasm_output/graphst...
38qft31FalseTrueFalsetketNoneNoneNone./benchviewer/static/files/qasm_output/qft_nat...
39dj69FalseFalseTruetketgraphibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
40grover-noancilla8FalseTrueFalseqiskit0ionqNone./benchviewer/static/files/qasm_output/grover-...
41qft14FalseFalseTruetketgraphNonerigetti_aspen_m1./benchviewer/static/files/qasm_output/qft_map...
42ghz100TrueFalseFalseqiskit-1NoneNone./benchviewer/static/files/qasm_output/ghz_ind...
43dj72TrueFalseFalsetketNoneNoneNone./benchviewer/static/files/qasm_output/dj_inde...
44graphstate7FalseTrueFalsetketgraphibmNone./benchviewer/static/files/qasm_output/graphst...
45graphstate30TrueFalseFalseqiskit-1NoneNone./benchviewer/static/files/qasm_output/graphst...
46qaoa8FalseTrueFalseqiskit2ionqNone./benchviewer/static/files/qasm_output/qaoa_na...
47dj86FalseFalseTruetketgraphibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
48graphstate44FalseTrueFalseqiskit1ionqNone./benchviewer/static/files/qasm_output/graphst...
49portfoliovqe8FalseFalseTruetketlineoqcoqc_lucy./benchviewer/static/files/qasm_output/portfol...
\n", + "
" + ], + "text/plain": [ + " benchmark num_qubits indep_flag nativegates_flag mapped_flag \\\n", + "0 ae 27 False True False \n", + "1 graphstate 24 False True False \n", + "2 dj 41 False False True \n", + "3 qft 8 True False False \n", + "4 graphstate 19 False True False \n", + "5 qaoa 3 False False True \n", + "6 graphstate 4 False True False \n", + "7 qftentangled 16 False False True \n", + "8 qpeinexact 25 False True False \n", + "9 qpeinexact 18 False True False \n", + "10 dj 112 False False True \n", + "11 qftentangled 19 False True False \n", + "12 qftentangled 18 False False True \n", + "13 qpeinexact 7 False False True \n", + "14 qftentangled 25 False False True \n", + "15 qwalk-noancilla 3 False False True \n", + "16 dj 30 False True False \n", + "17 dj 62 False True False \n", + "18 pricingput 5 False False True \n", + "19 qpeexact 22 False False True \n", + "20 qpeexact 17 False True False \n", + "21 ghz 34 False False True \n", + "22 ae 11 False False True \n", + "23 realamprandom 10 False True False \n", + "24 qaoa 17 False False True \n", + "25 qpeinexact 15 False False True \n", + "26 dj 42 False True False \n", + "27 qwalk-noancilla 6 False True False \n", + "28 pricingcall 5 False False True \n", + "29 ghz 49 False True False \n", + "30 dj 56 False True False \n", + "31 dj 112 False False True \n", + "32 grover-noancilla 2 False False True \n", + "33 ae 17 False False True \n", + "34 graphstate 52 False False True \n", + "35 qftentangled 10 False True False \n", + "36 realamprandom 13 False False True \n", + "37 graphstate 28 True False False \n", + "38 qft 31 False True False \n", + "39 dj 69 False False True \n", + "40 grover-noancilla 8 False True False \n", + "41 qft 14 False False True \n", + "42 ghz 100 True False False \n", + "43 dj 72 True False False \n", + "44 graphstate 7 False True False \n", + "45 graphstate 30 True False False \n", + "46 qaoa 8 False True False \n", + "47 dj 86 False False True \n", + "48 graphstate 44 False True False \n", + "49 portfoliovqe 8 False False True \n", + "\n", + " compiler compiler_settings gate_set target_device \\\n", + "0 qiskit 0 ionq None \n", + "1 qiskit 3 oqc None \n", + "2 qiskit 2 ibm ibm_washington \n", + "3 tket None None None \n", + "4 qiskit 1 oqc None \n", + "5 tket line oqc oqc_lucy \n", + "6 qiskit 0 ibm None \n", + "7 qiskit 2 None rigetti_aspen_m1 \n", + "8 qiskit 2 ibm None \n", + "9 qiskit 0 ibm None \n", + "10 qiskit 2 ibm ibm_washington \n", + "11 tket None ionq None \n", + "12 qiskit 2 ibm ibm_washington \n", + "13 qiskit 1 None rigetti_aspen_m1 \n", + "14 qiskit 0 ibm ibm_washington \n", + "15 tket graph ionq ionq11 \n", + "16 qiskit 1 ibm None \n", + "17 qiskit 0 oqc None \n", + "18 tket line oqc oqc_lucy \n", + "19 qiskit 0 ibm ibm_montreal \n", + "20 qiskit 0 None None \n", + "21 qiskit 3 None rigetti_aspen_m1 \n", + "22 tket graph None rigetti_aspen_m1 \n", + "23 qiskit 3 oqc None \n", + "24 qiskit 2 ibm ibm_washington \n", + "25 qiskit 0 None rigetti_aspen_m1 \n", + "26 tket None ionq None \n", + "27 qiskit 0 None None \n", + "28 qiskit 0 ionq ionq11 \n", + "29 tket None ionq None \n", + "30 qiskit 0 None None \n", + "31 qiskit 3 ibm ibm_washington \n", + "32 qiskit 0 None rigetti_aspen_m1 \n", + "33 qiskit 2 None rigetti_aspen_m1 \n", + "34 qiskit 0 ibm ibm_washington \n", + "35 qiskit 0 ionq None \n", + "36 qiskit 2 None rigetti_aspen_m1 \n", + "37 tket graph None None \n", + "38 tket None None None \n", + "39 tket graph ibm ibm_washington \n", + "40 qiskit 0 ionq None \n", + "41 tket graph None rigetti_aspen_m1 \n", + "42 qiskit -1 None None \n", + "43 tket None None None \n", + "44 tket graph ibm None \n", + "45 qiskit -1 None None \n", + "46 qiskit 2 ionq None \n", + "47 tket graph ibm ibm_washington \n", + "48 qiskit 1 ionq None \n", + "49 tket line oqc oqc_lucy \n", + "\n", + " path \n", + "0 ./benchviewer/static/files/qasm_output/ae_nati... \n", + "1 ./benchviewer/static/files/qasm_output/graphst... \n", + "2 ./benchviewer/static/files/qasm_output/dj_mapp... \n", + "3 ./benchviewer/static/files/qasm_output/qft_ind... \n", + "4 ./benchviewer/static/files/qasm_output/graphst... \n", + "5 ./benchviewer/static/files/qasm_output/qaoa_ma... \n", + "6 ./benchviewer/static/files/qasm_output/graphst... \n", + "7 ./benchviewer/static/files/qasm_output/qftenta... \n", + "8 ./benchviewer/static/files/qasm_output/qpeinex... \n", + "9 ./benchviewer/static/files/qasm_output/qpeinex... \n", + "10 ./benchviewer/static/files/qasm_output/dj_mapp... \n", + "11 ./benchviewer/static/files/qasm_output/qftenta... \n", + "12 ./benchviewer/static/files/qasm_output/qftenta... \n", + "13 ./benchviewer/static/files/qasm_output/qpeinex... \n", + "14 ./benchviewer/static/files/qasm_output/qftenta... \n", + "15 ./benchviewer/static/files/qasm_output/qwalk-n... \n", + "16 ./benchviewer/static/files/qasm_output/dj_nati... \n", + "17 ./benchviewer/static/files/qasm_output/dj_nati... \n", + "18 ./benchviewer/static/files/qasm_output/pricing... \n", + "19 ./benchviewer/static/files/qasm_output/qpeexac... \n", + "20 ./benchviewer/static/files/qasm_output/qpeexac... \n", + "21 ./benchviewer/static/files/qasm_output/ghz_map... \n", + "22 ./benchviewer/static/files/qasm_output/ae_mapp... \n", + "23 ./benchviewer/static/files/qasm_output/realamp... \n", + "24 ./benchviewer/static/files/qasm_output/qaoa_ma... \n", + "25 ./benchviewer/static/files/qasm_output/qpeinex... \n", + "26 ./benchviewer/static/files/qasm_output/dj_nati... \n", + "27 ./benchviewer/static/files/qasm_output/qwalk-n... \n", + "28 ./benchviewer/static/files/qasm_output/pricing... \n", + "29 ./benchviewer/static/files/qasm_output/ghz_nat... \n", + "30 ./benchviewer/static/files/qasm_output/dj_nati... \n", + "31 ./benchviewer/static/files/qasm_output/dj_mapp... \n", + "32 ./benchviewer/static/files/qasm_output/grover-... \n", + "33 ./benchviewer/static/files/qasm_output/ae_mapp... \n", + "34 ./benchviewer/static/files/qasm_output/graphst... \n", + "35 ./benchviewer/static/files/qasm_output/qftenta... \n", + "36 ./benchviewer/static/files/qasm_output/realamp... \n", + "37 ./benchviewer/static/files/qasm_output/graphst... \n", + "38 ./benchviewer/static/files/qasm_output/qft_nat... \n", + "39 ./benchviewer/static/files/qasm_output/dj_mapp... \n", + "40 ./benchviewer/static/files/qasm_output/grover-... \n", + "41 ./benchviewer/static/files/qasm_output/qft_map... \n", + "42 ./benchviewer/static/files/qasm_output/ghz_ind... \n", + "43 ./benchviewer/static/files/qasm_output/dj_inde... \n", + "44 ./benchviewer/static/files/qasm_output/graphst... \n", + "45 ./benchviewer/static/files/qasm_output/graphst... \n", + "46 ./benchviewer/static/files/qasm_output/qaoa_na... \n", + "47 ./benchviewer/static/files/qasm_output/dj_mapp... \n", + "48 ./benchviewer/static/files/qasm_output/graphst... \n", + "49 ./benchviewer/static/files/qasm_output/portfol... " + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from mqt.bench.utils import utils, qiskit_helper, tket_helper\n", + "import os\n", + "import re\n", + "import pandas as pd\n", + "rows_list = []\n", + "# for filename in os.listdir(qasm_path):\n", + "directory = utils.get_qasm_output_path()\n", + "i= 0\n", + "for f in os.listdir(directory):\n", + " i+=1\n", + " parsed_data = parse_data(os.path.join(directory, f))\n", + " rows_list.append(parsed_data)\n", + " if i > 50:\n", + " break\n", + "\n", + "colnames = [\n", + " \"benchmark\",\n", + " \"num_qubits\",\n", + " \"indep_flag\",\n", + " \"nativegates_flag\",\n", + " \"mapped_flag\",\n", + " \"compiler\",\n", + " \"compiler_settings\",\n", + " \"gate_set\",\n", + " \"target_device\",\n", + " \"path\",\n", + "]\n", + "\n", + "database = pd.DataFrame(rows_list, columns=colnames)\n", + "database[\"num_qubits\"] = database[\"num_qubits\"].astype(int)\n", + "database[\"benchmark\"] = database[\"benchmark\"].astype(str)\n", + "\n", + "database.head(50)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "5e749103", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(database)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "94ca287d", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 5d6842053ff02337ea903f68657c5be629ec38de Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 16:49:37 +0200 Subject: [PATCH 025/231] =?UTF-8?q?=E2=9C=A8=20added=20database=20parser?= =?UTF-8?q?=20prototype=20for=20new=20compilation=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adjusted_database_parser.ipynb | 79 ++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/adjusted_database_parser.ipynb b/adjusted_database_parser.ipynb index 868435849..6d456565f 100644 --- a/adjusted_database_parser.ipynb +++ b/adjusted_database_parser.ipynb @@ -3,7 +3,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "0b4f01e5", + "id": "63cd9080", "metadata": {}, "outputs": [], "source": [ @@ -29,7 +29,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "cd66bb9e", + "id": "92b83186", "metadata": {}, "outputs": [], "source": [ @@ -55,7 +55,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "6b8feed9", + "id": "1d2ffaed", "metadata": {}, "outputs": [], "source": [ @@ -65,6 +65,7 @@ " elif \"graph\" in filename:\n", " return \"graph\"\n", "\n", + "\n", "def get_gate_set(filename: str):\n", " if \"oqc\" in filename:\n", " return \"oqc\"\n", @@ -74,8 +75,8 @@ " return \"ibm\"\n", " elif \"oqc\" in filename:\n", " return \"oqc\"\n", - " \n", - " \n", + "\n", + "\n", "def get_target_device(filename: str):\n", " if \"ibm_washington\" in filename:\n", " return \"ibm_washington\"\n", @@ -92,11 +93,11 @@ { "cell_type": "code", "execution_count": 4, - "id": "0dcb1760", + "id": "a8d83429", "metadata": {}, "outputs": [], "source": [ - "def get_compiler_and_settings(filename:str):\n", + "def get_compiler_and_settings(filename: str):\n", " if \"qiskit\" in filename:\n", " return (\"qiskit\", get_opt_level(filename))\n", " elif \"tket\" in filename:\n", @@ -147,7 +148,7 @@ { "cell_type": "code", "execution_count": 22, - "id": "a16ae36f", + "id": "7618ce2d", "metadata": {}, "outputs": [ { @@ -1006,28 +1007,29 @@ "import os\n", "import re\n", "import pandas as pd\n", + "\n", "rows_list = []\n", "# for filename in os.listdir(qasm_path):\n", "directory = utils.get_qasm_output_path()\n", - "i= 0\n", + "i = 0\n", "for f in os.listdir(directory):\n", - " i+=1\n", + " i += 1\n", " parsed_data = parse_data(os.path.join(directory, f))\n", " rows_list.append(parsed_data)\n", " if i > 50:\n", " break\n", "\n", "colnames = [\n", - " \"benchmark\",\n", - " \"num_qubits\",\n", - " \"indep_flag\",\n", - " \"nativegates_flag\",\n", - " \"mapped_flag\",\n", - " \"compiler\",\n", - " \"compiler_settings\",\n", - " \"gate_set\",\n", - " \"target_device\",\n", - " \"path\",\n", + " \"benchmark\",\n", + " \"num_qubits\",\n", + " \"indep_flag\",\n", + " \"nativegates_flag\",\n", + " \"mapped_flag\",\n", + " \"compiler\",\n", + " \"compiler_settings\",\n", + " \"gate_set\",\n", + " \"target_device\",\n", + " \"path\",\n", "]\n", "\n", "database = pd.DataFrame(rows_list, columns=colnames)\n", @@ -1040,7 +1042,7 @@ { "cell_type": "code", "execution_count": 21, - "id": "5e749103", + "id": "d1773aa8", "metadata": {}, "outputs": [ { @@ -1058,10 +1060,43 @@ "len(database)" ] }, + { + "cell_type": "code", + "execution_count": 56, + "id": "e3d103af", + "metadata": {}, + "outputs": [], + "source": [ + "from zipfile import ZipFile, ZIP_DEFLATED\n", + "\n", + "\n", + "def create_zip_file():\n", + " zf = zipfile.ZipFile(\"MQTBench_all.zip\", \"w\")\n", + " for dirname, subdirs, files in os.walk(utils.get_qasm_output_path()):\n", + " for filename in files:\n", + " zf.write(\n", + " os.path.join(dirname, filename),\n", + " compress_type=ZIP_DEFLATED,\n", + " compresslevel=3,\n", + " arcname=filename,\n", + " )\n", + " zf.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "id": "72c430c7", + "metadata": {}, + "outputs": [], + "source": [ + "create_zip_file()" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "94ca287d", + "id": "5198f4f7", "metadata": {}, "outputs": [], "source": [] From 0a6aa6dc8a48d7279f327fae5db4e961ee9f2234 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 16:50:13 +0200 Subject: [PATCH 026/231] =?UTF-8?q?=E2=9C=A8=20added=20zip=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index c6c58b887..497e26067 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -5,6 +5,10 @@ from datetime import date + +from zipfile import ZipFile, ZIP_DEFLATED + + import networkx as nx import numpy as np import os @@ -348,3 +352,22 @@ def postprocess_ocr_qasm_files(): ) qc = QuantumCircuit.from_qasm_file(new_name) print("New qasm file for: ", new_name) + + +def create_zip_file(): + zf = ZipFile("MQTBench_all.zip", "w") + for dirname, subdirs, files in os.walk(get_qasm_output_path()): + for filename in files: + zf.write( + os.path.join(dirname, filename), + compress_type=ZIP_DEFLATED, + compresslevel=3, + arcname=filename, + ) + zf.write( + "./benchviewer/static/files/algo_level.txt", + compress_type=ZIP_DEFLATED, + compresslevel=3, + arcname="algo_level.txt", + ) + zf.close() From 72c875b8db78bf9b3454a924dc26740c21990857 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 9 Aug 2022 16:50:32 +0200 Subject: [PATCH 027/231] =?UTF-8?q?=E2=9C=A8=20added=20automatic=20workflo?= =?UTF-8?q?w=20including=20postprocessing=20for=20ocq=20qasm=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 6 +++--- mqt/bench/tests/test_all.py | 8 ++------ mqt/bench/utils/utils.py | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index b64011d4e..cc9f5e8f5 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -261,11 +261,9 @@ def generate_circuits_on_all_levels(qc, num_qubits, file_precheck): qc, num_qubits, file_precheck ) - if not num_generated_circuits_t_dep: + if not num_generated_circuits_t_dep and not num_generated_circuits_t_indep: return False - print(num_generated_circuits_t_indep, num_generated_circuits_t_dep) - return num_generated_circuits_t_indep + num_generated_circuits_t_dep @@ -656,3 +654,5 @@ def get_one_benchmark( print(args.file_name) create_benchmarks_from_config(args.file_name) + postprocess_ocr_qasm_files() + utils.create_zip_file() diff --git a/mqt/bench/tests/test_all.py b/mqt/bench/tests/test_all.py index b22e4c108..babf02d7d 100644 --- a/mqt/bench/tests/test_all.py +++ b/mqt/bench/tests/test_all.py @@ -333,11 +333,6 @@ def test_configure_end(): def test_generated_files(): directory = utils.get_qasm_output_path() - directory_postprocessing = directory + "qasm_compiled_postprocessed/" - for f in os.listdir(directory_postprocessing): - os.remove(os.path.join(directory_postprocessing, f)) - - utils.postprocess_ocr_qasm_files() failed_files = [] for f in os.listdir(directory): @@ -351,4 +346,5 @@ def test_generated_files(): with open("failed_files.txt", "w") as f: for fail in failed_files: f.write(str(fail) + "\n") - assert "oqc" in str(fail) + + assert len(failed_files) == 0 diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index 497e26067..1a5a6efbb 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -316,7 +316,7 @@ def postprocess_ocr_qasm_files(): if "oqc_lucy_qiskit" in f or "oqc_qiskit" in f: with open(f, "r") as f: lines = f.readlines() - new_name = os.path.join(directory + "qasm_compiled_postprocessed", filename) + new_name = os.path.join(directory, filename) with open(new_name, "w") as f: for line in lines: if not ( @@ -337,7 +337,7 @@ def postprocess_ocr_qasm_files(): elif "oqc_lucy_tket" in f or "oqc_tket" in f: with open(f, "r") as f: lines = f.readlines() - new_name = os.path.join(directory + "qasm_compiled_postprocessed", filename) + new_name = os.path.join(directory, filename) with open(new_name, "w") as f: count = 0 for line in lines: From 09c6e68348790c7521f599f986f6110dbd47456d Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 10 Aug 2022 15:14:18 +0200 Subject: [PATCH 028/231] =?UTF-8?q?=F0=9F=92=A1commented=20out=20the=20log?= =?UTF-8?q?ging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/main.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/benchviewer/main.py b/benchviewer/main.py index 99b37d58e..e11f9dbec 100644 --- a/benchviewer/main.py +++ b/benchviewer/main.py @@ -17,7 +17,7 @@ def init(): read_mqtbench_all_zip() init_database() - logging.basicConfig(filename="/local/mqtbench/downloads.log", level=logging.INFO) + #logging.basicConfig(filename="/local/mqtbench/downloads.log", level=logging.INFO) init() @@ -43,11 +43,7 @@ def download_pre_gen_zip(): directory = "./static/files/qasm_output/" filename = "MQTBench_all.zip" timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") - app.logger.info("###### Start ######") - app.logger.info("Timestamp: %s", timestamp) - app.logger.info("Headers: %s", request.headers) - app.logger.info("Download of pre-generated zip") - app.logger.info("###### End ######") + return send_from_directory( directory=directory, path=filename, @@ -68,12 +64,7 @@ def download_data(): prepared_data ) timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") - app.logger.info("###### Start ######") - app.logger.info("Timestamp: %s", timestamp) - app.logger.info("Headers: %s", request.headers) - app.logger.info("Prepared_data: %s", prepared_data) - app.logger.info("Download started: %s", len(file_paths)) - app.logger.info("###### End ######") + if file_paths or python_files_list: return app.response_class( From 5a2c7716f39e6f3acb3374b5fc69a9c276cd4094 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 10 Aug 2022 15:14:26 +0200 Subject: [PATCH 029/231] =?UTF-8?q?=E2=9C=A8=20initial=20new=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/templates/index.html | 238 ++++++++++++++++++++++++++++--- 1 file changed, 219 insertions(+), 19 deletions(-) diff --git a/benchviewer/templates/index.html b/benchviewer/templates/index.html index ddd574861..59a8cf2a0 100644 --- a/benchviewer/templates/index.html +++ b/benchviewer/templates/index.html @@ -10,22 +10,22 @@ integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> MQT Bench @@ -59,7 +59,7 @@
-
+

Welcome to the Munich Quantum Toolkit Benchmark Library (MQT Bench)!

@@ -127,8 +127,208 @@

page.

-
+
+

Benchmark Selection

+ +
+
+
Scalable Benchmarks:
+
+ + +
+ {% for benchmark in benchmarks %} + +
+
+ + {{ benchmark.name }} +
+
+ {% endfor %} +
+ +
+
Non-Scalable Benchmarks:
+ +
+ {% for nonscalable_benchmark in nonscalable_benchmarks %} + + +
+
+ + {{ nonscalable_benchmark.name }} +
+
+ + {% endfor %} +
+ +
+ +
+
Independent Level Options
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
Target-dependent: Native-Gates Level Options
+ +
+
+ + +
+
+ + + + + + + + +
+
+ +
+
+ + +
+
+
+
Native Gate Sets
+
+ + + + + + + + +
+
+ +
+
Target-dependent: Mapped Level Options
+
+
+ + +
+
+ + + + + + + + +
+
+
+
+ + +
+
+ + + + +
+ +
+
+
Devices
+
+ + + + + + + + + + +
+
+ +
+
+
# of selected benchmarks:
+
0
+ +
+ +
+
+ +
+
+
+ You can download a pre-generated .zip file with all available benchmarks here: +
+ +
+
+ + From 0d77e6afb992c47888995ad117e68dfba4426357 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 10 Aug 2022 16:30:25 +0200 Subject: [PATCH 030/231] =?UTF-8?q?=E2=9C=A8=20added=20disable/enable=20lo?= =?UTF-8?q?gic=20to=20initial=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/templates/index.html | 1283 ++++++------------------------ 1 file changed, 236 insertions(+), 1047 deletions(-) diff --git a/benchviewer/templates/index.html b/benchviewer/templates/index.html index 59a8cf2a0..398390aff 100644 --- a/benchviewer/templates/index.html +++ b/benchviewer/templates/index.html @@ -10,22 +10,7 @@ integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> MQT Bench @@ -57,636 +42,269 @@ - -
-
-

- Welcome to the Munich Quantum Toolkit Benchmark Library (MQT Bench)! -

-

Quantum software tools for a wide variety of design - tasks on and across different levels of abstraction are crucial for - eventually realizing useful quantum applications. This requires - practical and relevant benchmarks in order for new software - tools or design automation methods to be empirically evaluated and compared to the current - state of the art. Since these tools and methods operate on and across different - levels of abstraction, it is beneficial having benchmarks consistently available across those levels. The - MQT Benchmark Library (MQT Bench) provides a single benchmark suite which offers the same benchmark - algorithms on different levels of abstractions. At the moment, MQT Bench comprises more than 30.000 - benchmark - circuits ranging from 2 up to 130 qubits on four abstraction levels.

- -

In order to create a benchmark set according to your needs, simply use to form below to choose -

    -
  • the desired benchmark, -
  • the qubit range, -
  • the abstraction level (we currently consider an algorithmic level, a target-independent level, a - target-dependent native gates level, and a target-dependent mapped level), -
  • a native gate-set considered by the compiler (we currently consider the gate-sets provided by machines - from IBM and Rigetti), -
  • the architecture considered by the compiler (we currently consider the smallest and the biggest - architecture possible for the respective benchmark), as well as -
  • the optimization level used by the compiler to generate results for the target-dependent native gates - level and the target-dependent mapped level (O0 to O3, similar to the optimization levels - of classical compilers). -
- Afterwards, push the "Download Benchmarks"-button to download all benchmark instances based on the selection as - a .zip file.

- -

For a brief description of the benchmarks, we are referring to this page. -

- -

For a brief description of the file format of the resulting instances, we are referring to this page.

- -

For a more detailed description of MQT Bench, we are referring to the corresponding paper - "MQT Bench: Benchmarking Software and - Design Automation Tools for Quantum Computing". Our implementation is available on - Github. -

- -

In case you are using MQT Bench in your work, we would be thankful if you referred to it by citing - the following publication: -

- @misc{quetschlich2022mqtbench,
-   title={{{MQT Bench}}: Benchmarking Software and Design Automation Tools for Quantum Computing},
-   shorttitle = {{{MQT Bench}}},
-   author={Quetschlich, Nils and Burgholzer, Lukas and Wille, Robert},
-   year={2022},
-   eprint = {2204.13719},
-   eprinttype = {arxiv},
-   publisher = {arXiv},
-   note={{{MQT Bench}} is available at \url{https://www.cda.cit.tum.de/mqtbench/}},
+

+
+

+ Welcome to the Munich Quantum Toolkit Benchmark Library (MQT Bench)! +

+

Quantum software tools for a wide variety of design + tasks on and across different levels of abstraction are crucial for + eventually realizing useful quantum applications. This requires + practical and relevant benchmarks in order for new software + tools or design automation methods to be empirically evaluated and compared to the current + state of the art. Since these tools and methods operate on and across different + levels of abstraction, it is beneficial having benchmarks consistently available across those levels. The + MQT Benchmark Library (MQT Bench) provides a single benchmark suite which offers the same benchmark + algorithms on different levels of abstractions. At the moment, MQT Bench comprises more than 30.000 + benchmark + circuits ranging from 2 up to 130 qubits on four abstraction levels.

+ +

In order to create a benchmark set according to your needs, simply use to form below to choose +

    +
  • the desired benchmark, +
  • the qubit range, +
  • the abstraction level (we currently consider an algorithmic level, a target-independent level, a + target-dependent native gates level, and a target-dependent mapped level), +
  • a native gate-set considered by the compiler (we currently consider the gate-sets provided by machines + from IBM and Rigetti), +
  • the architecture considered by the compiler (we currently consider the smallest and the biggest + architecture possible for the respective benchmark), as well as +
  • the optimization level used by the compiler to generate results for the target-dependent native gates + level and the target-dependent mapped level (O0 to O3, similar to the optimization levels + of classical compilers). +
+ Afterwards, push the "Download Benchmarks"-button to download all benchmark instances based on the selection as + a .zip file.

+ +

For a brief description of the benchmarks, we are referring to this page. +

+ +

For a brief description of the file format of the resulting instances, we are referring to this page.

+ +

For a more detailed description of MQT Bench, we are referring to the corresponding paper + "MQT Bench: Benchmarking Software and + Design Automation Tools for Quantum Computing". Our implementation is available on + Github. +

+ +

In case you are using MQT Bench in your work, we would be thankful if you referred to it by citing + the following publication: +

+ @misc{quetschlich2022mqtbench,
+   title={{{MQT Bench}}: Benchmarking Software and Design Automation Tools for Quantum + Computing},
+   shorttitle = {{{MQT Bench}}},
+   author={Quetschlich, Nils and Burgholzer, Lukas and Wille, Robert},
+   year={2022},
+   eprint = {2204.13719},
+   eprinttype = {arxiv},
+   publisher = {arXiv},
+   note={{{MQT Bench}} is available at \url{https://www.cda.cit.tum.de/mqtbench/}},
} -

-

+

+

-

In case you have any problems or questions feel free to contact us via quantum.cda@xcit.tum.de. More on our work on quantum - computation is summarized on this - page.

+

In case you have any problems or questions feel free to contact us via quantum.cda@xcit.tum.de. More on our work on quantum + computation is summarized on this + page.

-
+

Benchmark Selection

-
+
+ +
+
+ + Select all +
+
-
Scalable Benchmarks:
-
- - -
- {% for benchmark in benchmarks %} -
+ +
Scalable Benchmarks:
+
+ + +
+ {% for benchmark in benchmarks %} + +
{{ benchmark.name }}
+
+ {% endfor %}
- {% endfor %} -
-
-
Non-Scalable Benchmarks:
-
- {% for nonscalable_benchmark in nonscalable_benchmarks %} +
+
Non-Scalable Benchmarks:
+ + (Fixed Number of Qubits) + {% for nonscalable_benchmark in nonscalable_benchmarks %} -
-
- - {{ nonscalable_benchmark.name }} +
+
+ + {{ nonscalable_benchmark.name }} +
+ + {% endfor %}
- {% endfor %}
-
+
+
+
Independent Level Options
-
-
Independent Level Options
+ id="indep_qiskit_compiler">
-
-
- - -
+
+
+ +
+
+
+
-
-
Target-dependent: Native-Gates Level Options
+
+
Target-dependent: Native-Gates Level Options
- +
- + - + - + - +
-
-
- - -
-
-
-
Native Gate Sets
-
- - - - - - - - -
-
- -
-
Target-dependent: Mapped Level Options
- -
-
- - - - - - - - -
-
-
-
- - -
-
- - - - -
- -
-
-
Devices
-
- - - - - - - - - - -
-
- -
-
-
# of selected benchmarks:
-
0
- -
- -
- - -
-
-
- You can download a pre-generated .zip file with all available benchmarks here: -
- -
-
- - @@ -726,10 +344,34 @@
Target-dependent: Mapped Level Options
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"> - - - From 8360870a1d3008d510b3ba25a995e62bc73c8f23 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 10 Aug 2022 16:30:50 +0200 Subject: [PATCH 031/231] =?UTF-8?q?=F0=9F=90=9B=20debug=20print=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchviewer/main.py b/benchviewer/main.py index e11f9dbec..cf7e711d3 100644 --- a/benchviewer/main.py +++ b/benchviewer/main.py @@ -59,7 +59,8 @@ def download_data(): if request.method == "POST": data = request.form prepared_data = prepareFormInput(data) - # print("prepared input data :", prepared_data) + print("raw data :", data) + print("prepared input data :", prepared_data) file_paths, algo_dicts, python_files_list = get_selected_file_paths( prepared_data ) From f7f85316437befb50cda4b79b449c4a1bed3522d Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 10 Aug 2022 17:36:53 +0200 Subject: [PATCH 032/231] =?UTF-8?q?=F0=9F=9A=A7=20work=20in=20progress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/main.py | 4 +- benchviewer/src/backend.py | 288 +++++++++++++++---------------- benchviewer/templates/index.html | 160 ++++++++--------- 3 files changed, 226 insertions(+), 226 deletions(-) diff --git a/benchviewer/main.py b/benchviewer/main.py index cf7e711d3..b997357af 100644 --- a/benchviewer/main.py +++ b/benchviewer/main.py @@ -17,7 +17,7 @@ def init(): read_mqtbench_all_zip() init_database() - #logging.basicConfig(filename="/local/mqtbench/downloads.log", level=logging.INFO) + # logging.basicConfig(filename="/local/mqtbench/downloads.log", level=logging.INFO) init() @@ -66,7 +66,6 @@ def download_data(): ) timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") - if file_paths or python_files_list: return app.response_class( generate_zip_ephemeral_chunks(file_paths, python_files_list), @@ -111,6 +110,7 @@ def benchmark_description(): @app.route(f"{PREFIX}/get_num_benchmarks", methods=["POST"]) def get_num_benchmarks(): + return None if request.method == "POST": data = request.form prepared_data = prepareFormInput(data) diff --git a/benchviewer/src/backend.py b/benchviewer/src/backend.py index 432c46077..01117368f 100644 --- a/benchviewer/src/backend.py +++ b/benchviewer/src/backend.py @@ -206,114 +206,6 @@ def parse_data(filename: str): return parsed_data -def parseFilterCriteria(input_data): - """Reformats the input_data such that it is easier to filter the database. - - Keyword arguments: - input_data -- dictionaries of all selected benchmarks - - Return values: - filter_list -- list of filter criteria for each selected benchmark - algo_dicts -- dictionary to handle the algorithm level, since that one is not available as a downloadable file - list(set(python_files_list)) -- list of all python files needed to generated the algorithm level - """ - algo_dicts = [] - python_files_list = [] - - filter_list = [] - for key, value in input_data.items(): - if "selectBench_" + str(key) not in value.keys(): - continue - min_qubits = -1 - max_qubits = -1 - algorithm_flag = False - indep_flag = False - nativegates_flag = False - mapped_flag = False - smallest_mapping = False - biggest_mapping = False - gate_set_ibm = False - gate_set_rigetti = False - opt_levels = [] - if int(key) > 0 and int(key) <= len(benchmarks): - name = benchmarks[int(key) - 1]["filename"] - elif int(key) > 0 and int(key) <= len(benchmarks) + len(nonscalable_benchmarks): - name = nonscalable_benchmarks[int(key) - 1 - len(benchmarks)]["filename"] - for key, value in value.items(): - if "minQubits" in key: - min_qubits = value - if "maxQubits" in key: - max_qubits = value - if "algorithmLevel" in key and value: - algorithm_flag = True - if "indepLevel" in key and value: - indep_flag = True - elif "nativeGatesLevel" in key and value: - nativegates_flag = True - elif "mappedLevel" in key and value: - mapped_flag = True - - if "ibm" in key: - gate_set_ibm = True - if "rigetti" in key: - gate_set_rigetti = True - if "optlevel0" in key: - opt_levels.append(0) - if "optlevel1" in key: - opt_levels.append(1) - if "optlevel2" in key: - opt_levels.append(2) - if "optlevel3" in key: - opt_levels.append(3) - if "smallest_arch" in key: - smallest_mapping = True - if "biggest_arch" in key: - biggest_mapping = True - - if sum([algorithm_flag, indep_flag, nativegates_flag, mapped_flag]) == 0: - continue - - filter_list.append( - [ - name, - min_qubits, - max_qubits, - gate_set_ibm, - gate_set_rigetti, - algorithm_flag, - indep_flag, - nativegates_flag, - mapped_flag, - smallest_mapping, - biggest_mapping, - opt_levels, - ] - ) - - if algorithm_flag: - if min_qubits != -1 and max_qubits != -1: - tmp_dict = { - "name": name, - "min_qubits": min_qubits, - "max_qubits": max_qubits, - } - else: - config_file_path = "../config.json" - with open(config_file_path, "r") as jsonfile: - cfg = json.load(jsonfile) - for benchmark_config in cfg["benchmarks"]: - if name == benchmark_config["name"]: - tmp_dict = benchmark_config - del tmp_dict["include"] - break - - algo_dicts.append(tmp_dict) - # python_files_list.append(name.split("-")[0]) - python_files_list.append("./static/files/algo_level.txt") - - return filter_list, algo_dicts, list(set(python_files_list)) - - def filterDatabase(filterCriteria, database): """Filters the database according to the filter criteria. @@ -340,19 +232,39 @@ def filterDatabase(filterCriteria, database): db_filtered = pd.DataFrame(columns=colnames) if len(database) == 0: return [] - # for each line of input (benchmark) - for line in filterCriteria: - benchmark = line[0] - min_qubits = int(line[1]) - max_qubits = int(line[2]) - gate_set_ibm = line[3] - gate_set_rigetti = line[4] - indep_flag = line[6] - nativegates_flag = line[7] - mapped_flag = line[8] - smallest_mapping = line[9] - biggest_mapping = line[10] - opt_levels = line[11] + + ( + (min_qubits, max_qubits), + indices_benchmarks, + (indep_qiskit_compiler, indep_tket_compiler), + ( + (nativegates_qiskit_compiler, nativegates_tket_compiler), + native_qiskit_opt_lvls, + native_gatesets, + ), + ( + (mapped_qiskit_compiler, mapped_tket_compiler), + (mapped_qiskit_opt_lvls, mapped_tket_placements), + mapped_devices, + ), + ) = filterCriteria + + db_tmp = database.loc[ + (database["num_qubits"] >= min_qubits) + & (database["num_qubits"] <= max_qubits) + ] + + if indep_qiskit_compiler: + #db_filtered = pd.concat([db_filtered, dbxyz]) + if indep_tket_compiler: + #db_filtered = pd.concat([db_filtered, dbxyz]) + + if nativegates_qiskit_compiler: + #consider + #native_qiskit_opt_lvls, + #native_gatesets, + + if nativegates_tket_compiler: # filter for benchmark name db1 = database.loc[(database["benchmark"] == benchmark)] @@ -365,11 +277,7 @@ def filterDatabase(filterCriteria, database): ] else: db2 = db1 - # Algo Layer - # if (algo_flag): - # db3 = db2.loc[(database["algo_layer"])] - # db_filtered = pd.concat([db_filtered, db3]) - # T-indep layer + if indep_flag: db4 = db2.loc[(database["indep_layer"])] # db4_tmp = db2.loc[(database["indep_layer"])] @@ -539,12 +447,12 @@ def get_selected_file_paths(prepared_data): algo_dicts -- dictionary to handle the algorithm level, since that one is not available as a downloadable file python_files_list -- list of all python files needed to generated the algorithm level """ - filter_criteria, algo_dicts, python_files_list = parseFilterCriteria(prepared_data) - if filter_criteria: - file_paths = filterDatabase(filter_criteria, database) - return file_paths, algo_dicts, python_files_list + + if prepared_data: + file_paths = filterDatabase(prepared_data, database) + return file_paths else: - return False, False, False + return False def init_database(): @@ -560,25 +468,117 @@ def init_database(): def prepareFormInput(formData): - """Formats the formData extracted from the user's inputs such that each benchmark is stored in one dictionary. - - Keyword arguments: - formData -- unformatted user's filter criterias + """Formats the formData extracted from the user's inputs.""" + + min_qubits = -1 + max_qubits = -1 + indep_qiskit_compiler = False + indep_tket_compiler = False + nativegates_qiskit_compiler = False + nativegates_tket_compiler = False + native_qiskit_opt_lvls = [] + native_gatesets = [] + mapped_qiskit_compiler = False + mapped_tket_compiler = False + mapped_qiskit_opt_lvls = [] + mapped_tket_placements = [] + mapped_devices = [] - Return values: - sub_dicts -- dictionary of dictionaries representing the user's filter criteria - """ - # Path form data into several dictionaries, one for each benchmark pat = re.compile(r"_\d+") - sub_dicts = {} + num_benchmarks = [] for k, v in formData.items(): m = pat.search(k) if m: num = m.group()[1:] - sub_dicts.setdefault(num, {})[k] = v - if "0" in sub_dicts: - del sub_dicts["0"] - return sub_dicts + num_benchmarks.append(num) + + if "minQubits" in k: + min_qubits = v + if "maxQubits" in k: + max_qubits = v + if "indep_qiskit_compiler" in k: + indep_qiskit_compiler = True + if "indep_tket_compiler" in k: + indep_tket_compiler = True + + if "nativegates_qiskit_compiler" in k: + nativegates_qiskit_compiler = True + if "nativegates_tket_compiler" in k: + nativegates_tket_compiler = True + if "nativegates_qiskit_compiler_opt0" in k: + native_qiskit_opt_lvls.append(0) + if "nativegates_qiskit_compiler_opt1" in k: + native_qiskit_opt_lvls.append(1) + if "nativegates_qiskit_compiler_opt2" in k: + native_qiskit_opt_lvls.append(2) + if "nativegates_qiskit_compiler_opt3" in k: + native_qiskit_opt_lvls.append(3) + + if "nativegates_ibm" in k: + native_gatesets.append("ibm") + if "nativegates_rigetti" in k: + native_gatesets.append("rigetti") + if "nativegates_oqc" in k: + native_gatesets.append("oqc") + if "nativegates_ionq" in k: + native_gatesets.append("ionq") + + if "mapped_qiskit_compiler" in k: + mapped_qiskit_compiler = True + if "mapped_tket_compiler" in k: + mapped_tket_compiler = True + if "mapped_qiskit_compiler_opt0" in k: + mapped_qiskit_opt_lvls.append(0) + if "mapped_qiskit_compiler_opt1" in k: + mapped_qiskit_opt_lvls.append(1) + if "mapped_qiskit_compiler_opt2" in k: + mapped_qiskit_opt_lvls.append(2) + if "mapped_qiskit_compiler_opt3" in k: + mapped_qiskit_opt_lvls.append(3) + + if "mapped_tket_compiler_graph" in k: + mapped_tket_placements.append("graph") + if "mapped_tket_compiler_line" in k: + mapped_tket_placements.append("line") + + if "device_ibm_montreal" in k: + mapped_devices.append("ibm_montreal") + if "device_ibm_washington" in k: + mapped_devices.append("ibm_washington") + if "device_rigetti_aspen_m1" in k: + mapped_devices.append("rigetti_aspen_m1") + if "device_oqc_lucy" in k: + mapped_devices.append("oqc_lucy") + if "device_ionq_ionq11" in k: + mapped_devices.append("ionq11") + + print("benchmarks: ", num_benchmarks) + print("indep compiler: ", indep_qiskit_compiler, indep_tket_compiler) + print("native compiler: ", nativegates_qiskit_compiler, nativegates_tket_compiler) + print("native compiler settings qiskit: ", native_qiskit_opt_lvls) + print("native compiler gatesets: ", native_gatesets) + print("mapped compiler: ", mapped_qiskit_compiler, mapped_tket_compiler) + print("mapped compiler settings qiskit: ", mapped_qiskit_opt_lvls) + print("mapped compiler settings tket: ", mapped_tket_placements) + print("mapped devices: ", mapped_devices) + + res = ( + (min_qubits, max_qubits), + num_benchmarks, + (indep_qiskit_compiler, indep_tket_compiler), + ( + (nativegates_qiskit_compiler, nativegates_tket_compiler), + native_qiskit_opt_lvls, + native_gatesets, + ), + ( + (mapped_qiskit_compiler, mapped_tket_compiler), + (mapped_qiskit_opt_lvls, mapped_tket_placements), + mapped_devices, + ), + ) + print("Overall Result: ", res) + return res def add_min_max_qubit_number(database): diff --git a/benchviewer/templates/index.html b/benchviewer/templates/index.html index 398390aff..e8e6f88f3 100644 --- a/benchviewer/templates/index.html +++ b/benchviewer/templates/index.html @@ -120,8 +120,9 @@

Benchmark Selection

- + Select all
@@ -131,11 +132,9 @@

Benchmark Selection

Scalable Benchmarks:
+ id="minQubits" name="minQubits" placeholder="Min Qubits (2)"> + id="maxQubits" name="maxQubits" placeholder="Max Qubits (130)">
{% for benchmark in benchmarks %} @@ -171,6 +170,19 @@
Non-Scalable Benchmarks:
+
+
+
Algorithm Level
+
+
+ Currently only available using the python package. For details can be found on our Github + page. + +
+
+
+
Independent Level Options
@@ -203,10 +215,10 @@
Target-dependent: Native-Gates Level Options
- - Target-dependent: Native-Gates Level Options
- + id="nativegates_tket_compiler" name="nativegates_tket_compiler"> +
@@ -250,20 +262,20 @@
Target-dependent: Mapped Level Options
- + id="mapped_qiskit_compiler" name="mapped_qiskit_compiler"> +
+ id="mapped_qiskit_compiler_opt0" name="mapped_qiskit_compiler_opt0"> - - -
@@ -276,10 +288,10 @@
Target-dependent: Mapped Level Options
+ id="mapped_tket_compiler_graph" name="mapped_tket_compiler_graph"> + id="mapped_tket_compiler_line" name="mapped_tket_compiler_line">
@@ -330,7 +342,6 @@
Target-dependent: Mapped Level Options
- From d00ec1fd5270f1ca4ffaf94e0ad366d9ce6bc24b Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 11 Aug 2022 11:23:00 +0200 Subject: [PATCH 033/231] =?UTF-8?q?=E2=9C=A8=20implemented=20new=20backend?= =?UTF-8?q?=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/main.py | 33 +--- benchviewer/src/backend.py | 281 +++++++++++++++---------------- benchviewer/templates/index.html | 56 +++--- 3 files changed, 163 insertions(+), 207 deletions(-) diff --git a/benchviewer/main.py b/benchviewer/main.py index b997357af..5a78758dd 100644 --- a/benchviewer/main.py +++ b/benchviewer/main.py @@ -61,14 +61,12 @@ def download_data(): prepared_data = prepareFormInput(data) print("raw data :", data) print("prepared input data :", prepared_data) - file_paths, algo_dicts, python_files_list = get_selected_file_paths( - prepared_data - ) + file_paths = get_selected_file_paths(prepared_data) timestamp = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") - if file_paths or python_files_list: + if file_paths: return app.response_class( - generate_zip_ephemeral_chunks(file_paths, python_files_list), + generate_zip_ephemeral_chunks(file_paths), mimetype="application/zip", headers={ "Content-Disposition": 'attachment; filename="MQTBench_{}.zip"'.format( @@ -110,32 +108,13 @@ def benchmark_description(): @app.route(f"{PREFIX}/get_num_benchmarks", methods=["POST"]) def get_num_benchmarks(): - return None + if request.method == "POST": data = request.form prepared_data = prepareFormInput(data) file_paths = get_selected_file_paths(prepared_data) - num = 0 - if file_paths[0]: - num += len(set(file_paths[0])) - - # Calculation of algo level benchmarks for non_scalable benchmarks - # check config.json for that - if file_paths[1]: - config_file_path = "../config.json" - with open(config_file_path, "r") as jsonfile: - cfg = json.load(jsonfile) - for dict in file_paths[1]: - if "max_qubits" in dict and "min_qubits" in dict: - num += int(dict["max_qubits"]) - int(dict["min_qubits"]) - else: - for benchmark_config in cfg["benchmarks"]: - if dict["name"] == benchmark_config["name"]: - res = get_num_algo_layer_benchmarks( - dict["name"], benchmark_config - ) - num += res - break + num = len(file_paths) + print("Num benchmarks: ", num) data = {"num_selected": num} return jsonify(data) else: diff --git a/benchviewer/src/backend.py b/benchviewer/src/backend.py index 01117368f..85c50b9c1 100644 --- a/benchviewer/src/backend.py +++ b/benchviewer/src/backend.py @@ -124,7 +124,7 @@ def createDatabase(zip_file: ZipFile): database -- database containing all available benchmarks """ rows_list = [] - # for filename in os.listdir(qasm_path): + for filename in zip_file.namelist(): if filename.endswith(".qasm"): parsed_data = parse_data(filename) @@ -134,20 +134,18 @@ def createDatabase(zip_file: ZipFile): colnames = [ "benchmark", "num_qubits", - "native_gate_set", - "algo_layer", - "indep_layer", - "nativegates_layer", - "mapped_layer", - "smallest_mapping", - "biggest_mapping", - "opt_level", + "indep_flag", + "nativegates_flag", + "mapped_flag", + "compiler", + "compiler_settings", + "gate_set", + "target_device", "path", ] database = pd.DataFrame(rows_list, columns=colnames) database["num_qubits"] = database["num_qubits"].astype(int) - database["opt_level"] = database["opt_level"].astype(int) database["benchmark"] = database["benchmark"].astype(str) return database @@ -162,6 +160,44 @@ def read_mqtbench_all_zip(): print("files: {}".format(len(MQTBENCH_ALL_ZIP.namelist()))) +def get_tket_settings(filename: str): + if "line" in filename: + return "line" + elif "graph" in filename: + return "graph" + + +def get_gate_set(filename: str): + if "oqc" in filename: + return "oqc" + elif "ionq" in filename: + return "ionq" + elif "ibm" in filename: + return "ibm" + elif "rigetti" in filename: + return "rigetti" + + +def get_target_device(filename: str): + if "ibm_washington" in filename: + return "ibm_washington" + elif "ibm_montreal" in filename: + return "ibm_montreal" + elif "rigetti_aspen_m1" in filename: + return "rigetti_aspen_m1" + elif "ionq11" in filename: + return "ionq11" + elif "oqc_lucy" in filename: + return "oqc_lucy" + + +def get_compiler_and_settings(filename: str): + if "qiskit" in filename: + return ("qiskit", get_opt_level(filename)) + elif "tket" in filename: + return ("tket", get_tket_settings(filename)) + + def parse_data(filename: str): """Extracts the necessary information from a given filename. @@ -173,34 +209,24 @@ def parse_data(filename: str): """ benchmark = filename.split("_")[0].lower() num_qubits = get_num_qubits(filename) - algorithm_flag = "algorithm" in filename indep_flag = "indep" in filename nativegates_flag = "nativegates" in filename mapped_flag = "mapped" in filename - smallest_mapping = False - biggest_mapping = False - opt_level = get_opt_level(filename) + compiler, compiler_settings = get_compiler_and_settings(filename) + gate_set = get_gate_set(filename) + target_device = get_target_device(filename) + path = os.path.join(filename) - gate_set = False - if "ibm" in filename: - gate_set = "ibm" - elif "rigetti" in filename: - gate_set = "rigetti" - if "ibm-s" in filename or "rigetti-s" in filename: - smallest_mapping = True - elif "ibm-b" in filename or "rigetti-b" in filename: - biggest_mapping = True parsed_data = [ benchmark, num_qubits, - gate_set, - algorithm_flag, indep_flag, nativegates_flag, mapped_flag, - smallest_mapping, - biggest_mapping, - opt_level, + compiler, + compiler_settings, + gate_set, + target_device, path, ] return parsed_data @@ -219,14 +245,13 @@ def filterDatabase(filterCriteria, database): colnames = [ "benchmark", "num_qubits", - "native_gate_set", - "algo_layer", - "indep_layer", - "nativegates_layer", - "mapped_layer", - "smallest_mapping", - "biggest_mapping", - "opt_level", + "indep_flag", + "nativegates_flag", + "mapped_flag", + "compiler", + "compiler_settings", + "gate_set", + "target_device", "path", ] db_filtered = pd.DataFrame(columns=colnames) @@ -249,110 +274,80 @@ def filterDatabase(filterCriteria, database): ), ) = filterCriteria - db_tmp = database.loc[ - (database["num_qubits"] >= min_qubits) - & (database["num_qubits"] <= max_qubits) - ] + for identifier in indices_benchmarks: + if int(identifier) > 0 and int(identifier) <= len(benchmarks): + name = benchmarks[int(identifier) - 1]["filename"] - if indep_qiskit_compiler: - #db_filtered = pd.concat([db_filtered, dbxyz]) - if indep_tket_compiler: - #db_filtered = pd.concat([db_filtered, dbxyz]) - - if nativegates_qiskit_compiler: - #consider - #native_qiskit_opt_lvls, - #native_gatesets, - - if nativegates_tket_compiler: - - # filter for benchmark name - db1 = database.loc[(database["benchmark"] == benchmark)] - - # filter for qubit range and stepsize (prob. set of relevant numbers and then filter) - if min_qubits != -1 and max_qubits != -1: - db2 = db1.loc[ + db_tmp = database.loc[ (database["num_qubits"] >= min_qubits) & (database["num_qubits"] <= max_qubits) + & (database["benchmark"] == name) ] + elif int(identifier) > 0 and int(identifier) <= len(benchmarks) + len( + nonscalable_benchmarks + ): + name = nonscalable_benchmarks[int(identifier) - 1 - len(benchmarks)][ + "filename" + ] + + db_tmp = database.loc[database["benchmark"] == name] else: - db2 = db1 - - if indep_flag: - db4 = db2.loc[(database["indep_layer"])] - # db4_tmp = db2.loc[(database["indep_layer"])] - # db4_total = pd.DataFrame(columns=colnames) - # for opt_level in opt_levels: - # db_tmp = db4_tmp.loc[(db4_tmp["opt_level"] == opt_level)] - # db4_total = pd.concat([db4_total, db_tmp]) - db_filtered = pd.concat([db_filtered, db4]) - # Native Gates - if nativegates_flag: - db5_tmp = db2.loc[(database["nativegates_layer"])] - db5_total = pd.DataFrame(columns=colnames) - for opt_level in opt_levels: - if gate_set_ibm: # IBM - db_tmp = db5_tmp.loc[ - (db5_tmp["native_gate_set"] == "ibm") - & ((db5_tmp["opt_level"] == opt_level)) + print("FAIL") + + if indep_qiskit_compiler: + db_tmp1 = db_tmp.loc[ + (db_tmp["indep_flag"] == True) & (db_tmp["compiler"] == "qiskit") + ] + db_filtered = pd.concat([db_filtered, db_tmp1]) + + if indep_tket_compiler: + db_tmp2 = db_tmp.loc[ + (db_tmp["indep_flag"] == True) & (db_tmp["compiler"] == "tket") + ] + db_filtered = pd.concat([db_filtered, db_tmp2]) + + if nativegates_qiskit_compiler: + for gate_set in native_gatesets: + for opt_lvl in native_qiskit_opt_lvls: + db_tmp3 = db_tmp.loc[ + (db_tmp["nativegates_flag"] == True) + & (db_tmp["gate_set"] == gate_set) + & (db_tmp["compiler"] == "qiskit") + & (db_tmp["compiler_settings"] == opt_lvl) ] - db5_total = pd.concat([db5_total, db_tmp]) - if gate_set_rigetti: # Rigetti - db_tmp = db5_tmp.loc[ - (db5_tmp["native_gate_set"] == "rigetti") - & ((db5_tmp["opt_level"] == opt_level)) + db_filtered = pd.concat([db_filtered, db_tmp3]) + + if nativegates_tket_compiler: + for gate_set in native_gatesets: + db_tmp4 = db_tmp.loc[ + (db_tmp["nativegates_flag"] == True) + & (db_tmp["gate_set"] == gate_set) + & (db_tmp["compiler"] == "tket") + ] + db_filtered = pd.concat([db_filtered, db_tmp4]) + + if mapped_qiskit_compiler: + for opt_lvl in native_qiskit_opt_lvls: + for device in mapped_devices: + db_tmp5 = db_tmp.loc[ + (db_tmp["mapped_flag"] == True) + & (db_tmp["target_device"] == device) + & (db_tmp["compiler"] == "qiskit") + & (db_tmp["compiler_settings"] == opt_lvl) ] - db5_total = pd.concat([db5_total, db_tmp]) - db_filtered = pd.concat([db_filtered, db5_total]) - # Mapped Layer - if mapped_flag: - - db6_total = pd.DataFrame(columns=colnames) - for opt_level in opt_levels: - if gate_set_ibm: # IBM - if smallest_mapping: - db6_tmp = db2.loc[ - (database["mapped_layer"]) - & (database["smallest_mapping"] == True) - ] - db_tmp = db6_tmp.loc[ - (db6_tmp["native_gate_set"] == "ibm") - & ((db6_tmp["opt_level"] == opt_level)) - ] - db6_total = pd.concat([db6_total, db_tmp]) - if biggest_mapping: - db6_tmp = db2.loc[ - (database["mapped_layer"]) - & (database["biggest_mapping"] == True) - ] - db_tmp = db6_tmp.loc[ - (db6_tmp["native_gate_set"] == "ibm") - & ((db6_tmp["opt_level"] == opt_level)) - ] - db6_total = pd.concat([db6_total, db_tmp]) - if gate_set_rigetti: # Rigetti - if smallest_mapping: - db6_tmp = db2.loc[ - (database["mapped_layer"]) - & (database["smallest_mapping"] == True) - ] - db_tmp = db6_tmp.loc[ - (db6_tmp["native_gate_set"] == "rigetti") - & ((db6_tmp["opt_level"] == opt_level)) - ] - db6_total = pd.concat([db6_total, db_tmp]) - if biggest_mapping: - db6_tmp = db2.loc[ - (database["mapped_layer"]) - & (database["biggest_mapping"] == True) - ] - db_tmp = db6_tmp.loc[ - (db6_tmp["native_gate_set"] == "rigetti") - & ((db6_tmp["opt_level"] == opt_level)) - ] - db6_total = pd.concat([db6_total, db_tmp]) - - db_filtered = pd.concat([db_filtered, db6_total]) + db_filtered = pd.concat([db_filtered, db_tmp5]) + + if mapped_tket_compiler: + for placement in mapped_tket_placements: + for device in mapped_devices: + db_tmp6 = db_tmp.loc[ + (db_tmp["mapped_flag"] == True) + & (db_tmp["target_device"] == device) + & (db_tmp["compiler"] == "tket") + & (db_tmp["compiler_settings"] == placement) + ] + db_filtered = pd.concat([db_filtered, db_tmp6]) + return db_filtered["path"].to_list() @@ -552,18 +547,18 @@ def prepareFormInput(formData): if "device_ionq_ionq11" in k: mapped_devices.append("ionq11") - print("benchmarks: ", num_benchmarks) - print("indep compiler: ", indep_qiskit_compiler, indep_tket_compiler) - print("native compiler: ", nativegates_qiskit_compiler, nativegates_tket_compiler) - print("native compiler settings qiskit: ", native_qiskit_opt_lvls) - print("native compiler gatesets: ", native_gatesets) - print("mapped compiler: ", mapped_qiskit_compiler, mapped_tket_compiler) - print("mapped compiler settings qiskit: ", mapped_qiskit_opt_lvls) - print("mapped compiler settings tket: ", mapped_tket_placements) - print("mapped devices: ", mapped_devices) + # print("benchmarks: ", num_benchmarks) + # print("indep compiler: ", indep_qiskit_compiler, indep_tket_compiler) + # print("native compiler: ", nativegates_qiskit_compiler, nativegates_tket_compiler) + # print("native compiler settings qiskit: ", native_qiskit_opt_lvls) + # print("native compiler gatesets: ", native_gatesets) + # print("mapped compiler: ", mapped_qiskit_compiler, mapped_tket_compiler) + # print("mapped compiler settings qiskit: ", mapped_qiskit_opt_lvls) + # print("mapped compiler settings tket: ", mapped_tket_placements) + # print("mapped devices: ", mapped_devices) res = ( - (min_qubits, max_qubits), + (int(min_qubits), int(max_qubits)), num_benchmarks, (indep_qiskit_compiler, indep_tket_compiler), ( diff --git a/benchviewer/templates/index.html b/benchviewer/templates/index.html index e8e6f88f3..cd8fe79ea 100644 --- a/benchviewer/templates/index.html +++ b/benchviewer/templates/index.html @@ -131,9 +131,9 @@

Benchmark Selection

Scalable Benchmarks:
- -
{% for benchmark in benchmarks %} @@ -190,14 +190,14 @@
Independent Level Options
+ id="indep_qiskit_compiler" name="indep_qiskit_compiler" value="true">
+ id="indep_tket_compiler" name="indep_tket_compiler" value="true">
@@ -211,7 +211,7 @@
Target-dependent: Native-Gates Level Options
+ id="nativegates_qiskit_compiler" name="nativegates_qiskit_compiler" value="true">
@@ -233,7 +233,7 @@
Target-dependent: Native-Gates Level Options
+ id="nativegates_tket_compiler" name="nativegates_tket_compiler value="true"">
@@ -376,16 +376,8 @@
Target-dependent: Mapped Level Options
} function toggleAllSelection() { - var ids = { - { - benchmarks | length - } - } - +{ - { - nonscalable_benchmarks | length - } - } + + var ids = {{benchmarks | length}}+{{nonscalable_benchmarks | length }} for (let i = 1; i <= ids; i++) { document.getElementById("selectBench_" + i).checked = all_benchmarks.checked } @@ -397,30 +389,20 @@
Target-dependent: Mapped Level Options
} function get_num_benchs() { - 0 - // form = document.getElementById("benchmark_form") - // const formData = new FormData(form); - // fetch('./get_num_benchmarks', { - // method: 'POST', - // body: formData, - // dataType: 'json', - // }).then(response => response.json()) - // .then(response => { - // document.getElementById("num_benchmarks").innerHTML = response.num_selected; - // }); + form = document.getElementById("benchmark_form") + const formData = new FormData(form); + fetch('./get_num_benchmarks', { + method: 'POST', + body: formData, + dataType: 'json', + }).then(response => response.json()) + .then(response => { + document.getElementById("num_benchmarks").innerHTML = response.num_selected; + }); } function check_col_if_all_selected() { - var ids = { - { - benchmarks | length - } - } - +{ - { - nonscalable_benchmarks | length - } - } + var ids = {{benchmarks | length}}+{{nonscalable_benchmarks | length }} var check_all_selected = true; for (let i = 1; i <= ids; i++) { if (!document.getElementById("selectBench_" + i).checked) { From d19b31b8a96429a713c7694c7907685f9d186221 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 11 Aug 2022 11:23:06 +0200 Subject: [PATCH 034/231] =?UTF-8?q?=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adjusted_database_parser.ipynb | 1290 +++++++++++--------------------- 1 file changed, 430 insertions(+), 860 deletions(-) diff --git a/adjusted_database_parser.ipynb b/adjusted_database_parser.ipynb index 6d456565f..749d32fdb 100644 --- a/adjusted_database_parser.ipynb +++ b/adjusted_database_parser.ipynb @@ -2,7 +2,78 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 204, + "id": "f334d4ee", + "metadata": {}, + "outputs": [], + "source": [ + "benchmarks = [\n", + " {\"name\": \"Amplitude Estimation (AE)\", \"id\": \"1\", \"filename\": \"ae\"},\n", + " {\"name\": \"Deutsch-Jozsa\", \"id\": \"2\", \"filename\": \"dj\"},\n", + " {\"name\": \"Graph State\", \"id\": \"3\", \"filename\": \"graphstate\"},\n", + " {\"name\": \"GHZ State\", \"id\": \"4\", \"filename\": \"ghz\"},\n", + " {\"name\": \"Grover's (no ancilla)\", \"id\": \"5\", \"filename\": \"grover-noancilla\"},\n", + " {\"name\": \"Grover's (v-chain)\", \"id\": \"6\", \"filename\": \"grover-v-chain\"},\n", + " {\n", + " \"name\": \"Portfolio Optimization with QAOA\",\n", + " \"id\": \"7\",\n", + " \"filename\": \"portfolioqaoa\",\n", + " },\n", + " {\"name\": \"Portfolio Optimization with VQE\", \"id\": \"8\", \"filename\": \"portfoliovqe\"},\n", + " {\n", + " \"name\": \"Quantum Approximation Optimization Algorithm (QAOA)\",\n", + " \"id\": \"9\",\n", + " \"filename\": \"qaoa\",\n", + " },\n", + " {\"name\": \"Quantum Fourier Transformation (QFT)\", \"id\": \"10\", \"filename\": \"qft\"},\n", + " {\"name\": \"QFT Entangled\", \"id\": \"11\", \"filename\": \"qftentangled\"},\n", + " {\"name\": \"Quantum Generative Adversarial Network\", \"id\": \"12\", \"filename\": \"qgan\"},\n", + " {\n", + " \"name\": \"Quantum Phase Estimation (QPE) exact\",\n", + " \"id\": \"13\",\n", + " \"filename\": \"qpeexact\",\n", + " },\n", + " {\n", + " \"name\": \"Quantum Phase Estimation (QPE) inexact\",\n", + " \"id\": \"14\",\n", + " \"filename\": \"qpeinexact\",\n", + " },\n", + " {\"name\": \"Quantum Walk (no ancilla)\", \"id\": \"15\", \"filename\": \"qwalk-noancilla\"},\n", + " {\"name\": \"Quantum Walk (v-chain)\", \"id\": \"16\", \"filename\": \"qwalk-v-chain\"},\n", + " {\"name\": \"Variational Quantum Eigensolver (VQE)\", \"id\": \"17\", \"filename\": \"vqe\"},\n", + " {\n", + " \"name\": \"Efficient SU2 ansatz with Random Parameters\",\n", + " \"id\": \"18\",\n", + " \"filename\": \"su2random\",\n", + " },\n", + " {\n", + " \"name\": \"Real Amplitudes ansatz with Random Parameters\",\n", + " \"id\": \"19\",\n", + " \"filename\": \"realamprandom\",\n", + " },\n", + " {\n", + " \"name\": \"Two Local ansatz with Random Parameters\",\n", + " \"id\": \"20\",\n", + " \"filename\": \"twolocalrandom\",\n", + " },\n", + " {\"name\": \"W-State\", \"id\": \"21\", \"filename\": \"wstate\"},\n", + "]\n", + "\n", + "nonscalable_benchmarks = [\n", + " {\"name\": \"Excited State\", \"id\": \"22\", \"filename\": \"excitedstate\"},\n", + " {\"name\": \"Ground State\", \"id\": \"23\", \"filename\": \"groundstate\"},\n", + " {\"name\": \"HHL\", \"id\": \"24\", \"filename\": \"hhl\"},\n", + " {\"name\": \"Pricing Call Option\", \"id\": \"25\", \"filename\": \"pricingcall\"},\n", + " {\"name\": \"Pricing Put Option\", \"id\": \"26\", \"filename\": \"pricingput\"},\n", + " {\"name\": \"Routing\", \"id\": \"27\", \"filename\": \"routing\"},\n", + " {\"name\": \"Shor's\", \"id\": \"28\", \"filename\": \"shor\"},\n", + " {\"name\": \"Travelling Salesman\", \"id\": \"29\", \"filename\": \"tsp\"},\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": 205, "id": "63cd9080", "metadata": {}, "outputs": [], @@ -28,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 206, "id": "92b83186", "metadata": {}, "outputs": [], @@ -54,7 +125,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 207, "id": "1d2ffaed", "metadata": {}, "outputs": [], @@ -73,8 +144,8 @@ " return \"ionq\"\n", " elif \"ibm\" in filename:\n", " return \"ibm\"\n", - " elif \"oqc\" in filename:\n", - " return \"oqc\"\n", + " elif \"rigetti\" in filename:\n", + " return \"rigetti\"\n", "\n", "\n", "def get_target_device(filename: str):\n", @@ -92,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 208, "id": "a8d83429", "metadata": {}, "outputs": [], @@ -106,7 +177,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 209, "id": "f133dfb1", "metadata": {}, "outputs": [], @@ -147,857 +218,17 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 213, "id": "7618ce2d", "metadata": {}, "outputs": [ { "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
benchmarknum_qubitsindep_flagnativegates_flagmapped_flagcompilercompiler_settingsgate_settarget_devicepath
0ae27FalseTrueFalseqiskit0ionqNone./benchviewer/static/files/qasm_output/ae_nati...
1graphstate24FalseTrueFalseqiskit3oqcNone./benchviewer/static/files/qasm_output/graphst...
2dj41FalseFalseTrueqiskit2ibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
3qft8TrueFalseFalsetketNoneNoneNone./benchviewer/static/files/qasm_output/qft_ind...
4graphstate19FalseTrueFalseqiskit1oqcNone./benchviewer/static/files/qasm_output/graphst...
5qaoa3FalseFalseTruetketlineoqcoqc_lucy./benchviewer/static/files/qasm_output/qaoa_ma...
6graphstate4FalseTrueFalseqiskit0ibmNone./benchviewer/static/files/qasm_output/graphst...
7qftentangled16FalseFalseTrueqiskit2Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/qftenta...
8qpeinexact25FalseTrueFalseqiskit2ibmNone./benchviewer/static/files/qasm_output/qpeinex...
9qpeinexact18FalseTrueFalseqiskit0ibmNone./benchviewer/static/files/qasm_output/qpeinex...
10dj112FalseFalseTrueqiskit2ibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
11qftentangled19FalseTrueFalsetketNoneionqNone./benchviewer/static/files/qasm_output/qftenta...
12qftentangled18FalseFalseTrueqiskit2ibmibm_washington./benchviewer/static/files/qasm_output/qftenta...
13qpeinexact7FalseFalseTrueqiskit1Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/qpeinex...
14qftentangled25FalseFalseTrueqiskit0ibmibm_washington./benchviewer/static/files/qasm_output/qftenta...
15qwalk-noancilla3FalseFalseTruetketgraphionqionq11./benchviewer/static/files/qasm_output/qwalk-n...
16dj30FalseTrueFalseqiskit1ibmNone./benchviewer/static/files/qasm_output/dj_nati...
17dj62FalseTrueFalseqiskit0oqcNone./benchviewer/static/files/qasm_output/dj_nati...
18pricingput5FalseFalseTruetketlineoqcoqc_lucy./benchviewer/static/files/qasm_output/pricing...
19qpeexact22FalseFalseTrueqiskit0ibmibm_montreal./benchviewer/static/files/qasm_output/qpeexac...
20qpeexact17FalseTrueFalseqiskit0NoneNone./benchviewer/static/files/qasm_output/qpeexac...
21ghz34FalseFalseTrueqiskit3Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/ghz_map...
22ae11FalseFalseTruetketgraphNonerigetti_aspen_m1./benchviewer/static/files/qasm_output/ae_mapp...
23realamprandom10FalseTrueFalseqiskit3oqcNone./benchviewer/static/files/qasm_output/realamp...
24qaoa17FalseFalseTrueqiskit2ibmibm_washington./benchviewer/static/files/qasm_output/qaoa_ma...
25qpeinexact15FalseFalseTrueqiskit0Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/qpeinex...
26dj42FalseTrueFalsetketNoneionqNone./benchviewer/static/files/qasm_output/dj_nati...
27qwalk-noancilla6FalseTrueFalseqiskit0NoneNone./benchviewer/static/files/qasm_output/qwalk-n...
28pricingcall5FalseFalseTrueqiskit0ionqionq11./benchviewer/static/files/qasm_output/pricing...
29ghz49FalseTrueFalsetketNoneionqNone./benchviewer/static/files/qasm_output/ghz_nat...
30dj56FalseTrueFalseqiskit0NoneNone./benchviewer/static/files/qasm_output/dj_nati...
31dj112FalseFalseTrueqiskit3ibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
32grover-noancilla2FalseFalseTrueqiskit0Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/grover-...
33ae17FalseFalseTrueqiskit2Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/ae_mapp...
34graphstate52FalseFalseTrueqiskit0ibmibm_washington./benchviewer/static/files/qasm_output/graphst...
35qftentangled10FalseTrueFalseqiskit0ionqNone./benchviewer/static/files/qasm_output/qftenta...
36realamprandom13FalseFalseTrueqiskit2Nonerigetti_aspen_m1./benchviewer/static/files/qasm_output/realamp...
37graphstate28TrueFalseFalsetketgraphNoneNone./benchviewer/static/files/qasm_output/graphst...
38qft31FalseTrueFalsetketNoneNoneNone./benchviewer/static/files/qasm_output/qft_nat...
39dj69FalseFalseTruetketgraphibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
40grover-noancilla8FalseTrueFalseqiskit0ionqNone./benchviewer/static/files/qasm_output/grover-...
41qft14FalseFalseTruetketgraphNonerigetti_aspen_m1./benchviewer/static/files/qasm_output/qft_map...
42ghz100TrueFalseFalseqiskit-1NoneNone./benchviewer/static/files/qasm_output/ghz_ind...
43dj72TrueFalseFalsetketNoneNoneNone./benchviewer/static/files/qasm_output/dj_inde...
44graphstate7FalseTrueFalsetketgraphibmNone./benchviewer/static/files/qasm_output/graphst...
45graphstate30TrueFalseFalseqiskit-1NoneNone./benchviewer/static/files/qasm_output/graphst...
46qaoa8FalseTrueFalseqiskit2ionqNone./benchviewer/static/files/qasm_output/qaoa_na...
47dj86FalseFalseTruetketgraphibmibm_washington./benchviewer/static/files/qasm_output/dj_mapp...
48graphstate44FalseTrueFalseqiskit1ionqNone./benchviewer/static/files/qasm_output/graphst...
49portfoliovqe8FalseFalseTruetketlineoqcoqc_lucy./benchviewer/static/files/qasm_output/portfol...
\n", - "
" - ], "text/plain": [ - " benchmark num_qubits indep_flag nativegates_flag mapped_flag \\\n", - "0 ae 27 False True False \n", - "1 graphstate 24 False True False \n", - "2 dj 41 False False True \n", - "3 qft 8 True False False \n", - "4 graphstate 19 False True False \n", - "5 qaoa 3 False False True \n", - "6 graphstate 4 False True False \n", - "7 qftentangled 16 False False True \n", - "8 qpeinexact 25 False True False \n", - "9 qpeinexact 18 False True False \n", - "10 dj 112 False False True \n", - "11 qftentangled 19 False True False \n", - "12 qftentangled 18 False False True \n", - "13 qpeinexact 7 False False True \n", - "14 qftentangled 25 False False True \n", - "15 qwalk-noancilla 3 False False True \n", - "16 dj 30 False True False \n", - "17 dj 62 False True False \n", - "18 pricingput 5 False False True \n", - "19 qpeexact 22 False False True \n", - "20 qpeexact 17 False True False \n", - "21 ghz 34 False False True \n", - "22 ae 11 False False True \n", - "23 realamprandom 10 False True False \n", - "24 qaoa 17 False False True \n", - "25 qpeinexact 15 False False True \n", - "26 dj 42 False True False \n", - "27 qwalk-noancilla 6 False True False \n", - "28 pricingcall 5 False False True \n", - "29 ghz 49 False True False \n", - "30 dj 56 False True False \n", - "31 dj 112 False False True \n", - "32 grover-noancilla 2 False False True \n", - "33 ae 17 False False True \n", - "34 graphstate 52 False False True \n", - "35 qftentangled 10 False True False \n", - "36 realamprandom 13 False False True \n", - "37 graphstate 28 True False False \n", - "38 qft 31 False True False \n", - "39 dj 69 False False True \n", - "40 grover-noancilla 8 False True False \n", - "41 qft 14 False False True \n", - "42 ghz 100 True False False \n", - "43 dj 72 True False False \n", - "44 graphstate 7 False True False \n", - "45 graphstate 30 True False False \n", - "46 qaoa 8 False True False \n", - "47 dj 86 False False True \n", - "48 graphstate 44 False True False \n", - "49 portfoliovqe 8 False False True \n", - "\n", - " compiler compiler_settings gate_set target_device \\\n", - "0 qiskit 0 ionq None \n", - "1 qiskit 3 oqc None \n", - "2 qiskit 2 ibm ibm_washington \n", - "3 tket None None None \n", - "4 qiskit 1 oqc None \n", - "5 tket line oqc oqc_lucy \n", - "6 qiskit 0 ibm None \n", - "7 qiskit 2 None rigetti_aspen_m1 \n", - "8 qiskit 2 ibm None \n", - "9 qiskit 0 ibm None \n", - "10 qiskit 2 ibm ibm_washington \n", - "11 tket None ionq None \n", - "12 qiskit 2 ibm ibm_washington \n", - "13 qiskit 1 None rigetti_aspen_m1 \n", - "14 qiskit 0 ibm ibm_washington \n", - "15 tket graph ionq ionq11 \n", - "16 qiskit 1 ibm None \n", - "17 qiskit 0 oqc None \n", - "18 tket line oqc oqc_lucy \n", - "19 qiskit 0 ibm ibm_montreal \n", - "20 qiskit 0 None None \n", - "21 qiskit 3 None rigetti_aspen_m1 \n", - "22 tket graph None rigetti_aspen_m1 \n", - "23 qiskit 3 oqc None \n", - "24 qiskit 2 ibm ibm_washington \n", - "25 qiskit 0 None rigetti_aspen_m1 \n", - "26 tket None ionq None \n", - "27 qiskit 0 None None \n", - "28 qiskit 0 ionq ionq11 \n", - "29 tket None ionq None \n", - "30 qiskit 0 None None \n", - "31 qiskit 3 ibm ibm_washington \n", - "32 qiskit 0 None rigetti_aspen_m1 \n", - "33 qiskit 2 None rigetti_aspen_m1 \n", - "34 qiskit 0 ibm ibm_washington \n", - "35 qiskit 0 ionq None \n", - "36 qiskit 2 None rigetti_aspen_m1 \n", - "37 tket graph None None \n", - "38 tket None None None \n", - "39 tket graph ibm ibm_washington \n", - "40 qiskit 0 ionq None \n", - "41 tket graph None rigetti_aspen_m1 \n", - "42 qiskit -1 None None \n", - "43 tket None None None \n", - "44 tket graph ibm None \n", - "45 qiskit -1 None None \n", - "46 qiskit 2 ionq None \n", - "47 tket graph ibm ibm_washington \n", - "48 qiskit 1 ionq None \n", - "49 tket line oqc oqc_lucy \n", - "\n", - " path \n", - "0 ./benchviewer/static/files/qasm_output/ae_nati... \n", - "1 ./benchviewer/static/files/qasm_output/graphst... \n", - "2 ./benchviewer/static/files/qasm_output/dj_mapp... \n", - "3 ./benchviewer/static/files/qasm_output/qft_ind... \n", - "4 ./benchviewer/static/files/qasm_output/graphst... \n", - "5 ./benchviewer/static/files/qasm_output/qaoa_ma... \n", - "6 ./benchviewer/static/files/qasm_output/graphst... \n", - "7 ./benchviewer/static/files/qasm_output/qftenta... \n", - "8 ./benchviewer/static/files/qasm_output/qpeinex... \n", - "9 ./benchviewer/static/files/qasm_output/qpeinex... \n", - "10 ./benchviewer/static/files/qasm_output/dj_mapp... \n", - "11 ./benchviewer/static/files/qasm_output/qftenta... \n", - "12 ./benchviewer/static/files/qasm_output/qftenta... \n", - "13 ./benchviewer/static/files/qasm_output/qpeinex... \n", - "14 ./benchviewer/static/files/qasm_output/qftenta... \n", - "15 ./benchviewer/static/files/qasm_output/qwalk-n... \n", - "16 ./benchviewer/static/files/qasm_output/dj_nati... \n", - "17 ./benchviewer/static/files/qasm_output/dj_nati... \n", - "18 ./benchviewer/static/files/qasm_output/pricing... \n", - "19 ./benchviewer/static/files/qasm_output/qpeexac... \n", - "20 ./benchviewer/static/files/qasm_output/qpeexac... \n", - "21 ./benchviewer/static/files/qasm_output/ghz_map... \n", - "22 ./benchviewer/static/files/qasm_output/ae_mapp... \n", - "23 ./benchviewer/static/files/qasm_output/realamp... \n", - "24 ./benchviewer/static/files/qasm_output/qaoa_ma... \n", - "25 ./benchviewer/static/files/qasm_output/qpeinex... \n", - "26 ./benchviewer/static/files/qasm_output/dj_nati... \n", - "27 ./benchviewer/static/files/qasm_output/qwalk-n... \n", - "28 ./benchviewer/static/files/qasm_output/pricing... \n", - "29 ./benchviewer/static/files/qasm_output/ghz_nat... \n", - "30 ./benchviewer/static/files/qasm_output/dj_nati... \n", - "31 ./benchviewer/static/files/qasm_output/dj_mapp... \n", - "32 ./benchviewer/static/files/qasm_output/grover-... \n", - "33 ./benchviewer/static/files/qasm_output/ae_mapp... \n", - "34 ./benchviewer/static/files/qasm_output/graphst... \n", - "35 ./benchviewer/static/files/qasm_output/qftenta... \n", - "36 ./benchviewer/static/files/qasm_output/realamp... \n", - "37 ./benchviewer/static/files/qasm_output/graphst... \n", - "38 ./benchviewer/static/files/qasm_output/qft_nat... \n", - "39 ./benchviewer/static/files/qasm_output/dj_mapp... \n", - "40 ./benchviewer/static/files/qasm_output/grover-... \n", - "41 ./benchviewer/static/files/qasm_output/qft_map... \n", - "42 ./benchviewer/static/files/qasm_output/ghz_ind... \n", - "43 ./benchviewer/static/files/qasm_output/dj_inde... \n", - "44 ./benchviewer/static/files/qasm_output/graphst... \n", - "45 ./benchviewer/static/files/qasm_output/graphst... \n", - "46 ./benchviewer/static/files/qasm_output/qaoa_na... \n", - "47 ./benchviewer/static/files/qasm_output/dj_mapp... \n", - "48 ./benchviewer/static/files/qasm_output/graphst... \n", - "49 ./benchviewer/static/files/qasm_output/portfol... " + "(36044, 10)" ] }, - "execution_count": 22, + "execution_count": 213, "metadata": {}, "output_type": "execute_result" } @@ -1010,14 +241,14 @@ "\n", "rows_list = []\n", "# for filename in os.listdir(qasm_path):\n", - "directory = utils.get_qasm_output_path()\n", - "i = 0\n", + "directory = (\n", + " \"/Users/nils/Desktop/qasm_output/qasm_output\" # utils.get_qasm_output_path()\n", + ")\n", + "\n", "for f in os.listdir(directory):\n", - " i += 1\n", " parsed_data = parse_data(os.path.join(directory, f))\n", " rows_list.append(parsed_data)\n", - " if i > 50:\n", - " break\n", + "\n", "\n", "colnames = [\n", " \"benchmark\",\n", @@ -1036,30 +267,369 @@ "database[\"num_qubits\"] = database[\"num_qubits\"].astype(int)\n", "database[\"benchmark\"] = database[\"benchmark\"].astype(str)\n", "\n", - "database.head(50)" + "database.shape" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 214, "id": "d1773aa8", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[False, True]\n" + ] + } + ], + "source": [ + "print(list(database.indep_flag.unique()))" + ] + }, + { + "cell_type": "code", + "execution_count": 215, + "id": "fb0d3b37", + "metadata": {}, + "outputs": [], + "source": [ + "def filterDatabase(filterCriteria, database):\n", + " colnames = [\n", + " \"benchmark\",\n", + " \"num_qubits\",\n", + " \"indep_flag\",\n", + " \"nativegates_flag\",\n", + " \"mapped_flag\",\n", + " \"compiler\",\n", + " \"compiler_settings\",\n", + " \"gate_set\",\n", + " \"target_device\",\n", + " \"path\",\n", + " ]\n", + " db_filtered = pd.DataFrame(columns=colnames)\n", + " if len(database) == 0:\n", + " return []\n", + "\n", + " (\n", + " (min_qubits, max_qubits),\n", + " indices_benchmarks,\n", + " (indep_qiskit_compiler, indep_tket_compiler),\n", + " (\n", + " (nativegates_qiskit_compiler, nativegates_tket_compiler),\n", + " native_qiskit_opt_lvls,\n", + " native_gatesets,\n", + " ),\n", + " (\n", + " (mapped_qiskit_compiler, mapped_tket_compiler),\n", + " (mapped_qiskit_opt_lvls, mapped_tket_placements),\n", + " mapped_devices,\n", + " ),\n", + " ) = filterCriteria\n", + "\n", + " for identifier in indices_benchmarks:\n", + " if int(identifier) > 0 and int(identifier) <= len(benchmarks):\n", + " name = benchmarks[int(identifier) - 1][\"filename\"]\n", + "\n", + " db_tmp = database.loc[\n", + " (database[\"num_qubits\"] >= min_qubits)\n", + " & (database[\"num_qubits\"] <= max_qubits)\n", + " & (database[\"benchmark\"] == name)\n", + " ]\n", + " elif int(identifier) > 0 and int(identifier) <= len(benchmarks) + len(\n", + " nonscalable_benchmarks\n", + " ):\n", + " name = nonscalable_benchmarks[int(identifier) - 1 - len(benchmarks)][\n", + " \"filename\"\n", + " ]\n", + " db_tmp = database.loc[database[\"benchmark\"] == name]\n", + " else:\n", + " print(\"FAIL\")\n", + "\n", + " print(name, \":\", len(db_tmp))\n", + "\n", + " if indep_qiskit_compiler:\n", + " db_tmp1 = db_tmp.loc[\n", + " (db_tmp[\"indep_flag\"] == True) & (db_tmp[\"compiler\"] == \"qiskit\")\n", + " ]\n", + " db_filtered = pd.concat([db_filtered, db_tmp1])\n", + "\n", + " if indep_tket_compiler:\n", + " db_tmp2 = db_tmp.loc[\n", + " (db_tmp[\"indep_flag\"] == True) & (db_tmp[\"compiler\"] == \"tket\")\n", + " ]\n", + " db_filtered = pd.concat([db_filtered, db_tmp2])\n", + "\n", + " if nativegates_qiskit_compiler:\n", + " for gate_set in native_gatesets:\n", + " for opt_lvl in native_qiskit_opt_lvls:\n", + " db_tmp3 = db_tmp.loc[\n", + " (db_tmp[\"nativegates_flag\"] == True)\n", + " & (db_tmp[\"gate_set\"] == gate_set)\n", + " & (db_tmp[\"compiler\"] == \"qiskit\")\n", + " & (db_tmp[\"compiler_settings\"] == opt_lvl)\n", + " ]\n", + " db_filtered = pd.concat([db_filtered, db_tmp3])\n", + "\n", + " if nativegates_tket_compiler:\n", + " for gate_set in native_gatesets:\n", + " db_tmp4 = db_tmp.loc[\n", + " (db_tmp[\"nativegates_flag\"] == True)\n", + " & (db_tmp[\"gate_set\"] == gate_set)\n", + " & (db_tmp[\"compiler\"] == \"tket\")\n", + " ]\n", + " db_filtered = pd.concat([db_filtered, db_tmp4])\n", + "\n", + " if mapped_qiskit_compiler:\n", + " for opt_lvl in native_qiskit_opt_lvls:\n", + " for device in mapped_devices:\n", + " db_tmp5 = db_tmp.loc[\n", + " (db_tmp[\"mapped_flag\"] == True)\n", + " & (db_tmp[\"target_device\"] == device)\n", + " & (db_tmp[\"compiler\"] == \"qiskit\")\n", + " & (db_tmp[\"compiler_settings\"] == opt_lvl)\n", + " ]\n", + " db_filtered = pd.concat([db_filtered, db_tmp5])\n", + "\n", + " if mapped_tket_compiler:\n", + " for placement in mapped_tket_placements:\n", + " for device in mapped_devices:\n", + " db_tmp6 = db_tmp.loc[\n", + " (db_tmp[\"mapped_flag\"] == True)\n", + " & (db_tmp[\"target_device\"] == device)\n", + " & (db_tmp[\"compiler\"] == \"tket\")\n", + " & (db_tmp[\"compiler_settings\"] == placement)\n", + " ]\n", + " db_filtered = pd.concat([db_filtered, db_tmp6])\n", + "\n", + " return db_filtered[\"path\"].to_list()" + ] + }, + { + "cell_type": "code", + "execution_count": 196, + "id": "eb8b9026", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ae : 2035\n", + "dj : 4188\n", + "graphstate : 3971\n", + "ghz : 4270\n", + "grover-noancilla : 310\n", + "grover-v-chain : 0\n", + "portfolioqaoa : 352\n", + "portfoliovqe : 442\n", + "qaoa : 750\n", + "qft : 2060\n", + "qftentangled : 2009\n", + "qgan : 104\n", + "qpeexact : 2031\n", + "qpeinexact : 2029\n", + "qwalk-noancilla : 262\n", + "qwalk-v-chain : 0\n", + "vqe : 559\n", + "su2random : 1824\n", + "realamprandom : 1829\n", + "twolocalrandom : 1824\n", + "wstate : 4270\n", + "excitedstate : 0\n", + "groundstate : 0\n", + "hhl : 78\n", + "pricingcall : 343\n", + "pricingput : 341\n", + "routing : 103\n", + "shor : 8\n", + "tsp : 52\n" + ] + } + ], + "source": [ + "criteria = (\n", + " (1, 130),\n", + " [\n", + " \"1\",\n", + " \"2\",\n", + " \"3\",\n", + " \"4\",\n", + " \"5\",\n", + " \"6\",\n", + " \"7\",\n", + " \"8\",\n", + " \"9\",\n", + " \"10\",\n", + " \"11\",\n", + " \"12\",\n", + " \"13\",\n", + " \"14\",\n", + " \"15\",\n", + " \"16\",\n", + " \"17\",\n", + " \"18\",\n", + " \"19\",\n", + " \"20\",\n", + " \"21\",\n", + " \"22\",\n", + " \"23\",\n", + " \"24\",\n", + " \"25\",\n", + " \"26\",\n", + " \"27\",\n", + " \"28\",\n", + " \"29\",\n", + " ],\n", + " (True, True),\n", + " ((True, True), [0, 1, 2, 3], [\"oqc\", \"ionq\", \"ibm\", \"rigetti\"]),\n", + " (\n", + " (True, True),\n", + " ([0, 1, 2, 3], [\"graph\", \"line\"]),\n", + " [\"ibm_washington\", \"rigetti_aspen_m1\", \"ionq11\", \"ibm_montreal\", \"oqc_lucy\"],\n", + " ),\n", + ")\n", + "paths = filterDatabase(criteria, database)" + ] + }, + { + "cell_type": "code", + "execution_count": 197, + "id": "4bc63027", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "11" + "36044" ] }, - "execution_count": 21, + "execution_count": 197, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "len(database)" + "len(paths)" ] }, + { + "cell_type": "code", + "execution_count": 198, + "id": "9ce284a5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(17281, 10) (4038, 10) (21319, 10)\n" + ] + } + ], + "source": [ + "print(\n", + " database.loc[\n", + " (database[\"nativegates_flag\"] == True) & (database[\"compiler\"] == \"qiskit\")\n", + " ].shape,\n", + " database.loc[\n", + " (database[\"nativegates_flag\"] == True) & (database[\"compiler\"] == \"tket\")\n", + " ].shape,\n", + " database.loc[(database[\"nativegates_flag\"] == True)].shape,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 199, + "id": "eeec38f4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "17281\n" + ] + } + ], + "source": [ + "native_gatesets = [\"oqc\", \"ionq\", \"ibm\", \"rigetti\"]\n", + "native_qiskit_opt_lvls = [0, 1, 2, 3]\n", + "tmp = 0\n", + "for gate_set in native_gatesets:\n", + " for opt_lvl in native_qiskit_opt_lvls:\n", + " db_tmp3 = database.loc[\n", + " (database[\"nativegates_flag\"] == True)\n", + " & (database[\"gate_set\"] == gate_set)\n", + " & (database[\"compiler\"] == \"qiskit\")\n", + " & (database[\"compiler_settings\"] == opt_lvl)\n", + " ]\n", + " tmp += db_tmp3.shape[0]\n", + "print(tmp)" + ] + }, + { + "cell_type": "code", + "execution_count": 200, + "id": "a460063a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4038\n" + ] + } + ], + "source": [ + "native_gatesets = [\"oqc\", \"ionq\", \"ibm\", \"rigetti\"]\n", + "tmp = 0\n", + "for gate_set in native_gatesets:\n", + " db_tmp3 = database.loc[\n", + " (database[\"nativegates_flag\"] == True)\n", + " & (database[\"gate_set\"] == gate_set)\n", + " & (database[\"compiler\"] == \"tket\")\n", + " ]\n", + " tmp += db_tmp3.shape[0]\n", + "print(tmp)" + ] + }, + { + "cell_type": "code", + "execution_count": 201, + "id": "e9cdb06a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['ionq', 'oqc', 'rigetti', 'ibm'], dtype=object)" + ] + }, + "execution_count": 201, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "database.loc[\n", + " (database[\"nativegates_flag\"] == True) & (database[\"compiler\"] == \"tket\")\n", + "].gate_set.unique()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4bf28f41", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": 56, From 85ca0ba7a2ce336a7c4e30c69a5f587d35bed285 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 11 Aug 2022 14:18:54 +0200 Subject: [PATCH 035/231] =?UTF-8?q?=F0=9F=90=9B=20bugfix=20for=20num=20ben?= =?UTF-8?q?chmarks=20calculation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/src/backend.py | 5 +++-- benchviewer/templates/index.html | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/benchviewer/src/backend.py b/benchviewer/src/backend.py index 85c50b9c1..3ab74f639 100644 --- a/benchviewer/src/backend.py +++ b/benchviewer/src/backend.py @@ -309,6 +309,7 @@ def filterDatabase(filterCriteria, database): if nativegates_qiskit_compiler: for gate_set in native_gatesets: for opt_lvl in native_qiskit_opt_lvls: + print(opt_lvl) db_tmp3 = db_tmp.loc[ (db_tmp["nativegates_flag"] == True) & (db_tmp["gate_set"] == gate_set) @@ -327,7 +328,7 @@ def filterDatabase(filterCriteria, database): db_filtered = pd.concat([db_filtered, db_tmp4]) if mapped_qiskit_compiler: - for opt_lvl in native_qiskit_opt_lvls: + for opt_lvl in mapped_qiskit_opt_lvls: for device in mapped_devices: db_tmp5 = db_tmp.loc[ (db_tmp["mapped_flag"] == True) @@ -572,7 +573,7 @@ def prepareFormInput(formData): mapped_devices, ), ) - print("Overall Result: ", res) + #print("Overall Result: ", res) return res diff --git a/benchviewer/templates/index.html b/benchviewer/templates/index.html index cd8fe79ea..1eef2afc7 100644 --- a/benchviewer/templates/index.html +++ b/benchviewer/templates/index.html @@ -321,7 +321,7 @@
Target-dependent: Mapped Level Options
# of selected benchmarks:
0
- @@ -386,6 +386,8 @@
Target-dependent: Mapped Level Options
function checks_on_change() { check_col_if_all_selected() get_num_benchs() + + } function get_num_benchs() { @@ -398,7 +400,15 @@
Target-dependent: Mapped Level Options
}).then(response => response.json()) .then(response => { document.getElementById("num_benchmarks").innerHTML = response.num_selected; + + if (num_benchmarks.innerHTML > 0) { + downloadButton.disabled = false; + } + if (num_benchmarks.innerHTML == 0) { + downloadButton.disabled = true; + } }); + } function check_col_if_all_selected() { @@ -415,13 +425,6 @@
Target-dependent: Mapped Level Options
} } - $("form").keypress(function (e) { - if (e.keyCode == 13) { - e.preventDefault(); - return false; - } - }) - From b263e570664f4166a8b13534251a9734edd057fa Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 11 Aug 2022 14:34:41 +0200 Subject: [PATCH 036/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/config.json b/config.json index 237334b5e..a5d1392b3 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,5 @@ { -"timeout": 10, -"save_png": false, -"save_hist": false, +"timeout": 300, "benchmarks": [ { "name": "ae", @@ -45,7 +43,7 @@ "name": "grover", "include": true, "min_qubits": 2, - "max_qubits": 23, + "max_qubits": 130, "stepsize": 1, "ancillary_mode": ["noancilla", "v-chain"] }, @@ -53,39 +51,39 @@ "name": "hhl", "include": true, "min_index": 1, - "max_index": 4 + "max_index": 10 }, { "name": "portfolioqaoa", "include": true, "min_qubits": 3, - "max_qubits": 19, + "max_qubits": 130, "stepsize": 1 }, { "name": "portfoliovqe", "include": true, "min_qubits": 3, - "max_qubits": 19, + "max_qubits": 130, "stepsize": 1 }, { "name": "pricingcall", "include": true, "min_uncertainty": 2, - "max_uncertainty": 14 + "max_uncertainty": 130 }, { "name": "pricingput", "include": true, "min_uncertainty": 2, - "max_uncertainty": 14 + "max_uncertainty": 130 }, { "name": "qaoa", "include": true , "min_qubits": 3, - "max_qubits": 24, + "max_qubits": 130, "stepsize": 1 }, { @@ -106,7 +104,7 @@ "name": "qgan", "include": true, "min_qubits": 2, - "max_qubits": 14, + "max_qubits": 130, "stepsize": 1 }, { @@ -127,7 +125,7 @@ "name": "qwalk", "include": true, "min_qubits": 3, - "max_qubits": 95, + "max_qubits": 130, "stepsize": 1, "ancillary_mode": ["noancilla", "v-chain"] }, @@ -142,7 +140,7 @@ "name": "routing", "include": true, "min_nodes": 2, - "max_nodes": 4 + "max_nodes": 130 }, { "name": "shor", @@ -160,7 +158,7 @@ "name": "tsp", "include": true, "min_nodes": 2, - "max_nodes": 4 + "max_nodes": 10 }, { "name": "twolocalrandom", @@ -173,7 +171,7 @@ "name": "vqe", "include": true, "min_qubits": 3, - "max_qubits": 21, + "max_qubits": 130, "stepsize": 1 }, { From dd27b162ed5108dc9a8de56b9a353dd3993f5244 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 11 Aug 2022 14:34:48 +0200 Subject: [PATCH 037/231] =?UTF-8?q?=E2=9C=A8=20removed=20printouts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/qiskit_helper.py | 26 +++++++++++------------ mqt/bench/utils/tket_helper.py | 36 ++++++++++++++++---------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/mqt/bench/utils/qiskit_helper.py b/mqt/bench/utils/qiskit_helper.py index 82460a441..e1eb73fa9 100644 --- a/mqt/bench/utils/qiskit_helper.py +++ b/mqt/bench/utils/qiskit_helper.py @@ -60,7 +60,7 @@ def get_indep_level( qasm_output_folder = utils.get_qasm_output_path() filepath = qasm_output_folder + filename_indep + ".qasm" if not (path.isfile(filepath) and file_precheck): - print(filepath + " does not already exists and is newly created") + # print(filepath + " does not already exists and is newly created") openqasm_gates = utils.get_openqasm_gates() target_independent = transpile( qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 @@ -108,12 +108,12 @@ def get_native_gates_level( path.isfile(qasm_output_folder + filename_nativegates + ".qasm") and file_precheck ): - print( - qasm_output_folder - + filename_nativegates - + ".qasm" - + " does not already exists and is newly created" - ) + # print( + # qasm_output_folder + # + filename_nativegates + # + ".qasm" + # + " does not already exists and is newly created" + # ) compiled_without_architecture = transpile( qc, basis_gates=gate_set, optimization_level=opt_level, seed_transpiler=10 ) @@ -183,12 +183,12 @@ def get_mapped_level( if not ( path.isfile(qasm_output_folder + filename_mapped + ".qasm") and file_precheck ): - print( - qasm_output_folder - + filename_mapped - + ".qasm" - + " does not already exists and is newly created" - ) + # print( + # qasm_output_folder + # + filename_mapped + # + ".qasm" + # + " does not already exists and is newly created" + # ) compiled_with_architecture = transpile( qc, optimization_level=opt_level, diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index ac789174e..bca236893 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -82,12 +82,12 @@ def get_indep_level( if not ( path.isfile(qasm_output_folder + filename_native + ".qasm") and file_precheck ): - print( - qasm_output_folder - + filename_native - + ".qasm" - + " does not already exists and is newly created" - ) + # print( + # qasm_output_folder + # + filename_native + # + ".qasm" + # + " does not already exists and is newly created" + # ) openqasm_gates = utils.get_openqasm_gates() target_independent_qiskit = transpile( qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 @@ -119,12 +119,12 @@ def get_native_gates_level( if not ( path.isfile(qasm_output_folder + filename_native + ".qasm") and file_precheck ): - print( - qasm_output_folder - + filename_native - + ".qasm" - + " does not already exists and is newly created" - ) + # print( + # qasm_output_folder + # + filename_native + # + ".qasm" + # + " does not already exists and is newly created" + # ) openqasm_gates = utils.get_openqasm_gates() target_independent_qiskit = transpile( qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 @@ -171,12 +171,12 @@ def get_mapped_level( path.isfile(qasm_output_folder + filename_mapped + ".qasm") and file_precheck ): cmap = utils.get_cmap_from_devicename(device) - print( - qasm_output_folder - + filename_mapped - + ".qasm" - + " does not already exists and is newly created" - ) + # print( + # qasm_output_folder + # + filename_mapped + # + ".qasm" + # + " does not already exists and is newly created" + # ) openqasm_gates = utils.get_openqasm_gates() target_independent_qiskit = transpile( qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 From b15036cf2c660760e12c0080c25ca15fa4a871ec Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 11 Aug 2022 14:35:13 +0200 Subject: [PATCH 038/231] =?UTF-8?q?=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/src/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchviewer/src/backend.py b/benchviewer/src/backend.py index 3ab74f639..5696243d5 100644 --- a/benchviewer/src/backend.py +++ b/benchviewer/src/backend.py @@ -573,7 +573,7 @@ def prepareFormInput(formData): mapped_devices, ), ) - #print("Overall Result: ", res) + # print("Overall Result: ", res) return res From de1b8fd2c89e8afad408735db1b1c13142bdfb2a Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Fri, 12 Aug 2022 07:07:30 +0200 Subject: [PATCH 039/231] =?UTF-8?q?=E2=9C=A8=20removed=20exception=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index cc9f5e8f5..26f6353bb 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -91,14 +91,6 @@ def timeout_handler(signum, frame): # Custom signal handler signal.alarm(timeout) try: res = func(*args) - except TimeoutException: - print( - "Calculation/Generation exceeded timeout limit for ", - func, - args[0].name, - args[1:], - ) - return False except Exception as e: # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) print("Exception: ", e, func, args[0].name, args[1:]) From 7d18d34717827afb92875bcc13662426472b4f8f Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Fri, 12 Aug 2022 10:53:46 +0200 Subject: [PATCH 040/231] =?UTF-8?q?=E2=9C=A8=20removed=20algo=20level=20ha?= =?UTF-8?q?ndling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/main.py | 17 ----------------- benchviewer/src/backend.py | 11 ++++------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/benchviewer/main.py b/benchviewer/main.py index 5a78758dd..e5b930622 100644 --- a/benchviewer/main.py +++ b/benchviewer/main.py @@ -123,23 +123,6 @@ def get_num_benchmarks(): return jsonify(data) -def get_num_algo_layer_benchmarks(benchmark_name, config_entry): - if ( - benchmark_name == "groundstate" - or benchmark_name == "excitedstate" - or benchmark_name == "shor" - ): - return len(config_entry["instances"]) - elif benchmark_name == "routing" or benchmark_name == "tsp": - return config_entry["max_nodes"] - config_entry["min_nodes"] - elif benchmark_name == "pricingcall" or benchmark_name == "pricingput": - return config_entry["max_uncertainty"] - config_entry["min_uncertainty"] - elif benchmark_name == "hhl": - return config_entry["max_index"] - config_entry["min_index"] - else: - return False - - def main(): app.run(debug=True) diff --git a/benchviewer/src/backend.py b/benchviewer/src/backend.py index 5696243d5..5e8e192a7 100644 --- a/benchviewer/src/backend.py +++ b/benchviewer/src/backend.py @@ -391,13 +391,12 @@ def flush(self): def generate_zip_ephemeral_chunks( - filenames: List[str], python_files_list: bool = False + filenames: List[str], ) -> Iterable[bytes]: """Generates the zip file for the selected benchmarks and returns a generator of the chunks. Keyword arguments: paths -- list of file paths for all selected benchmarks - python_files_list -- list of all python files necessary to generate the benchmarks on the algorithm level Return values: Generator of bytes to send to the browser @@ -406,8 +405,8 @@ def generate_zip_ephemeral_chunks( fileobj = NoSeekBytesIO(io.BytesIO()) paths: List[Path] = [Path(name) for name in filenames] - if python_files_list: - paths.append(Path("./static/files/algo_level.txt")) + # if python_files_list: + # paths.append(Path("./static/files/algo_level.txt")) with ZipFile(fileobj, mode="w") as zf: for individualFile in paths: @@ -439,9 +438,7 @@ def get_selected_file_paths(prepared_data): prepared_data -- user's filter criteria after preparation step Return values: - filter_list -- list of filter criteria for each selected benchmark - algo_dicts -- dictionary to handle the algorithm level, since that one is not available as a downloadable file - python_files_list -- list of all python files needed to generated the algorithm level + file_paths -- list of filter criteria for each selected benchmark """ if prepared_data: From fed23e7ad8e993a785ac0dd0aae2cb2fe8a5367a Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Fri, 12 Aug 2022 12:35:27 +0200 Subject: [PATCH 041/231] =?UTF-8?q?=E2=9C=A8=20adapted=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/src/tests/test_backend.py | 614 ++++++++------------------ 1 file changed, 178 insertions(+), 436 deletions(-) diff --git a/benchviewer/src/tests/test_backend.py b/benchviewer/src/tests/test_backend.py index bbeca99eb..1032ef8c0 100644 --- a/benchviewer/src/tests/test_backend.py +++ b/benchviewer/src/tests/test_backend.py @@ -9,10 +9,10 @@ @pytest.mark.parametrize( "filename, expected_res", [ - ("shor_15_4_nativegates_rigetti_opt0_18.qasm", 0), - ("dj_mapped_ibm-s_opt3_103.qasm", 3), - ("graphstate_nativegates_ibm_opt2_15.qasm", 2), - ("grover-noancilla_nativegates_ibm_opt1_8.qasm", 1), + ("shor_15_4_nativegates_rigetti_qiskit_opt0_18.qasm", 0), + ("dj_mapped_ibm_washington_qiskit_opt3_103.qasm", 3), + ("graphstate_nativegates_ibm_qiskit_opt2_15.qasm", 2), + ("grover-noancilla_nativegates_ibm_qiskit_opt1_8.qasm", 1), ("HHL_indep_5.qasm", -1), ], ) @@ -23,11 +23,11 @@ def test_get_opt_level(filename, expected_res): @pytest.mark.parametrize( "filename, expected_res", [ - ("shor_15_4_nativegates_rigetti_opt0_18.qasm", 18), - ("dj_mapped_ibm-s_opt3_103.qasm", 103), - ("graphstate_nativegates_ibm_opt2_15.qasm", 15), - ("grover-noancilla_nativegates_ibm_opt1_8.qasm", 8), - ("HHL_indep_a.qasm", -1), + ("shor_15_4_nativegates_rigetti_qiskit_opt0_18.qasm", 18), + ("dj_mapped_ibm_washington_qiskit_opt3_103.qasm", 103), + ("graphstate_nativegates_ibm_qiskit_opt2_15.qasm", 15), + ("grover-noancilla_nativegates_ibm_qiskit_opt1_8.qasm", 8), + ("HHL_indep_5.qasm", 5), ], ) def test_get_num_qubits(filename, expected_res): @@ -38,83 +38,78 @@ def test_get_num_qubits(filename, expected_res): "filename, expected_res", [ ( - "shor_15_4_nativegates_rigetti_opt0_18.qasm", + "shor_15_4_nativegates_rigetti_qiskit_opt0_18.qasm", [ "shor", 18, - "rigetti", - False, False, True, False, - False, - False, + "qiskit", 0, - "shor_15_4_nativegates_rigetti_opt0_18.qasm", + "rigetti", + None, + "shor_15_4_nativegates_rigetti_qiskit_opt0_18.qasm", ], ), ( - "dj_mapped_ibm-s_opt3_103.qasm", + "dj_mapped_ibm_washington_qiskit_opt3_103.qasm", [ "dj", 103, - "ibm", - False, False, False, True, - True, - False, + "qiskit", 3, - "dj_mapped_ibm-s_opt3_103.qasm", + "ibm", + "ibm_washington", + "dj_mapped_ibm_washington_qiskit_opt3_103.qasm", ], ), ( - "dj_mapped_ibm-b_opt3_103.qasm", + "pricingcall_mapped_oqc_lucy_tket_line_5.qasm", [ - "dj", - 103, - "ibm", - False, - False, + "pricingcall", + 5, False, - True, False, True, - 3, - "dj_mapped_ibm-b_opt3_103.qasm", + "tket", + "line", + "oqc", + "oqc_lucy", + "pricingcall_mapped_oqc_lucy_tket_line_5.qasm", ], ), ( - "grover-noancilla_nativegates_ibm_opt3_8.qasm", + "portfoliovqe_nativegates_ionq_qiskit_opt1_3.qasm", [ - "grover-noancilla", - 8, - "ibm", - False, + "portfoliovqe", + 3, False, True, False, - False, - False, - 3, - "grover-noancilla_nativegates_ibm_opt3_8.qasm", + "qiskit", + 1, + "ionq", + None, + "portfoliovqe_nativegates_ionq_qiskit_opt1_3.qasm", ], ), ( - "HHL_indep_5.qasm", + "HHL_indep_qiskit_5.qasm", [ "hhl", 5, - False, - False, True, False, False, - False, - False, + "qiskit", -1, - "HHL_indep_5.qasm", + None, + None, + "HHL_indep_qiskit_5.qasm", ], ), ], @@ -126,270 +121,116 @@ def test_parse_data(filename, expected_res): def test_prepareFormInput(): form_data = dict( [ - ("selectBench_4", "GHZ State"), - ("minQubits_4", "5"), - ("maxQubits_4", "10"), - ("indepLevel_4", "true"), + ("all_benchmarks", "true"), + ("minQubits", "75"), + ("maxQubits", "110"), + ("selectBench_1", "Amplitude Estimation (AE)"), + ("selectBench_2", "Deutsch-Jozsa"), ("selectBench_3", "Graph State"), - ("minQubits_3", "5"), - ("maxQubits_3", "20"), - ("nativeGatesLevel_3", "true"), - ("ibm_3", "ibm"), - ("optlevel1_3", "1"), - ("optlevel3_3", "3"), - ("selectBench_21", "W State"), - ("minQubits_21", "10"), - ("maxQubits_21", "30"), - ("mappedLevel_21", "true"), - ("rigetti_21", "rigetti"), - ("smallest_arch_21", "True"), - ("optlevel0_21", "0"), - ("optlevel2_21", "2"), + ("selectBench_4", "GHZ State"), + ("selectBench_5", "Grover's (no ancilla)"), + ("selectBench_6", "Grover's (v-chain)"), + ("selectBench_7", "Portfolio Optimization with QAOA"), + ("selectBench_8", "Portfolio Optimization with VQE"), + ("selectBench_9", "Quantum Approximation Optimization Algorithm (QAOA)"), ("selectBench_10", "Quantum Fourier Transformation (QFT)"), - ("minQubits_10", "20"), - ("maxQubits_10", "120"), - ("nativeGatesLevel_10", "true"), - ("mappedLevel_10", "true"), - ("ibm_10", "ibm"), - ("rigetti_10", "rigetti"), - ("smallest_arch_10", "True"), - ("biggest_arch_10", "True"), - ("optlevel0_10", "0"), - ("optlevel1_10", "1"), - ("optlevel3_10", "3"), - ("selectBench_11", "Entangled QFT"), - ("minQubits_11", "100"), - ("maxQubits_11", "110"), - ("indepLevel_11", "true"), - ("mappedLevel_11", "true"), - ("biggest_arch_11", "True"), - ("optlevel2_11", "2"), + ("selectBench_11", "QFT Entangled"), + ("selectBench_12", "Quantum Generative Adversarial Network"), ("selectBench_13", "Quantum Phase Estimation (QPE) exact"), - ("minQubits_13", "5"), - ("maxQubits_13", "40"), - ("algorithmLevel_13", "true"), + ("selectBench_14", "Quantum Phase Estimation (QPE) inexact"), + ("selectBench_15", "Quantum Walk (no ancilla)"), + ("selectBench_16", "Quantum Walk (v-chain)"), + ("selectBench_17", "Variational Quantum Eigensolver (VQE)"), + ("selectBench_18", "Efficient SU2 ansatz with Random Parameters"), + ("selectBench_19", "Real Amplitudes ansatz with Random Parameters"), + ("selectBench_20", "Two Local ansatz with Random Parameters"), + ("selectBench_21", "W-State"), + ("selectBench_22", "Excited State"), + ("selectBench_23", "Ground State"), + ("selectBench_24", "HHL"), + ("selectBench_25", "Pricing Call Option"), + ("selectBench_26", "Pricing Put Option"), + ("selectBench_27", "Routing"), + ("selectBench_28", "Shor's"), + ("selectBench_29", "Travelling Salesman"), + ("indep_qiskit_compiler", "true"), + ("indep_tket_compiler", "true"), + ("nativegates_qiskit_compiler", "true"), + ("nativegates_qiskit_compiler_opt0", "true"), + ("nativegates_qiskit_compiler_opt1", "true"), + ("nativegates_qiskit_compiler_opt2", "true"), + ("nativegates_qiskit_compiler_opt3", "true"), + ("nativegates_tket_compiler value=", "on"), + ("nativegates_ibm", "true"), + ("nativegates_rigetti", "true"), + ("nativegates_oqc", "true"), + ("nativegates_ionq", "true"), + ("mapped_qiskit_compiler", "true"), + ("mapped_qiskit_compiler_opt0", "true"), + ("mapped_qiskit_compiler_opt1", "true"), + ("mapped_qiskit_compiler_opt2", "true"), + ("mapped_qiskit_compiler_opt3", "true"), + ("mapped_tket_compiler", "true"), + ("mapped_tket_compiler_graph", "true"), + ("mapped_tket_compiler_line", "true"), + ("device_ibm_washington", "true"), + ("device_ibm_montreal", "true"), + ("device_rigetti_aspen_m1", "true"), + ("device_oqc_lucy", "true"), + ("device_ionq_ionq11", "true"), ] ) - expected_res = { - "3": { - "selectBench_3": "Graph State", - "minQubits_3": "5", - "maxQubits_3": "20", - "nativeGatesLevel_3": "true", - "ibm_3": "ibm", - "optlevel1_3": "1", - "optlevel3_3": "3", - }, - "4": { - "selectBench_4": "GHZ State", - "minQubits_4": "5", - "maxQubits_4": "10", - "indepLevel_4": "true", - }, - "10": { - "selectBench_10": "Quantum Fourier Transformation (QFT)", - "minQubits_10": "20", - "maxQubits_10": "120", - "nativeGatesLevel_10": "true", - "mappedLevel_10": "true", - "ibm_10": "ibm", - "rigetti_10": "rigetti", - "smallest_arch_10": "True", - "biggest_arch_10": "True", - "optlevel0_10": "0", - "optlevel1_10": "1", - "optlevel3_10": "3", - }, - "11": { - "selectBench_11": "Entangled QFT", - "minQubits_11": "100", - "maxQubits_11": "110", - "indepLevel_11": "true", - "mappedLevel_11": "true", - "biggest_arch_11": "True", - "optlevel2_11": "2", - }, - "13": { - "selectBench_13": "Quantum Phase Estimation (QPE) exact", - "minQubits_13": "5", - "maxQubits_13": "40", - "algorithmLevel_13": "true", - }, - "21": { - "selectBench_21": "W State", - "minQubits_21": "10", - "maxQubits_21": "30", - "mappedLevel_21": "true", - "rigetti_21": "rigetti", - "smallest_arch_21": "True", - "optlevel0_21": "0", - "optlevel2_21": "2", - }, - } - assert backend.prepareFormInput(form_data) == expected_res - -def test_parseFilterCriteria(): - input_data = dict( - { - "3": { - "selectBench_3": "Graph State", - "minQubits_3": "5", - "maxQubits_3": "20", - "nativeGatesLevel_3": "true", - "ibm_3": "ibm", - "optlevel1_3": "1", - "optlevel3_3": "3", - }, - "4": { - "selectBench_4": "GHZ State", - "minQubits_4": "5", - "maxQubits_4": "10", - "indepLevel_4": "true", - }, - "10": { - "selectBench_10": "Quantum Fourier Transformation (QFT)", - "minQubits_10": "20", - "maxQubits_10": "120", - "nativeGatesLevel_10": "true", - "mappedLevel_10": "true", - "ibm_10": "ibm", - "rigetti_10": "rigetti", - "smallest_arch_10": "True", - "biggest_arch_10": "True", - "optlevel0_10": "0", - "optlevel1_10": "1", - "optlevel3_10": "3", - }, - "11": { - "selectBench_11": "Entangled QFT", - "minQubits_11": "100", - "maxQubits_11": "110", - "indepLevel_11": "true", - "mappedLevel_11": "true", - "biggest_arch_11": "True", - "optlevel2_11": "2", - }, - "13": { - "selectBench_13": "Quantum Phase Estimation (QPE) exact", - "minQubits_13": "5", - "maxQubits_13": "40", - "algorithmLevel_13": "true", - }, - "21": { - "selectBench_21": "W State", - "minQubits_21": "10", - "maxQubits_21": "30", - "mappedLevel_21": "true", - "rigetti_21": "rigetti", - "smallest_arch_21": "True", - "optlevel0_21": "0", - "optlevel2_21": "2", - }, - "29": { - "selectBench_29": "Travelling Salesman", - "minQubits_29": "-1", - "maxQubits_29": "-1", - "indepLevel_29": "true", - }, - } - ) - expected_filter_criteria = [ - [ - "graphstate", - "5", - "20", - True, - False, - False, - False, - True, - False, - False, - False, - [1, 3], - ], - ["ghz", "5", "10", False, False, False, True, False, False, False, False, []], + expected_res = ( + (75, 110), [ - "qft", - "20", - "120", - True, - True, - False, - False, - True, - True, - True, - True, - [0, 1, 3], - ], - [ - "qftentangled", - "100", - "110", - False, - False, - False, - True, - False, - True, - False, - True, - [2], - ], - [ - "qpeexact", + "1", + "2", + "3", + "4", "5", - "40", - False, - False, - True, - False, - False, - False, - False, - False, - [], - ], - [ - "wstate", + "6", + "7", + "8", + "9", "10", - "30", - False, - True, - False, - False, - False, - True, - True, - False, - [0, 2], - ], - [ - "tsp", - "-1", - "-1", - False, - False, - False, - True, - False, - False, - False, - False, - [], + "11", + "12", + "13", + "14", + "15", + "16", + "17", + "18", + "19", + "20", + "21", + "22", + "23", + "24", + "25", + "26", + "27", + "28", + "29", ], - ] - expected_algo_dicts = [{"name": "qpeexact", "min_qubits": "5", "max_qubits": "40"}] - expected_python_files_list = ["./static/files/algo_level.txt"] - - assert backend.parseFilterCriteria(input_data) == ( - expected_filter_criteria, - expected_algo_dicts, - expected_python_files_list, + (True, True), + ((True, True), [0, 1, 2, 3], ["ibm", "rigetti", "oqc", "ionq"]), + ( + (True, True), + ([0, 1, 2, 3], ["graph", "line"]), + [ + "ibm_washington", + "ibm_montreal", + "rigetti_aspen_m1", + "oqc_lucy", + "ionq11", + ], + ), ) + assert backend.prepareFormInput(form_data) == expected_res + def test_create_database(): @@ -400,158 +241,59 @@ def test_create_database(): MQTBENCH_ALL_ZIP = ZipFile(bytes, mode="r") database = backend.createDatabase(MQTBENCH_ALL_ZIP) - assert len(database) == 37497 + assert len(database) > 0 backend.database = database - input_data = dict( - { - "4": { - "selectBench_4": "GHZ State", - "minQubits_4": "5", - "maxQubits_4": "7", - "indepLevel_4": "true", - } - } - ) - res = backend.get_selected_file_paths(input_data) - assert len(res[0]) == 3 - - input_data = dict( - { - "3": { - "selectBench_3": "Graph State", - "minQubits_3": "99", - "maxQubits_3": "106", - "nativeGatesLevel_3": "true", - "ibm_3": "ibm", - "optlevel1_3": "1", - "optlevel2_3": "2", - } - } - ) - res = backend.get_selected_file_paths(input_data) - assert len(res[0]) == 16 - - input_data = dict( - { - "3": { - "selectBench_3": "Graph State", - "minQubits_3": "99", - "maxQubits_3": "106", - "nativeGatesLevel_3": "true", - "ibm_3": "ibm", - "optlevel1_3": "1", - } - } + input_data = ( + (2, 5), + ["4"], + (True, False), + ((False, False), [], []), + ((False, False), ([], []), []), ) res = backend.get_selected_file_paths(input_data) - assert len(res[0]) == 8 + assert len(res[0]) > 3 - input_data = dict( - { - "3": { - "selectBench_3": "Graph State", - "optlevel2_3": "2", - } - } + input_data = ( + (100, 110), + ["3"], + (False, False), + ((False, True), [], ["rigetti", "ionq"]), + ((False, False), ([], []), []), ) res = backend.get_selected_file_paths(input_data) - assert res == (False, False, False) + assert len(res[0]) > 20 - input_data = dict( - { - "10": { - "selectBench_10": "Quantum Fourier Transformation (QFT)", - "minQubits_10": "5", - "maxQubits_10": "6", - "mappedLevel_10": "true", - "rigetti_10": "rigetti", - "optlevel1_10": "1", - "biggest_arch_10": "True", - } - } + input_data = ( + (75, 110), + ["2"], + (False, False), + ((False, False), [], ["rigetti", "ionq"]), + ((True, True), ([1, 3], ["graph"]), ["ibm_washington", "rigetti_aspen_m1"]), ) res = backend.get_selected_file_paths(input_data) - assert len(res[0]) == 2 + assert len(res[0]) > 20 - input_data = dict( - { - "10": { - "selectBench_10": "Quantum Fourier Transformation (QFT)", - "minQubits_10": "5", - "maxQubits_10": "6", - "mappedLevel_10": "true", - "rigetti_10": "rigetti", - "optlevel1_10": "1", - "smallest_arch_10": "True", - "biggest_arch_10": "True", - } - } - ) - res = backend.get_selected_file_paths(input_data) - assert len(res[0]) == 4 - - input_data = dict( - { - "10": { - "selectBench_10": "Quantum Fourier Transformation (QFT)", - "minQubits_10": "5", - "maxQubits_10": "6", - "mappedLevel_10": "true", - "ibm_10": "ibm", - "rigetti_10": "rigetti", - "optlevel1_10": "1", - "smallest_arch_10": "True", - "biggest_arch_10": "True", - } - } - ) - res = backend.get_selected_file_paths(input_data) - assert len(res[0]) == 8 - - input_data = dict( - { - "10": { - "selectBench_10": "Quantum Fourier Transformation (QFT)", - "minQubits_10": "5", - "maxQubits_10": "8", - "nativeGatesLevel_10": "true", - "mappedLevel_10": "true", - "ibm_10": "ibm", - "rigetti_10": "rigetti", - "optlevel1_10": "1", - "smallest_arch_10": "True", - "biggest_arch_10": "True", - } - } + input_data = ( + (2, 5), + ["24"], + (True, True), + ((True, False), [1, 3], ["rigetti", "ionq", "oqc", "ibm"]), + ( + (True, True), + ([1, 3], ["graph", "line"]), + ["ibm_montreal", "rigetti_aspen_m1", "ionq11", "ocq_lucy"], + ), ) res = backend.get_selected_file_paths(input_data) - assert len(res[0]) == 24 + assert len(res[0]) > 20 - input_data = dict( - { - "21": { - "selectBench_21": "W State", - "minQubits_21": "5", - "maxQubits_21": "10", - "mappedLevel_21": "true", - "rigetti_21": "rigetti", - "smallest_arch_21": "True", - "optlevel0_21": "0", - }, - "10": { - "selectBench_10": "Quantum Fourier Transformation (QFT)", - "minQubits_10": "5", - "maxQubits_10": "8", - "nativeGatesLevel_10": "true", - "mappedLevel_10": "true", - "ibm_10": "ibm", - "rigetti_10": "rigetti", - "optlevel1_10": "1", - "smallest_arch_10": "True", - "biggest_arch_10": "True", - }, - } + input_data = ( + (2, 130), + ["1"], + (False, False), + ((True, True), [], []), + ((True, True), ([], []), []), ) res = backend.get_selected_file_paths(input_data) - assert len(res[0]) == 30 + assert res == [] From c4a26a8adf37ee0094bd7d150e859deaf300e905 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Fri, 12 Aug 2022 12:35:40 +0200 Subject: [PATCH 042/231] =?UTF-8?q?=E2=9C=A8=20removed=20unused=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/src/backend.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/benchviewer/src/backend.py b/benchviewer/src/backend.py index 5e8e192a7..895264f17 100644 --- a/benchviewer/src/backend.py +++ b/benchviewer/src/backend.py @@ -309,7 +309,6 @@ def filterDatabase(filterCriteria, database): if nativegates_qiskit_compiler: for gate_set in native_gatesets: for opt_lvl in native_qiskit_opt_lvls: - print(opt_lvl) db_tmp3 = db_tmp.loc[ (db_tmp["nativegates_flag"] == True) & (db_tmp["gate_set"] == gate_set) @@ -572,16 +571,3 @@ def prepareFormInput(formData): ) # print("Overall Result: ", res) return res - - -def add_min_max_qubit_number(database): - for benchmark in benchmarks: - max_val = database[database["benchmark"] == benchmark["filename"]][ - "num_qubits" - ].max() - benchmark["max_qubits"] = int(max_val) - - min_val = database[database["benchmark"] == benchmark["filename"]][ - "num_qubits" - ].min() - benchmark["min_qubits"] = int(min_val) From 76fc5716246b5913dd3c98af6decf20459f56111 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Fri, 12 Aug 2022 14:26:28 +0200 Subject: [PATCH 043/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20parallelization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 26f6353bb..201685986 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -72,7 +72,7 @@ def create_benchmarks_from_config(cfg_path: str): from joblib import Parallel, delayed - Parallel(n_jobs=-1, verbose=1)( + Parallel(n_jobs=-1, verbose=9)( delayed(generate_benchmark)(benchmark) for benchmark in cfg["benchmarks"] ) return @@ -91,6 +91,9 @@ def timeout_handler(signum, frame): # Custom signal handler signal.alarm(timeout) try: res = func(*args) + # except TimeoutException: + # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) + # return False except Exception as e: # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) print("Exception: ", e, func, args[0].name, args[1:]) From 647001b753521db503bfb5ac4331a852ea30db5a Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Fri, 12 Aug 2022 14:29:43 +0200 Subject: [PATCH 044/231] =?UTF-8?q?=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adjusted_database_parser.ipynb | 696 --------------------------------- 1 file changed, 696 deletions(-) delete mode 100644 adjusted_database_parser.ipynb diff --git a/adjusted_database_parser.ipynb b/adjusted_database_parser.ipynb deleted file mode 100644 index 749d32fdb..000000000 --- a/adjusted_database_parser.ipynb +++ /dev/null @@ -1,696 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 204, - "id": "f334d4ee", - "metadata": {}, - "outputs": [], - "source": [ - "benchmarks = [\n", - " {\"name\": \"Amplitude Estimation (AE)\", \"id\": \"1\", \"filename\": \"ae\"},\n", - " {\"name\": \"Deutsch-Jozsa\", \"id\": \"2\", \"filename\": \"dj\"},\n", - " {\"name\": \"Graph State\", \"id\": \"3\", \"filename\": \"graphstate\"},\n", - " {\"name\": \"GHZ State\", \"id\": \"4\", \"filename\": \"ghz\"},\n", - " {\"name\": \"Grover's (no ancilla)\", \"id\": \"5\", \"filename\": \"grover-noancilla\"},\n", - " {\"name\": \"Grover's (v-chain)\", \"id\": \"6\", \"filename\": \"grover-v-chain\"},\n", - " {\n", - " \"name\": \"Portfolio Optimization with QAOA\",\n", - " \"id\": \"7\",\n", - " \"filename\": \"portfolioqaoa\",\n", - " },\n", - " {\"name\": \"Portfolio Optimization with VQE\", \"id\": \"8\", \"filename\": \"portfoliovqe\"},\n", - " {\n", - " \"name\": \"Quantum Approximation Optimization Algorithm (QAOA)\",\n", - " \"id\": \"9\",\n", - " \"filename\": \"qaoa\",\n", - " },\n", - " {\"name\": \"Quantum Fourier Transformation (QFT)\", \"id\": \"10\", \"filename\": \"qft\"},\n", - " {\"name\": \"QFT Entangled\", \"id\": \"11\", \"filename\": \"qftentangled\"},\n", - " {\"name\": \"Quantum Generative Adversarial Network\", \"id\": \"12\", \"filename\": \"qgan\"},\n", - " {\n", - " \"name\": \"Quantum Phase Estimation (QPE) exact\",\n", - " \"id\": \"13\",\n", - " \"filename\": \"qpeexact\",\n", - " },\n", - " {\n", - " \"name\": \"Quantum Phase Estimation (QPE) inexact\",\n", - " \"id\": \"14\",\n", - " \"filename\": \"qpeinexact\",\n", - " },\n", - " {\"name\": \"Quantum Walk (no ancilla)\", \"id\": \"15\", \"filename\": \"qwalk-noancilla\"},\n", - " {\"name\": \"Quantum Walk (v-chain)\", \"id\": \"16\", \"filename\": \"qwalk-v-chain\"},\n", - " {\"name\": \"Variational Quantum Eigensolver (VQE)\", \"id\": \"17\", \"filename\": \"vqe\"},\n", - " {\n", - " \"name\": \"Efficient SU2 ansatz with Random Parameters\",\n", - " \"id\": \"18\",\n", - " \"filename\": \"su2random\",\n", - " },\n", - " {\n", - " \"name\": \"Real Amplitudes ansatz with Random Parameters\",\n", - " \"id\": \"19\",\n", - " \"filename\": \"realamprandom\",\n", - " },\n", - " {\n", - " \"name\": \"Two Local ansatz with Random Parameters\",\n", - " \"id\": \"20\",\n", - " \"filename\": \"twolocalrandom\",\n", - " },\n", - " {\"name\": \"W-State\", \"id\": \"21\", \"filename\": \"wstate\"},\n", - "]\n", - "\n", - "nonscalable_benchmarks = [\n", - " {\"name\": \"Excited State\", \"id\": \"22\", \"filename\": \"excitedstate\"},\n", - " {\"name\": \"Ground State\", \"id\": \"23\", \"filename\": \"groundstate\"},\n", - " {\"name\": \"HHL\", \"id\": \"24\", \"filename\": \"hhl\"},\n", - " {\"name\": \"Pricing Call Option\", \"id\": \"25\", \"filename\": \"pricingcall\"},\n", - " {\"name\": \"Pricing Put Option\", \"id\": \"26\", \"filename\": \"pricingput\"},\n", - " {\"name\": \"Routing\", \"id\": \"27\", \"filename\": \"routing\"},\n", - " {\"name\": \"Shor's\", \"id\": \"28\", \"filename\": \"shor\"},\n", - " {\"name\": \"Travelling Salesman\", \"id\": \"29\", \"filename\": \"tsp\"},\n", - "]" - ] - }, - { - "cell_type": "code", - "execution_count": 205, - "id": "63cd9080", - "metadata": {}, - "outputs": [], - "source": [ - "def get_opt_level(filename: str):\n", - " \"\"\"Extracts the optimization level based on a filename.\n", - "\n", - " Keyword arguments:\n", - " filename -- filename of a benchmark\n", - "\n", - " Return values:\n", - " num -- optimization level\n", - " \"\"\"\n", - "\n", - " pat = re.compile(r\"opt\\d\")\n", - " m = pat.search(filename)\n", - " if m:\n", - " num = m.group()[-1:]\n", - " else:\n", - " num = -1\n", - " return int(num)" - ] - }, - { - "cell_type": "code", - "execution_count": 206, - "id": "92b83186", - "metadata": {}, - "outputs": [], - "source": [ - "def get_num_qubits(filename: str):\n", - " \"\"\"Extracts the number of qubits based on a filename.\n", - "\n", - " Keyword arguments:\n", - " filename -- filename of a benchmark\n", - "\n", - " Return values:\n", - " num -- optimization level\n", - " \"\"\"\n", - "\n", - " pat = re.compile(r\"(\\d+)\\.\")\n", - " m = pat.search(filename)\n", - " if m:\n", - " num = m.group()[0:-1]\n", - " else:\n", - " num = -1\n", - " return int(num)" - ] - }, - { - "cell_type": "code", - "execution_count": 207, - "id": "1d2ffaed", - "metadata": {}, - "outputs": [], - "source": [ - "def get_tket_settings(filename: str):\n", - " if \"line\" in filename:\n", - " return \"line\"\n", - " elif \"graph\" in filename:\n", - " return \"graph\"\n", - "\n", - "\n", - "def get_gate_set(filename: str):\n", - " if \"oqc\" in filename:\n", - " return \"oqc\"\n", - " elif \"ionq\" in filename:\n", - " return \"ionq\"\n", - " elif \"ibm\" in filename:\n", - " return \"ibm\"\n", - " elif \"rigetti\" in filename:\n", - " return \"rigetti\"\n", - "\n", - "\n", - "def get_target_device(filename: str):\n", - " if \"ibm_washington\" in filename:\n", - " return \"ibm_washington\"\n", - " elif \"ibm_montreal\" in filename:\n", - " return \"ibm_montreal\"\n", - " elif \"rigetti_aspen_m1\" in filename:\n", - " return \"rigetti_aspen_m1\"\n", - " elif \"ionq11\" in filename:\n", - " return \"ionq11\"\n", - " elif \"oqc_lucy\" in filename:\n", - " return \"oqc_lucy\"" - ] - }, - { - "cell_type": "code", - "execution_count": 208, - "id": "a8d83429", - "metadata": {}, - "outputs": [], - "source": [ - "def get_compiler_and_settings(filename: str):\n", - " if \"qiskit\" in filename:\n", - " return (\"qiskit\", get_opt_level(filename))\n", - " elif \"tket\" in filename:\n", - " return (\"tket\", get_tket_settings(filename))" - ] - }, - { - "cell_type": "code", - "execution_count": 209, - "id": "f133dfb1", - "metadata": {}, - "outputs": [], - "source": [ - "def parse_data(filename: str):\n", - " \"\"\"Extracts the necessary information from a given filename.\n", - "\n", - " Keyword arguments:\n", - " filename -- name of file\n", - "\n", - " Return values:\n", - " parsed_data -- parsed data extracted from filename\n", - " \"\"\"\n", - " benchmark = filename.split(\"_\")[1].lower().split(\"/\")[-1]\n", - " num_qubits = get_num_qubits(filename)\n", - " indep_flag = \"indep\" in filename\n", - " nativegates_flag = \"nativegates\" in filename\n", - " mapped_flag = \"mapped\" in filename\n", - " compiler, compiler_settings = get_compiler_and_settings(filename)\n", - " gate_set = get_gate_set(filename)\n", - " target_device = get_target_device(filename)\n", - "\n", - " path = os.path.join(filename)\n", - " parsed_data = [\n", - " benchmark,\n", - " num_qubits,\n", - " indep_flag,\n", - " nativegates_flag,\n", - " mapped_flag,\n", - " compiler,\n", - " compiler_settings,\n", - " gate_set,\n", - " target_device,\n", - " path,\n", - " ]\n", - " return parsed_data" - ] - }, - { - "cell_type": "code", - "execution_count": 213, - "id": "7618ce2d", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(36044, 10)" - ] - }, - "execution_count": 213, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from mqt.bench.utils import utils, qiskit_helper, tket_helper\n", - "import os\n", - "import re\n", - "import pandas as pd\n", - "\n", - "rows_list = []\n", - "# for filename in os.listdir(qasm_path):\n", - "directory = (\n", - " \"/Users/nils/Desktop/qasm_output/qasm_output\" # utils.get_qasm_output_path()\n", - ")\n", - "\n", - "for f in os.listdir(directory):\n", - " parsed_data = parse_data(os.path.join(directory, f))\n", - " rows_list.append(parsed_data)\n", - "\n", - "\n", - "colnames = [\n", - " \"benchmark\",\n", - " \"num_qubits\",\n", - " \"indep_flag\",\n", - " \"nativegates_flag\",\n", - " \"mapped_flag\",\n", - " \"compiler\",\n", - " \"compiler_settings\",\n", - " \"gate_set\",\n", - " \"target_device\",\n", - " \"path\",\n", - "]\n", - "\n", - "database = pd.DataFrame(rows_list, columns=colnames)\n", - "database[\"num_qubits\"] = database[\"num_qubits\"].astype(int)\n", - "database[\"benchmark\"] = database[\"benchmark\"].astype(str)\n", - "\n", - "database.shape" - ] - }, - { - "cell_type": "code", - "execution_count": 214, - "id": "d1773aa8", - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[False, True]\n" - ] - } - ], - "source": [ - "print(list(database.indep_flag.unique()))" - ] - }, - { - "cell_type": "code", - "execution_count": 215, - "id": "fb0d3b37", - "metadata": {}, - "outputs": [], - "source": [ - "def filterDatabase(filterCriteria, database):\n", - " colnames = [\n", - " \"benchmark\",\n", - " \"num_qubits\",\n", - " \"indep_flag\",\n", - " \"nativegates_flag\",\n", - " \"mapped_flag\",\n", - " \"compiler\",\n", - " \"compiler_settings\",\n", - " \"gate_set\",\n", - " \"target_device\",\n", - " \"path\",\n", - " ]\n", - " db_filtered = pd.DataFrame(columns=colnames)\n", - " if len(database) == 0:\n", - " return []\n", - "\n", - " (\n", - " (min_qubits, max_qubits),\n", - " indices_benchmarks,\n", - " (indep_qiskit_compiler, indep_tket_compiler),\n", - " (\n", - " (nativegates_qiskit_compiler, nativegates_tket_compiler),\n", - " native_qiskit_opt_lvls,\n", - " native_gatesets,\n", - " ),\n", - " (\n", - " (mapped_qiskit_compiler, mapped_tket_compiler),\n", - " (mapped_qiskit_opt_lvls, mapped_tket_placements),\n", - " mapped_devices,\n", - " ),\n", - " ) = filterCriteria\n", - "\n", - " for identifier in indices_benchmarks:\n", - " if int(identifier) > 0 and int(identifier) <= len(benchmarks):\n", - " name = benchmarks[int(identifier) - 1][\"filename\"]\n", - "\n", - " db_tmp = database.loc[\n", - " (database[\"num_qubits\"] >= min_qubits)\n", - " & (database[\"num_qubits\"] <= max_qubits)\n", - " & (database[\"benchmark\"] == name)\n", - " ]\n", - " elif int(identifier) > 0 and int(identifier) <= len(benchmarks) + len(\n", - " nonscalable_benchmarks\n", - " ):\n", - " name = nonscalable_benchmarks[int(identifier) - 1 - len(benchmarks)][\n", - " \"filename\"\n", - " ]\n", - " db_tmp = database.loc[database[\"benchmark\"] == name]\n", - " else:\n", - " print(\"FAIL\")\n", - "\n", - " print(name, \":\", len(db_tmp))\n", - "\n", - " if indep_qiskit_compiler:\n", - " db_tmp1 = db_tmp.loc[\n", - " (db_tmp[\"indep_flag\"] == True) & (db_tmp[\"compiler\"] == \"qiskit\")\n", - " ]\n", - " db_filtered = pd.concat([db_filtered, db_tmp1])\n", - "\n", - " if indep_tket_compiler:\n", - " db_tmp2 = db_tmp.loc[\n", - " (db_tmp[\"indep_flag\"] == True) & (db_tmp[\"compiler\"] == \"tket\")\n", - " ]\n", - " db_filtered = pd.concat([db_filtered, db_tmp2])\n", - "\n", - " if nativegates_qiskit_compiler:\n", - " for gate_set in native_gatesets:\n", - " for opt_lvl in native_qiskit_opt_lvls:\n", - " db_tmp3 = db_tmp.loc[\n", - " (db_tmp[\"nativegates_flag\"] == True)\n", - " & (db_tmp[\"gate_set\"] == gate_set)\n", - " & (db_tmp[\"compiler\"] == \"qiskit\")\n", - " & (db_tmp[\"compiler_settings\"] == opt_lvl)\n", - " ]\n", - " db_filtered = pd.concat([db_filtered, db_tmp3])\n", - "\n", - " if nativegates_tket_compiler:\n", - " for gate_set in native_gatesets:\n", - " db_tmp4 = db_tmp.loc[\n", - " (db_tmp[\"nativegates_flag\"] == True)\n", - " & (db_tmp[\"gate_set\"] == gate_set)\n", - " & (db_tmp[\"compiler\"] == \"tket\")\n", - " ]\n", - " db_filtered = pd.concat([db_filtered, db_tmp4])\n", - "\n", - " if mapped_qiskit_compiler:\n", - " for opt_lvl in native_qiskit_opt_lvls:\n", - " for device in mapped_devices:\n", - " db_tmp5 = db_tmp.loc[\n", - " (db_tmp[\"mapped_flag\"] == True)\n", - " & (db_tmp[\"target_device\"] == device)\n", - " & (db_tmp[\"compiler\"] == \"qiskit\")\n", - " & (db_tmp[\"compiler_settings\"] == opt_lvl)\n", - " ]\n", - " db_filtered = pd.concat([db_filtered, db_tmp5])\n", - "\n", - " if mapped_tket_compiler:\n", - " for placement in mapped_tket_placements:\n", - " for device in mapped_devices:\n", - " db_tmp6 = db_tmp.loc[\n", - " (db_tmp[\"mapped_flag\"] == True)\n", - " & (db_tmp[\"target_device\"] == device)\n", - " & (db_tmp[\"compiler\"] == \"tket\")\n", - " & (db_tmp[\"compiler_settings\"] == placement)\n", - " ]\n", - " db_filtered = pd.concat([db_filtered, db_tmp6])\n", - "\n", - " return db_filtered[\"path\"].to_list()" - ] - }, - { - "cell_type": "code", - "execution_count": 196, - "id": "eb8b9026", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ae : 2035\n", - "dj : 4188\n", - "graphstate : 3971\n", - "ghz : 4270\n", - "grover-noancilla : 310\n", - "grover-v-chain : 0\n", - "portfolioqaoa : 352\n", - "portfoliovqe : 442\n", - "qaoa : 750\n", - "qft : 2060\n", - "qftentangled : 2009\n", - "qgan : 104\n", - "qpeexact : 2031\n", - "qpeinexact : 2029\n", - "qwalk-noancilla : 262\n", - "qwalk-v-chain : 0\n", - "vqe : 559\n", - "su2random : 1824\n", - "realamprandom : 1829\n", - "twolocalrandom : 1824\n", - "wstate : 4270\n", - "excitedstate : 0\n", - "groundstate : 0\n", - "hhl : 78\n", - "pricingcall : 343\n", - "pricingput : 341\n", - "routing : 103\n", - "shor : 8\n", - "tsp : 52\n" - ] - } - ], - "source": [ - "criteria = (\n", - " (1, 130),\n", - " [\n", - " \"1\",\n", - " \"2\",\n", - " \"3\",\n", - " \"4\",\n", - " \"5\",\n", - " \"6\",\n", - " \"7\",\n", - " \"8\",\n", - " \"9\",\n", - " \"10\",\n", - " \"11\",\n", - " \"12\",\n", - " \"13\",\n", - " \"14\",\n", - " \"15\",\n", - " \"16\",\n", - " \"17\",\n", - " \"18\",\n", - " \"19\",\n", - " \"20\",\n", - " \"21\",\n", - " \"22\",\n", - " \"23\",\n", - " \"24\",\n", - " \"25\",\n", - " \"26\",\n", - " \"27\",\n", - " \"28\",\n", - " \"29\",\n", - " ],\n", - " (True, True),\n", - " ((True, True), [0, 1, 2, 3], [\"oqc\", \"ionq\", \"ibm\", \"rigetti\"]),\n", - " (\n", - " (True, True),\n", - " ([0, 1, 2, 3], [\"graph\", \"line\"]),\n", - " [\"ibm_washington\", \"rigetti_aspen_m1\", \"ionq11\", \"ibm_montreal\", \"oqc_lucy\"],\n", - " ),\n", - ")\n", - "paths = filterDatabase(criteria, database)" - ] - }, - { - "cell_type": "code", - "execution_count": 197, - "id": "4bc63027", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "36044" - ] - }, - "execution_count": 197, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(paths)" - ] - }, - { - "cell_type": "code", - "execution_count": 198, - "id": "9ce284a5", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(17281, 10) (4038, 10) (21319, 10)\n" - ] - } - ], - "source": [ - "print(\n", - " database.loc[\n", - " (database[\"nativegates_flag\"] == True) & (database[\"compiler\"] == \"qiskit\")\n", - " ].shape,\n", - " database.loc[\n", - " (database[\"nativegates_flag\"] == True) & (database[\"compiler\"] == \"tket\")\n", - " ].shape,\n", - " database.loc[(database[\"nativegates_flag\"] == True)].shape,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 199, - "id": "eeec38f4", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "17281\n" - ] - } - ], - "source": [ - "native_gatesets = [\"oqc\", \"ionq\", \"ibm\", \"rigetti\"]\n", - "native_qiskit_opt_lvls = [0, 1, 2, 3]\n", - "tmp = 0\n", - "for gate_set in native_gatesets:\n", - " for opt_lvl in native_qiskit_opt_lvls:\n", - " db_tmp3 = database.loc[\n", - " (database[\"nativegates_flag\"] == True)\n", - " & (database[\"gate_set\"] == gate_set)\n", - " & (database[\"compiler\"] == \"qiskit\")\n", - " & (database[\"compiler_settings\"] == opt_lvl)\n", - " ]\n", - " tmp += db_tmp3.shape[0]\n", - "print(tmp)" - ] - }, - { - "cell_type": "code", - "execution_count": 200, - "id": "a460063a", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "4038\n" - ] - } - ], - "source": [ - "native_gatesets = [\"oqc\", \"ionq\", \"ibm\", \"rigetti\"]\n", - "tmp = 0\n", - "for gate_set in native_gatesets:\n", - " db_tmp3 = database.loc[\n", - " (database[\"nativegates_flag\"] == True)\n", - " & (database[\"gate_set\"] == gate_set)\n", - " & (database[\"compiler\"] == \"tket\")\n", - " ]\n", - " tmp += db_tmp3.shape[0]\n", - "print(tmp)" - ] - }, - { - "cell_type": "code", - "execution_count": 201, - "id": "e9cdb06a", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array(['ionq', 'oqc', 'rigetti', 'ibm'], dtype=object)" - ] - }, - "execution_count": 201, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "database.loc[\n", - " (database[\"nativegates_flag\"] == True) & (database[\"compiler\"] == \"tket\")\n", - "].gate_set.unique()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4bf28f41", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 56, - "id": "e3d103af", - "metadata": {}, - "outputs": [], - "source": [ - "from zipfile import ZipFile, ZIP_DEFLATED\n", - "\n", - "\n", - "def create_zip_file():\n", - " zf = zipfile.ZipFile(\"MQTBench_all.zip\", \"w\")\n", - " for dirname, subdirs, files in os.walk(utils.get_qasm_output_path()):\n", - " for filename in files:\n", - " zf.write(\n", - " os.path.join(dirname, filename),\n", - " compress_type=ZIP_DEFLATED,\n", - " compresslevel=3,\n", - " arcname=filename,\n", - " )\n", - " zf.close()" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "id": "72c430c7", - "metadata": {}, - "outputs": [], - "source": [ - "create_zip_file()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5198f4f7", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.7" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From 14e0b35b73aea8dc832212b56ba4be8c1628f406 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 13:08:15 +0200 Subject: [PATCH 045/231] =?UTF-8?q?=F0=9F=90=9B=20fixed=20bug=20caused=20b?= =?UTF-8?q?y=20faulty=20import=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 201685986..9d51c1d81 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -649,5 +649,5 @@ def get_one_benchmark( print(args.file_name) create_benchmarks_from_config(args.file_name) - postprocess_ocr_qasm_files() + utils.postprocess_ocr_qasm_files() utils.create_zip_file() From 41b81e7c97e9640753987f6ffbc886aee7adbdf7 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 14:13:38 +0200 Subject: [PATCH 046/231] =?UTF-8?q?=F0=9F=90=9B=20removed=20qiskit=20compi?= =?UTF-8?q?le=20step?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/tket_helper.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index bca236893..b440032db 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -8,14 +8,14 @@ auto_rebase_pass, ) from pytket.placement import GraphPlacement, LinePlacement -from pytket.qasm import circuit_to_qasm_str, circuit_to_qasm +from pytket.qasm import circuit_to_qasm_str, circuit_from_qasm_str from pytket import architecture, circuit from mqt.bench.utils import utils from os import path from pytket.extensions.qiskit import qiskit_to_tk -from qiskit import transpile +from qiskit import QuantumCircuit def get_rebase(gate_set_name: str, get_gatenames: bool = False): @@ -70,7 +70,7 @@ def get_ibm_rebase(get_gatenames: bool = False): def get_indep_level( - qc: circuit, + qc: QuantumCircuit, num_qubits: int, file_precheck: bool, return_qc: bool = False, @@ -88,12 +88,9 @@ def get_indep_level( # + ".qasm" # + " does not already exists and is newly created" # ) - openqasm_gates = utils.get_openqasm_gates() - target_independent_qiskit = transpile( - qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 - ) - qc_tket = qiskit_to_tk(target_independent_qiskit) + qc_tket = circuit_from_qasm_str(qc.qasm()) FullPeepholeOptimise().apply(qc_tket) + print(qc_tket) if return_qc: return qc_tket else: @@ -125,11 +122,8 @@ def get_native_gates_level( # + ".qasm" # + " does not already exists and is newly created" # ) - openqasm_gates = utils.get_openqasm_gates() - target_independent_qiskit = transpile( - qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 - ) - qc_tket = qiskit_to_tk(target_independent_qiskit) + + qc_tket = qiskit_to_tk(qc) native_gatenames = get_rebase(gate_set_name, True) native_gate_set_rebase = get_rebase(gate_set_name) native_gate_set_rebase.apply(qc_tket) @@ -177,11 +171,8 @@ def get_mapped_level( # + ".qasm" # + " does not already exists and is newly created" # ) - openqasm_gates = utils.get_openqasm_gates() - target_independent_qiskit = transpile( - qc, basis_gates=openqasm_gates, optimization_level=1, seed_transpiler=10 - ) - qc_tket = qiskit_to_tk(target_independent_qiskit) + + qc_tket = qiskit_to_tk(qc) native_gatenames = get_rebase(gate_set_name, True) native_gate_set_rebase = get_rebase(gate_set_name) From bfd24f3b4ac2a79d0e5229c5e532ee83a19e92d8 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 14:13:53 +0200 Subject: [PATCH 047/231] =?UTF-8?q?=E2=9C=A8=20modified=20zip=20creation?= =?UTF-8?q?=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/utils.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index 1a5a6efbb..85c57258e 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -358,16 +358,11 @@ def create_zip_file(): zf = ZipFile("MQTBench_all.zip", "w") for dirname, subdirs, files in os.walk(get_qasm_output_path()): for filename in files: - zf.write( - os.path.join(dirname, filename), - compress_type=ZIP_DEFLATED, - compresslevel=3, - arcname=filename, - ) - zf.write( - "./benchviewer/static/files/algo_level.txt", - compress_type=ZIP_DEFLATED, - compresslevel=3, - arcname="algo_level.txt", - ) + if filename.endswith(".qasm"): + zf.write( + os.path.join(dirname, filename), + compress_type=ZIP_DEFLATED, + compresslevel=3, + arcname=filename, + ) zf.close() From 39b66a02b90c163b8ec9b50a44df8db63591d12e Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 15:12:22 +0200 Subject: [PATCH 048/231] =?UTF-8?q?=E2=9C=A8=20used=20different=20scheme?= =?UTF-8?q?=20for=20timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 46 +++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 9d51c1d81..f745c7367 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -79,28 +79,42 @@ def create_benchmarks_from_config(cfg_path: str): def benchmark_generation_watcher(func, args): - class TimeoutException(Exception): # Custom exception class - pass + import multiprocessing - def timeout_handler(signum, frame): # Custom signal handler - raise TimeoutException("TimeoutException") + p = multiprocessing.Process(target=func(*args)) + p.start() - # Change the behavior of SIGALRM - signal.signal(signal.SIGALRM, timeout_handler) + p.join(timeout) - signal.alarm(timeout) - try: - res = func(*args) + if p.is_alive(): + print("still running, time to terminate/kill it") + p.terminate() + return False + + return True + + # class TimeoutException(Exception): # Custom exception class + # pass + # + # def timeout_handler(signum, frame): # Custom signal handler + # raise TimeoutException("TimeoutException") + # + # # Change the behavior of SIGALRM + # signal.signal(signal.SIGALRM, timeout_handler) + # + # signal.alarm(timeout) + # try: + # res = func(*args) # except TimeoutException: # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) # return False - except Exception as e: - # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) - print("Exception: ", e, func, args[0].name, args[1:]) - return False - else: - # Reset the alarm - signal.alarm(0) + # except Exception as e: + # # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) + # print("Exception: ", e)#, func, args[0].name, args[1:]) + # return False + # else: + # # Reset the alarm + # signal.alarm(0) return res From 929c61bc0f64b09cdc301987ce2cc98547f2baeb Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 15:12:36 +0200 Subject: [PATCH 049/231] =?UTF-8?q?=E2=9C=A8=20added=20rebase=20for=20inde?= =?UTF-8?q?p=20layer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/tket_helper.py | 62 +++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index b440032db..755c39616 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -27,6 +27,64 @@ def get_rebase(gate_set_name: str, get_gatenames: bool = False): return get_ibm_rebase(get_gatenames) elif gate_set_name == "rigetti": return get_rigetti_rebase(get_gatenames) + elif gate_set_name == "openqasm": + return get_openqasm_rebase(get_gatenames) + + +def get_openqasm_rebase(get_gatenames: bool = False): + if get_gatenames: + return utils.get_openqasm_gates() + else: + openqasm_rebase = auto_rebase_pass( + { + OpType.U3, + OpType.U2, + OpType.U1, + OpType.CX, + OpType.noop, + # "u0", + # u", + # "p", + OpType.X, + OpType.Y, + OpType.Z, + OpType.H, + OpType.S, + OpType.Sdg, + OpType.T, + OpType.Tdg, + OpType.Rx, + OpType.Ry, + OpType.Rz, + OpType.SX, + OpType.SXdg, + OpType.CX, + OpType.CZ, + OpType.CY, + OpType.SWAP, + OpType.CH, + OpType.CCX, + OpType.CSWAP, + OpType.CRx, + OpType.CRy, + OpType.CRz, + OpType.CU1, + # OpType.CPhase, + OpType.CU3, + OpType.CSX, + # "cu", + OpType.XXPhase, + OpType.ZZPhase, + # "rccx", + # "rc3x", + # "c3x", + # "c3sqrtx", + # "c4x", + OpType.Measure, + } + ) + + return openqasm_rebase def get_ionq_rebase(get_gatenames: bool = False): @@ -88,7 +146,9 @@ def get_indep_level( # + ".qasm" # + " does not already exists and is newly created" # ) - qc_tket = circuit_from_qasm_str(qc.qasm()) + qc_tket = qiskit_to_tk(qc) + openqasm_gate_set_rebase = get_rebase("openqasm") + openqasm_gate_set_rebase.apply(qc_tket) FullPeepholeOptimise().apply(qc_tket) print(qc_tket) if return_qc: From 5373a43f566616581103fba41aab433113ae0768 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 15:24:34 +0200 Subject: [PATCH 050/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20timeout=20watche?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index f745c7367..a2cd88843 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -6,6 +6,7 @@ import signal import argparse import numpy as np +import multiprocessing from typing import Union from os import path, mkdir, remove @@ -79,7 +80,6 @@ def create_benchmarks_from_config(cfg_path: str): def benchmark_generation_watcher(func, args): - import multiprocessing p = multiprocessing.Process(target=func(*args)) p.start() From a0dd4573bc2fed6f99a4197406ad9bda9cf4ff32 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 18:56:04 +0200 Subject: [PATCH 051/231] =?UTF-8?q?=E2=9C=85=20adjusted=20test=20to=20new?= =?UTF-8?q?=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/src/tests/test_backend.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/benchviewer/src/tests/test_backend.py b/benchviewer/src/tests/test_backend.py index 1032ef8c0..10a4fbc86 100644 --- a/benchviewer/src/tests/test_backend.py +++ b/benchviewer/src/tests/test_backend.py @@ -252,7 +252,7 @@ def test_create_database(): ((False, False), ([], []), []), ) res = backend.get_selected_file_paths(input_data) - assert len(res[0]) > 3 + assert len(res) > 3 input_data = ( (100, 110), @@ -262,7 +262,7 @@ def test_create_database(): ((False, False), ([], []), []), ) res = backend.get_selected_file_paths(input_data) - assert len(res[0]) > 20 + assert len(res) > 20 input_data = ( (75, 110), @@ -272,7 +272,7 @@ def test_create_database(): ((True, True), ([1, 3], ["graph"]), ["ibm_washington", "rigetti_aspen_m1"]), ) res = backend.get_selected_file_paths(input_data) - assert len(res[0]) > 20 + assert len(res) > 20 input_data = ( (2, 5), @@ -286,7 +286,7 @@ def test_create_database(): ), ) res = backend.get_selected_file_paths(input_data) - assert len(res[0]) > 20 + assert len(res) > 20 input_data = ( (2, 130), From c7d5b843a2c9539957e2dd521cd57b34c06b1412 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 18:56:27 +0200 Subject: [PATCH 052/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20tket=20function?= =?UTF-8?q?=20to=20handle=20algo=20layer=20circuit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/tket_helper.py | 41 +++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index 755c39616..c88c0fdbc 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -15,7 +15,7 @@ from os import path from pytket.extensions.qiskit import qiskit_to_tk -from qiskit import QuantumCircuit +from qiskit import QuantumCircuit, transpile def get_rebase(gate_set_name: str, get_gatenames: bool = False): @@ -146,11 +146,20 @@ def get_indep_level( # + ".qasm" # + " does not already exists and is newly created" # ) - qc_tket = qiskit_to_tk(qc) + try: + qc = transpile( + qc, + basis_gates=utils.get_openqasm_gates(), + seed_transpiler=10, + optimization_level=0, + ) + qc_tket = qiskit_to_tk(qc) + except Exception as e: + print(e) + return False openqasm_gate_set_rebase = get_rebase("openqasm") openqasm_gate_set_rebase.apply(qc_tket) FullPeepholeOptimise().apply(qc_tket) - print(qc_tket) if return_qc: return qc_tket else: @@ -183,7 +192,19 @@ def get_native_gates_level( # + " does not already exists and is newly created" # ) - qc_tket = qiskit_to_tk(qc) + try: + qc = transpile( + qc, + basis_gates=utils.get_openqasm_gates(), + seed_transpiler=10, + optimization_level=0, + ) + + qc_tket = qiskit_to_tk(qc) + except Exception as e: + print(e) + return False + native_gatenames = get_rebase(gate_set_name, True) native_gate_set_rebase = get_rebase(gate_set_name) native_gate_set_rebase.apply(qc_tket) @@ -231,8 +252,18 @@ def get_mapped_level( # + ".qasm" # + " does not already exists and is newly created" # ) + try: + qc = transpile( + qc, + basis_gates=utils.get_openqasm_gates(), + seed_transpiler=10, + optimization_level=0, + ) - qc_tket = qiskit_to_tk(qc) + qc_tket = qiskit_to_tk(qc) + except Exception as e: + print(e) + return False native_gatenames = get_rebase(gate_set_name, True) native_gate_set_rebase = get_rebase(gate_set_name) From cbed3cb6117b2bae6308bba82ae2441d9ad6eb8e Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Sat, 13 Aug 2022 18:56:51 +0200 Subject: [PATCH 053/231] =?UTF-8?q?=E2=9C=A8=20removed=20alternative=20app?= =?UTF-8?q?roach=20to=20take=20care=20of=20timeout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 51 ++++++++++++-------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index a2cd88843..9b3e53bc8 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -73,48 +73,35 @@ def create_benchmarks_from_config(cfg_path: str): from joblib import Parallel, delayed - Parallel(n_jobs=-1, verbose=9)( + Parallel(n_jobs=-1, verbose=100)( delayed(generate_benchmark)(benchmark) for benchmark in cfg["benchmarks"] ) return def benchmark_generation_watcher(func, args): + class TimeoutException(Exception): # Custom exception class + pass - p = multiprocessing.Process(target=func(*args)) - p.start() + def timeout_handler(signum, frame): # Custom signal handler + raise TimeoutException("TimeoutException") - p.join(timeout) + # Change the behavior of SIGALRM + signal.signal(signal.SIGALRM, timeout_handler) - if p.is_alive(): - print("still running, time to terminate/kill it") - p.terminate() + signal.alarm(timeout) + try: + res = func(*args) + except TimeoutException: + print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) return False - - return True - - # class TimeoutException(Exception): # Custom exception class - # pass - # - # def timeout_handler(signum, frame): # Custom signal handler - # raise TimeoutException("TimeoutException") - # - # # Change the behavior of SIGALRM - # signal.signal(signal.SIGALRM, timeout_handler) - # - # signal.alarm(timeout) - # try: - # res = func(*args) - # except TimeoutException: - # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) - # return False - # except Exception as e: - # # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) - # print("Exception: ", e)#, func, args[0].name, args[1:]) - # return False - # else: - # # Reset the alarm - # signal.alarm(0) + except Exception as e: + # print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) + print("Exception: ", e) # , func, args[0].name, args[1:]) + return False + else: + # Reset the alarm + signal.alarm(0) return res From 49de38454119bdeafe6190bb1b632579ca518ce6 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 16 Aug 2022 09:46:45 +0200 Subject: [PATCH 054/231] =?UTF-8?q?=E2=9C=A8=20improved=20logic=20in=20ben?= =?UTF-8?q?chmark=20generation=20and=20print=20statements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 9b3e53bc8..f03be71ed 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -230,8 +230,6 @@ def generate_benchmark(benchmark): benchmark["min_qubits"], benchmark["max_qubits"], benchmark["stepsize"] ): - # res_qc_creation == qc, num_qubits, file_precheck - # res == filename, depth, num_qubits res_qc_creation = qc_creation_watcher( create_scalable_qc, [benchmark, n] ) @@ -250,6 +248,7 @@ def generate_circuits_on_all_levels(qc, num_qubits, file_precheck): num_generated_circuits_t_indep = generate_target_indep_level_circuit( qc, num_qubits, file_precheck ) + if not num_generated_circuits_t_indep: return False @@ -257,11 +256,13 @@ def generate_circuits_on_all_levels(qc, num_qubits, file_precheck): qc, num_qubits, file_precheck ) - if not num_generated_circuits_t_dep and not num_generated_circuits_t_indep: + if num_generated_circuits_t_dep and num_generated_circuits_t_indep: + return num_generated_circuits_t_indep + num_generated_circuits_t_dep + elif num_generated_circuits_t_indep: + return num_generated_circuits_t_indep + else: return False - return num_generated_circuits_t_indep + num_generated_circuits_t_dep - def generate_target_indep_level_circuit( qc: QuantumCircuit, num_qubits: int, file_precheck @@ -649,6 +650,10 @@ def get_one_benchmark( args = parser.parse_args() print(args.file_name) + print("#### Start generating") create_benchmarks_from_config(args.file_name) - utils.postprocess_ocr_qasm_files() - utils.create_zip_file() + print("#### Start preprocessing") + # utils.postprocess_ocr_qasm_files() + print("#### Start zipping") + # utils.create_zip_file() + print("#### Generation ended") From 9e1a76eed78e5d1796cfdd932e3e74a869b03143 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 16 Aug 2022 10:44:43 +0200 Subject: [PATCH 055/231] =?UTF-8?q?=E2=9C=A8=20using=20qiskit=20indep=20co?= =?UTF-8?q?mpilation=20step=20now=20before=20tket=20steps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/tket_helper.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index c88c0fdbc..30866c494 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -147,18 +147,19 @@ def get_indep_level( # + " does not already exists and is newly created" # ) try: + gates = list(set(utils.get_openqasm_gates()) - set(["rccx"])) qc = transpile( qc, - basis_gates=utils.get_openqasm_gates(), + basis_gates=gates, seed_transpiler=10, optimization_level=0, ) qc_tket = qiskit_to_tk(qc) except Exception as e: - print(e) + print("TKET Exception Indep: ", e) return False - openqasm_gate_set_rebase = get_rebase("openqasm") - openqasm_gate_set_rebase.apply(qc_tket) + # openqasm_gate_set_rebase = get_rebase("openqasm") + # openqasm_gate_set_rebase.apply(qc_tket) FullPeepholeOptimise().apply(qc_tket) if return_qc: return qc_tket @@ -193,16 +194,17 @@ def get_native_gates_level( # ) try: + gates = list(set(utils.get_openqasm_gates()) - set(["rccx"])) qc = transpile( qc, - basis_gates=utils.get_openqasm_gates(), + basis_gates=gates, seed_transpiler=10, optimization_level=0, ) qc_tket = qiskit_to_tk(qc) except Exception as e: - print(e) + print("TKET Exception NativeGates: ", e) return False native_gatenames = get_rebase(gate_set_name, True) @@ -253,16 +255,17 @@ def get_mapped_level( # + " does not already exists and is newly created" # ) try: + gates = list(set(utils.get_openqasm_gates()) - set(["rccx"])) qc = transpile( qc, - basis_gates=utils.get_openqasm_gates(), + basis_gates=gates, seed_transpiler=10, optimization_level=0, ) qc_tket = qiskit_to_tk(qc) except Exception as e: - print(e) + print("TKET Exception Mapped: ", e) return False native_gatenames = get_rebase(gate_set_name, True) From 0f12293952e6cf477dc3589887d30aa800e944d7 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 16 Aug 2022 10:44:54 +0200 Subject: [PATCH 056/231] =?UTF-8?q?=E2=9C=A8=20improved=20call=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index f03be71ed..cb8a57a38 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -269,19 +269,18 @@ def generate_target_indep_level_circuit( ): num_generated_circuits = 0 - res = qiskit_helper.get_indep_level(qc, num_qubits, file_precheck) - if not res: - return False - else: + res_indep_qiskit = qiskit_helper.get_indep_level(qc, num_qubits, file_precheck) + if res_indep_qiskit: num_generated_circuits += 1 - res = tket_helper.get_indep_level(qc, num_qubits, file_precheck) - if not res: - return False - else: + res_indep_tket = tket_helper.get_indep_level(qc, num_qubits, file_precheck) + if res_indep_tket: num_generated_circuits += 1 - return num_generated_circuits + if not res_indep_qiskit and not res_indep_tket: + return False + else: + return num_generated_circuits def generate_target_dep_level_circuit( From 8058679ebf24c8ca2c2e8bd2564c2a9819d1e3cd Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 16 Aug 2022 13:20:04 +0200 Subject: [PATCH 057/231] =?UTF-8?q?=E2=9C=A8=20adjsuted=20docu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index cb8a57a38..ebcb92c5b 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -524,17 +524,16 @@ def get_one_benchmark( Keyword arguments: benchmark_name -- name of the to be generated benchmark - level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where + level -- Choice of level, either as a string ("alg", "indep", "gates" or "mapped") or as a number between 0-3 where 0 corresponds to "alg" level and 3 to "mapped" leve circuit_size -- Input for the benchmark creation, in most cases this is equal to the qubit number benchmark_instance_name -- Input selection for some benchmarks, namely "groundstate", "excitedstate" and "shor" - 0 corresponds to "alg" level and 3 to "mapped" level compiler -- "qiskit" or "tket" compiler_settings -- Optimization level for if compiler is qiskit (0-3), Line Placement or Graph Placement if compiler is tket (True or False) gate_set_name -- "ibm", "rigetti", "ionq", or "oqc" device_name -- "ibm_washington", "ibm_montreal", "aspen_m1", "ionq11", ""lucy"" Return values: - QuantumCircuit -- Representing the benchmark with the selected options, either as Qiskit::QuantumCircuit or Pytket::Circuit object + Quantum Circuit Object -- Representing the benchmark with the selected options, either as Qiskit::QuantumCircuit or Pytket::Circuit object """ init_module_paths() @@ -652,7 +651,7 @@ def get_one_benchmark( print("#### Start generating") create_benchmarks_from_config(args.file_name) print("#### Start preprocessing") - # utils.postprocess_ocr_qasm_files() + utils.postprocess_ocr_qasm_files() print("#### Start zipping") - # utils.create_zip_file() + utils.create_zip_file() print("#### Generation ended") From 6c4c483781b5268f4a3514826a7e14b80cd93bfc Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 16 Aug 2022 13:20:16 +0200 Subject: [PATCH 058/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20compression=20lv?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/src/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchviewer/src/backend.py b/benchviewer/src/backend.py index 895264f17..e909f7de0 100644 --- a/benchviewer/src/backend.py +++ b/benchviewer/src/backend.py @@ -419,7 +419,7 @@ def generate_zip_ephemeral_chunks( individualFile.name, data=MQTBENCH_ALL_ZIP.read(individualFile.name), compress_type=ZIP_DEFLATED, - compresslevel=1, + compresslevel=3, ) fileobj.hidden_seek(0) yield fileobj.read() From ddc2ccf6e05f864f8d710f320e0ada9993795c7b Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Tue, 16 Aug 2022 13:20:23 +0200 Subject: [PATCH 059/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20compression=20al?= =?UTF-8?q?go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mqt/bench/utils/utils.py b/mqt/bench/utils/utils.py index 85c57258e..979187f55 100644 --- a/mqt/bench/utils/utils.py +++ b/mqt/bench/utils/utils.py @@ -6,7 +6,7 @@ from datetime import date -from zipfile import ZipFile, ZIP_DEFLATED +from zipfile import ZipFile, ZIP_LZMA import networkx as nx @@ -361,7 +361,7 @@ def create_zip_file(): if filename.endswith(".qasm"): zf.write( os.path.join(dirname, filename), - compress_type=ZIP_DEFLATED, + compress_type=ZIP_LZMA, compresslevel=3, arcname=filename, ) From 1fe6cdd5a8730d357afae84858fb4a7cb53995f2 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 17 Aug 2022 12:15:23 +0200 Subject: [PATCH 060/231] =?UTF-8?q?=E2=9C=A8=20added=20generation=20watche?= =?UTF-8?q?r=20again=20for=20indep=20layer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index ebcb92c5b..2c9e702ce 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -269,11 +269,15 @@ def generate_target_indep_level_circuit( ): num_generated_circuits = 0 - res_indep_qiskit = qiskit_helper.get_indep_level(qc, num_qubits, file_precheck) + res_indep_qiskit = benchmark_generation_watcher( + qiskit_helper.get_indep_level, [qc, num_qubits, file_precheck] + ) if res_indep_qiskit: num_generated_circuits += 1 - res_indep_tket = tket_helper.get_indep_level(qc, num_qubits, file_precheck) + res_indep_tket = benchmark_generation_watcher( + tket_helper.get_indep_level, [qc, num_qubits, file_precheck] + ) if res_indep_tket: num_generated_circuits += 1 From 27844bb80f64bca2bb5eac42b6598abfd6002174 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 17 Aug 2022 13:41:08 +0200 Subject: [PATCH 061/231] =?UTF-8?q?=E2=9C=A8=20update=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.json b/config.json index a5d1392b3..5758d36f7 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { -"timeout": 300, +"timeout": 100, "benchmarks": [ { "name": "ae", @@ -127,7 +127,7 @@ "min_qubits": 3, "max_qubits": 130, "stepsize": 1, - "ancillary_mode": ["noancilla", "v-chain"] + "ancillary_mode": ["noancilla","v-chain"] }, { "name": "realamprandom", From 8124de582ba3e408c0a91795a6dad665788f43fb Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Wed, 17 Aug 2022 13:41:35 +0200 Subject: [PATCH 062/231] =?UTF-8?q?=E2=9C=A8=20improved=20generation=20log?= =?UTF-8?q?ic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/benchmark_generator.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/mqt/bench/benchmark_generator.py b/mqt/bench/benchmark_generator.py index 2c9e702ce..d30c586b4 100644 --- a/mqt/bench/benchmark_generator.py +++ b/mqt/bench/benchmark_generator.py @@ -120,7 +120,7 @@ def timeout_handler(signum, frame): # Custom signal handler try: qc, num_qubits, file_precheck = func(*args) except TimeoutException: - print("Calculation/Generation exceeded timeout limit for ", func, args[1:]) + print("Benchmark Creation exceeded timeout limit for ", func, args[1:]) return False except Exception as e: print("Something else went wrong: ", e) @@ -245,23 +245,17 @@ def generate_benchmark(benchmark): def generate_circuits_on_all_levels(qc, num_qubits, file_precheck): - num_generated_circuits_t_indep = generate_target_indep_level_circuit( + succes_generated_circuits_t_indep = generate_target_indep_level_circuit( qc, num_qubits, file_precheck ) - if not num_generated_circuits_t_indep: + if not succes_generated_circuits_t_indep: return False - num_generated_circuits_t_dep = generate_target_dep_level_circuit( + succes_generated_circuits_t_dep = generate_target_dep_level_circuit( qc, num_qubits, file_precheck ) - - if num_generated_circuits_t_dep and num_generated_circuits_t_indep: - return num_generated_circuits_t_indep + num_generated_circuits_t_dep - elif num_generated_circuits_t_indep: - return num_generated_circuits_t_indep - else: - return False + return True def generate_target_indep_level_circuit( @@ -281,10 +275,10 @@ def generate_target_indep_level_circuit( if res_indep_tket: num_generated_circuits += 1 - if not res_indep_qiskit and not res_indep_tket: + if num_generated_circuits == 0: return False else: - return num_generated_circuits + return True def generate_target_dep_level_circuit( @@ -372,7 +366,8 @@ def generate_target_dep_level_circuit( num_generated_benchmarks += 1 if num_generated_benchmarks == 0: return False - return num_generated_benchmarks + else: + return True def create_scalable_qc(benchmark, num_qubits, ancillary_mode=None): From 065969b604ab58f4ea4cdbed230825c3a9abae76 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 18 Aug 2022 15:15:15 +0200 Subject: [PATCH 063/231] =?UTF-8?q?=E2=9C=A8=20adjusted=20requirements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index bb964aa68..3b54f528f 100644 --- a/setup.py +++ b/setup.py @@ -27,16 +27,16 @@ url="https://github.com/cda-tum/mqtbench", keywords="mqt quantum benchmarking performance testing", install_requires=[ - "qiskit[visualization]==0.35.0", - "pandas==1.3.5", - "flask==2.1.2", - "networkx==2.8.3", - "pytest==7.1.1", + "qiskit[visualization]~=0.35.0", + "pandas~=1.3.5", + "flask~=2.1.2", + "networkx~=2.8.3", + "pytest~=7.1.1", ], extras_require={ "all": [ "qiskit_finance~=0.3.1", - "qiskit_machine-learning==0.4.0", + "qiskit_machine-learning~=0.4.0", "qiskit_nature~=0.3.1", "qiskit_optimization~=0.3.2", ], From 9a184adaa09ab2f88829803b46743baf858dd3d5 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 18 Aug 2022 16:18:27 +0200 Subject: [PATCH 064/231] =?UTF-8?q?=E2=9C=A8=20commented=20out=20not=20use?= =?UTF-8?q?d=20openqasm=20gate=20tket=20rebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mqt/bench/utils/tket_helper.py | 118 ++++++++++++++++----------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/mqt/bench/utils/tket_helper.py b/mqt/bench/utils/tket_helper.py index 30866c494..62bfbf170 100644 --- a/mqt/bench/utils/tket_helper.py +++ b/mqt/bench/utils/tket_helper.py @@ -27,65 +27,65 @@ def get_rebase(gate_set_name: str, get_gatenames: bool = False): return get_ibm_rebase(get_gatenames) elif gate_set_name == "rigetti": return get_rigetti_rebase(get_gatenames) - elif gate_set_name == "openqasm": - return get_openqasm_rebase(get_gatenames) - - -def get_openqasm_rebase(get_gatenames: bool = False): - if get_gatenames: - return utils.get_openqasm_gates() - else: - openqasm_rebase = auto_rebase_pass( - { - OpType.U3, - OpType.U2, - OpType.U1, - OpType.CX, - OpType.noop, - # "u0", - # u", - # "p", - OpType.X, - OpType.Y, - OpType.Z, - OpType.H, - OpType.S, - OpType.Sdg, - OpType.T, - OpType.Tdg, - OpType.Rx, - OpType.Ry, - OpType.Rz, - OpType.SX, - OpType.SXdg, - OpType.CX, - OpType.CZ, - OpType.CY, - OpType.SWAP, - OpType.CH, - OpType.CCX, - OpType.CSWAP, - OpType.CRx, - OpType.CRy, - OpType.CRz, - OpType.CU1, - # OpType.CPhase, - OpType.CU3, - OpType.CSX, - # "cu", - OpType.XXPhase, - OpType.ZZPhase, - # "rccx", - # "rc3x", - # "c3x", - # "c3sqrtx", - # "c4x", - OpType.Measure, - } - ) - - return openqasm_rebase - + #elif gate_set_name == "openqasm": + #return get_openqasm_rebase(get_gatenames) + +# +# def get_openqasm_rebase(get_gatenames: bool = False): +# if get_gatenames: +# return utils.get_openqasm_gates() +# else: +# openqasm_rebase = auto_rebase_pass( +# { +# OpType.U3, +# OpType.U2, +# OpType.U1, +# OpType.CX, +# OpType.noop, +# # "u0", +# # u", +# # "p", +# OpType.X, +# OpType.Y, +# OpType.Z, +# OpType.H, +# OpType.S, +# OpType.Sdg, +# OpType.T, +# OpType.Tdg, +# OpType.Rx, +# OpType.Ry, +# OpType.Rz, +# OpType.SX, +# OpType.SXdg, +# OpType.CX, +# OpType.CZ, +# OpType.CY, +# OpType.SWAP, +# OpType.CH, +# OpType.CCX, +# OpType.CSWAP, +# OpType.CRx, +# OpType.CRy, +# OpType.CRz, +# OpType.CU1, +# # OpType.CPhase, +# OpType.CU3, +# OpType.CSX, +# # "cu", +# OpType.XXPhase, +# OpType.ZZPhase, +# # "rccx", +# # "rc3x", +# # "c3x", +# # "c3sqrtx", +# # "c4x", +# OpType.Measure, +# } +# ) +# +# return openqasm_rebase +# def get_ionq_rebase(get_gatenames: bool = False): if get_gatenames: From 8a470b9078d54483588cd4d25f68542d229cac21 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 18 Aug 2022 17:59:42 +0200 Subject: [PATCH 065/231] =?UTF-8?q?=E2=9C=A8=20added=20automatic=20downloa?= =?UTF-8?q?d=20of=20suitable=20github=20asset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/src/backend.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/benchviewer/src/backend.py b/benchviewer/src/backend.py index e909f7de0..fa21d1dbe 100644 --- a/benchviewer/src/backend.py +++ b/benchviewer/src/backend.py @@ -153,6 +153,38 @@ def createDatabase(zip_file: ZipFile): def read_mqtbench_all_zip(): global MQTBENCH_ALL_ZIP huge_zip = Path("./static/files/qasm_output/MQTBench_all.zip") + + version_of_suitable_benchmark_zipfile = "v1.0.0" + # ask user if suitable file should be downloaded + # if yes: download + import requests, io, os + + response = input( + "Shall the benchmarks file suitable with this MQTBench version be downloaded? (Y/n) " + ) + if response.lower() == "y" or response == "": + print("Start downloading benchmarks...") + + url = ( + "https://api.github.com/repos/nquetschlich/test/releases/tags/" + + version_of_suitable_benchmark_zipfile + ) + response = requests.get(url) + zip_file_url = response.json()["assets"][0]["browser_download_url"] + + if not os.path.isdir("tmp_download"): + os.mkdir("tmp_download") + r = requests.get(zip_file_url) + + with open("tmp_download/MQTBench_all.zip", "wb") as f: + f.write(r.content) + os.replace( + "tmp_download/MQTBench_all.zip", + "static/files/test_automatic_download/MQTBench_all.zip", + ) + os.rmdir("tmp_download") + print("...completed!") + print("Reading in {} ({} bytes) ...".format(huge_zip.name, huge_zip.stat().st_size)) with huge_zip.open("rb") as zf: bytes = io.BytesIO(zf.read()) From d2c9285408d185d5ec3b1ba84ff599199e61b642 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Thu, 18 Aug 2022 18:00:00 +0200 Subject: [PATCH 066/231] =?UTF-8?q?=E2=9C=A8=20added=20python=20packaging?= =?UTF-8?q?=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/__init__.py | 1 + setup.py | 1 + 2 files changed, 2 insertions(+) diff --git a/benchviewer/__init__.py b/benchviewer/__init__.py index e69de29bb..aedc91710 100644 --- a/benchviewer/__init__.py +++ b/benchviewer/__init__.py @@ -0,0 +1 @@ +from .main import main as start_local_server diff --git a/setup.py b/setup.py index 3b54f528f..50b3b99cf 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,7 @@ setup( name="mqt.bench", packages=[ + "benchviewer", "mqt.bench", "mqt.bench.utils", "mqt.bench.benchmarks", From 99b0efc0b5d23b9926b793e34a550ebf63f4d369 Mon Sep 17 00:00:00 2001 From: Nils Quetschlich Date: Fri, 19 Aug 2022 09:00:32 +0200 Subject: [PATCH 067/231] =?UTF-8?q?=F0=9F=9A=9A=20moved=20benchviewer=20in?= =?UTF-8?q?to=20mqt=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchviewer/__init__.py | 1 - {benchviewer => mqt/benchviewer}/README.md | 0 mqt/benchviewer/__init__.py | 1 + {benchviewer => mqt/benchviewer}/main.py | 25 ++++---- .../benchviewer}/requirements.txt | 0 .../benchviewer}/src/__init__.py | 0 .../benchviewer}/src/backend.py | 59 +++++++++++------- .../benchviewer}/src/tests/__init__.py | 0 .../benchviewer}/src/tests/test_backend.py | 6 +- .../static/TUM_Logo_blau_rgb_s.svg | 0 .../benchviewer}/static/favicon.ico | Bin .../benchviewer}/static/files/algo_level.txt | 0 .../templates/benchmark_description.html | 2 +- .../benchviewer}/templates/description.html | 2 +- .../benchviewer}/templates/index.html | 2 +- .../benchviewer}/templates/legal.html | 2 +- {benchviewer => mqt/benchviewer}/wsgi.py | 0 17 files changed, 55 insertions(+), 45 deletions(-) delete mode 100644 benchviewer/__init__.py rename {benchviewer => mqt/benchviewer}/README.md (100%) create mode 100644 mqt/benchviewer/__init__.py rename {benchviewer => mqt/benchviewer}/main.py (96%) rename {benchviewer => mqt/benchviewer}/requirements.txt (100%) rename {benchviewer => mqt/benchviewer}/src/__init__.py (100%) rename {benchviewer => mqt/benchviewer}/src/backend.py (92%) rename {benchviewer => mqt/benchviewer}/src/tests/__init__.py (100%) rename {benchviewer => mqt/benchviewer}/src/tests/test_backend.py (98%) rename {benchviewer => mqt/benchviewer}/static/TUM_Logo_blau_rgb_s.svg (100%) rename {benchviewer => mqt/benchviewer}/static/favicon.ico (100%) rename {benchviewer => mqt/benchviewer}/static/files/algo_level.txt (100%) rename {benchviewer => mqt/benchviewer}/templates/benchmark_description.html (99%) rename {benchviewer => mqt/benchviewer}/templates/description.html (98%) rename {benchviewer => mqt/benchviewer}/templates/index.html (99%) rename {benchviewer => mqt/benchviewer}/templates/legal.html (98%) rename {benchviewer => mqt/benchviewer}/wsgi.py (100%) diff --git a/benchviewer/__init__.py b/benchviewer/__init__.py deleted file mode 100644 index aedc91710..000000000 --- a/benchviewer/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .main import main as start_local_server diff --git a/benchviewer/README.md b/mqt/benchviewer/README.md similarity index 100% rename from benchviewer/README.md rename to mqt/benchviewer/README.md diff --git a/mqt/benchviewer/__init__.py b/mqt/benchviewer/__init__.py new file mode 100644 index 000000000..b96465af5 --- /dev/null +++ b/mqt/benchviewer/__init__.py @@ -0,0 +1 @@ +from .main import start_server diff --git a/benchviewer/main.py b/mqt/benchviewer/main.py similarity index 96% rename from benchviewer/main.py rename to mqt/benchviewer/main.py index e5b930622..16a781b04 100644 --- a/benchviewer/main.py +++ b/mqt/benchviewer/main.py @@ -8,22 +8,29 @@ request, send_from_directory, ) -from src.backend import * +from mqt.benchviewer.src.backend import * from datetime import datetime import logging +app = Flask(__name__) +PREFIX = "/mqtbench/" + def init(): read_mqtbench_all_zip() init_database() - # logging.basicConfig(filename="/local/mqtbench/downloads.log", level=logging.INFO) -init() -app = Flask(__name__) +def start_server(): + app.run(debug=False) -PREFIX = "/mqtbench/" + +if __name__ == "__main__": + start_server() + + +init() @app.route(f"{PREFIX}/", methods=["POST", "GET"]) @@ -121,11 +128,3 @@ def get_num_benchmarks(): data = {"num_selected": 0} return jsonify(data) - - -def main(): - app.run(debug=True) - - -if __name__ == "__main__": - main() diff --git a/benchviewer/requirements.txt b/mqt/benchviewer/requirements.txt similarity index 100% rename from benchviewer/requirements.txt rename to mqt/benchviewer/requirements.txt diff --git a/benchviewer/src/__init__.py b/mqt/benchviewer/src/__init__.py similarity index 100% rename from benchviewer/src/__init__.py rename to mqt/benchviewer/src/__init__.py diff --git a/benchviewer/src/backend.py b/mqt/benchviewer/src/backend.py similarity index 92% rename from benchviewer/src/backend.py rename to mqt/benchviewer/src/backend.py index fa21d1dbe..0e7d6ce0d 100644 --- a/benchviewer/src/backend.py +++ b/mqt/benchviewer/src/backend.py @@ -152,38 +152,49 @@ def createDatabase(zip_file: ZipFile): def read_mqtbench_all_zip(): global MQTBENCH_ALL_ZIP - huge_zip = Path("./static/files/qasm_output/MQTBench_all.zip") + huge_zip = Path("mqt/benchviewer/static/files/qasm_output/MQTBench_all.zip") version_of_suitable_benchmark_zipfile = "v1.0.0" # ask user if suitable file should be downloaded # if yes: download import requests, io, os - response = input( - "Shall the benchmarks file suitable with this MQTBench version be downloaded? (Y/n) " + url = ( + "https://api.github.com/repos/nquetschlich/test/releases/tags/" + + version_of_suitable_benchmark_zipfile ) - if response.lower() == "y" or response == "": - print("Start downloading benchmarks...") - - url = ( - "https://api.github.com/repos/nquetschlich/test/releases/tags/" - + version_of_suitable_benchmark_zipfile - ) - response = requests.get(url) - zip_file_url = response.json()["assets"][0]["browser_download_url"] - - if not os.path.isdir("tmp_download"): - os.mkdir("tmp_download") - r = requests.get(zip_file_url) - - with open("tmp_download/MQTBench_all.zip", "wb") as f: - f.write(r.content) - os.replace( - "tmp_download/MQTBench_all.zip", - "static/files/test_automatic_download/MQTBench_all.zip", + response = requests.get(url) + if not response: + print("Suitable benchmarks cannot be downloaded, URL is faulty.") + else: + file_size = int((response.json()["assets"][0]["size"])) / 10e6 + response = input( + "Shall the benchmarks file suitable with this MQTBench ({} MB) version be downloaded? (Y/n)".format( + file_size + ) ) - os.rmdir("tmp_download") - print("...completed!") + if response.lower() == "y" or response == "": + print("Start downloading benchmarks...") + + url = ( + "https://api.github.com/repos/nquetschlich/test/releases/tags/" + + version_of_suitable_benchmark_zipfile + ) + response = requests.get(url) + zip_file_url = response.json()["assets"][0]["browser_download_url"] + + if not os.path.isdir("mqt/benchviewer/tmp_download"): + os.mkdir("mqt/benchviewer/tmp_download") + r = requests.get(zip_file_url) + + with open("mqt/benchviewer/tmp_download/MQTBench_all.zip", "wb") as f: + f.write(r.content) + os.replace( + "mqt/benchviewer/tmp_download/MQTBench_all.zip", + "mqt/benchviewer/static/files/test_automatic_download/MQTBench_all.zip", + ) + os.rmdir("mqt/benchviewer/tmp_download") + print("...completed!") print("Reading in {} ({} bytes) ...".format(huge_zip.name, huge_zip.stat().st_size)) with huge_zip.open("rb") as zf: diff --git a/benchviewer/src/tests/__init__.py b/mqt/benchviewer/src/tests/__init__.py similarity index 100% rename from benchviewer/src/tests/__init__.py rename to mqt/benchviewer/src/tests/__init__.py diff --git a/benchviewer/src/tests/test_backend.py b/mqt/benchviewer/src/tests/test_backend.py similarity index 98% rename from benchviewer/src/tests/test_backend.py rename to mqt/benchviewer/src/tests/test_backend.py index 10a4fbc86..d705a38e8 100644 --- a/benchviewer/src/tests/test_backend.py +++ b/mqt/benchviewer/src/tests/test_backend.py @@ -1,9 +1,9 @@ -from benchviewer.src import backend +from mqt.benchviewer.src import backend import pytest from pathlib import Path import io -from zipfile import ZipFile, ZIP_DEFLATED +from zipfile import ZipFile @pytest.mark.parametrize( @@ -234,7 +234,7 @@ def test_prepareFormInput(): def test_create_database(): - huge_zip = Path("./benchviewer/static/files/qasm_output/MQTBench_all.zip") + huge_zip = Path("mqt/benchviewer/static/files/qasm_output/MQTBench_all.zip") MQTBENCH_ALL_ZIP = None with huge_zip.open("rb") as zf: bytes = io.BytesIO(zf.read()) diff --git a/benchviewer/static/TUM_Logo_blau_rgb_s.svg b/mqt/benchviewer/static/TUM_Logo_blau_rgb_s.svg similarity index 100% rename from benchviewer/static/TUM_Logo_blau_rgb_s.svg rename to mqt/benchviewer/static/TUM_Logo_blau_rgb_s.svg diff --git a/benchviewer/static/favicon.ico b/mqt/benchviewer/static/favicon.ico similarity index 100% rename from benchviewer/static/favicon.ico rename to mqt/benchviewer/static/favicon.ico diff --git a/benchviewer/static/files/algo_level.txt b/mqt/benchviewer/static/files/algo_level.txt similarity index 100% rename from benchviewer/static/files/algo_level.txt rename to mqt/benchviewer/static/files/algo_level.txt diff --git a/benchviewer/templates/benchmark_description.html b/mqt/benchviewer/templates/benchmark_description.html similarity index 99% rename from benchviewer/templates/benchmark_description.html rename to mqt/benchviewer/templates/benchmark_description.html index 149c6d996..7a5b46ada 100644 --- a/benchviewer/templates/benchmark_description.html +++ b/mqt/benchviewer/templates/benchmark_description.html @@ -37,7 +37,7 @@