From 868b09f24e79d2b91ada306a965de177bd818dee Mon Sep 17 00:00:00 2001 From: gonfeco Date: Wed, 13 Sep 2023 14:27:32 +0200 Subject: [PATCH] linting in btc_01_pl --- .github/workflows/python-app.yml | 13 +- tests/test_btc_01_pl.py | 3 +- tests/test_btc_02_ae.py | 189 ++++++++++++++++++ tests/test_btc_03_qpe.py | 86 ++++++++ tnbs/BTC_02_AE/ae_sine_integral.py | 38 +++- tnbs/BTC_02_AE/my_benchmark_execution.py | 17 +- tnbs/BTC_03_QPE/QPE/qpe_rz.py | 11 +- tnbs/BTC_03_QPE/QPE/rz_lib.py | 9 +- tnbs/BTC_03_QPE/my_benchmark_execution.py | 11 +- tnbs/{BTC_01_PL => btc_01_pl}/PL/__init__.py | 0 .../PL/data_loading.py | 5 +- .../PL/load_probabilities.py | 5 +- .../PL/utils/__init__.py | 0 .../PL/utils/data_extracting.py | 0 .../PL/utils/utils.py | 0 tnbs/{BTC_01_PL => btc_01_pl}/__init__.py | 0 .../my_benchmark_execution.py | 24 +-- .../my_benchmark_info.py | 1 - .../my_benchmark_summary.py | 4 +- .../my_environment_info.py | 2 - .../neasqc_benchmark.py | 0 21 files changed, 363 insertions(+), 55 deletions(-) create mode 100644 tests/test_btc_02_ae.py create mode 100644 tests/test_btc_03_qpe.py rename tnbs/{BTC_01_PL => btc_01_pl}/PL/__init__.py (100%) rename tnbs/{BTC_01_PL => btc_01_pl}/PL/data_loading.py (98%) rename tnbs/{BTC_01_PL => btc_01_pl}/PL/load_probabilities.py (98%) rename tnbs/{BTC_01_PL => btc_01_pl}/PL/utils/__init__.py (100%) rename tnbs/{BTC_01_PL => btc_01_pl}/PL/utils/data_extracting.py (100%) rename tnbs/{BTC_01_PL => btc_01_pl}/PL/utils/utils.py (100%) rename tnbs/{BTC_01_PL => btc_01_pl}/__init__.py (100%) rename tnbs/{BTC_01_PL => btc_01_pl}/my_benchmark_execution.py (95%) rename tnbs/{BTC_01_PL => btc_01_pl}/my_benchmark_info.py (99%) rename tnbs/{BTC_01_PL => btc_01_pl}/my_benchmark_summary.py (99%) rename tnbs/{BTC_01_PL => btc_01_pl}/my_environment_info.py (99%) rename tnbs/{BTC_01_PL => btc_01_pl}/neasqc_benchmark.py (100%) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 5dc2a71..b0a1fae 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -25,15 +25,12 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - #- name: Lint with flake8 - # run: | - # # stop the build if there are Python syntax errors or undefined names - # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: show python path + - name: Lint with flake8 run: | - python -c "import sys; print('\n'.join(sys.path)); import os; print(os.getcwd())" + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | pytest diff --git a/tests/test_btc_01_pl.py b/tests/test_btc_01_pl.py index 14000a1..3314717 100644 --- a/tests/test_btc_01_pl.py +++ b/tests/test_btc_01_pl.py @@ -11,8 +11,7 @@ r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) sys.path.append(folder) -from tnbs.BTC_01_PL.my_benchmark_execution import KERNEL_BENCHMARK as PL_CLASS -from tnbs.BTC_01_PL.PL import * +from tnbs.btc_01_pl.my_benchmark_execution import KERNEL_BENCHMARK as PL_CLASS def create_folder(folder_name): diff --git a/tests/test_btc_02_ae.py b/tests/test_btc_02_ae.py new file mode 100644 index 0000000..d381416 --- /dev/null +++ b/tests/test_btc_02_ae.py @@ -0,0 +1,189 @@ +import os +import shutil +import sys +import pandas as pd +import numpy as np +import re + +folder = os.getcwd() +folder = re.sub( + r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) +sys.path.append(folder+"/tnbs/BTC_02_AE") +from my_benchmark_execution import KERNEL_BENCHMARK as AE_CLASS + + +def create_folder(folder_name): + """ + Check if folder exist. If not the function creates it + + Parameters + ---------- + + folder_name : str + Name of the folder + + Returns + ---------- + + folder_name : str + Name of the folder + """ + + # Check if the folder already exists + if not os.path.exists(folder_name): + # If it does not exist, create the folder + os.mkdir(folder_name) + print(f"Folder '{folder_name}' created.") + else: + print(f"Folder '{folder_name}' already exists.") + if folder_name.endswith('/') != True: + folder_name = folder_name + "/" + return folder_name + +def test_ae_iqae(): + + kernel_configuration ={ + "ae_type": "IQAE", + "epsilon": 0.001, + "alpha": 0.05, # This the alpha for the AE algorithm + "multiplexor": True, + "shots": 1000, + "qpu": "c", + "integrals": [0] + } + name = "AE_{}".format(kernel_configuration["ae_type"]) + + benchmark_arguments = { + #Pre benchmark configuration + "pre_benchmark": True, + "pre_samples": None, + "pre_save": True, + #Saving configuration + "save_append" : True, + "saving_folder": "./Results_IQAE/", + "benchmark_times": "{}_times_benchmark.csv".format(name), + "csv_results": "{}_benchmark.csv".format(name), + "summary_results": "{}_SummaryResults.csv".format(name), + #Computing Repetitions configuration + "alpha": None, + "min_meas": None, + "max_meas": 10, + "relative_error": None, + "absolute_error": None, + #List number of qubits tested + "list_of_qbits": [4], + } + + benchmark_arguments.update({"kernel_configuration": kernel_configuration}) + folder = create_folder(benchmark_arguments["saving_folder"]) + ae_bench = AE_CLASS(**benchmark_arguments) + ae_bench.exe() + filename = folder + benchmark_arguments["summary_results"] + a = pd.read_csv(filename, header=[0, 1], index_col=[0, 1]) + #print(a["absolute_error_sum"]["mean"]) + #print(100* list(a['KS']['mean'])[0]) + assert(100* list(a['absolute_error_sum']['mean'])[0] < 1.0) + shutil.rmtree(folder) + +def test_ae_mlae(): + + kernel_configuration ={ + "ae_type": "MLAE", + "schedule": [ + [1, 2, 4, 8, 12], + [100, 100, 100, 100, 100] + ], + "delta": 1.0e-7, + "ns": 10000, + "mcz_qlm": False, + "multiplexor": True, + "shots": 1000, + "qpu": "c", + "integrals": [0] + } + name = "AE_{}".format(kernel_configuration["ae_type"]) + + benchmark_arguments = { + #Pre benchmark configuration + "pre_benchmark": True, + "pre_samples": None, + "pre_save": True, + #Saving configuration + "save_append" : True, + "saving_folder": "./Results_MLAE/", + "benchmark_times": "{}_times_benchmark.csv".format(name), + "csv_results": "{}_benchmark.csv".format(name), + "summary_results": "{}_SummaryResults.csv".format(name), + #Computing Repetitions configuration + "alpha": None, + "min_meas": None, + "max_meas": 10, + "relative_error": None, + "absolute_error": None, + #List number of qubits tested + "list_of_qbits": [4], + } + + benchmark_arguments.update({"kernel_configuration": kernel_configuration}) + folder = create_folder(benchmark_arguments["saving_folder"]) + ae_bench = AE_CLASS(**benchmark_arguments) + ae_bench.exe() + filename = folder + benchmark_arguments["summary_results"] + a = pd.read_csv(filename, header=[0, 1], index_col=[0, 1]) + #print(a["absolute_error_sum"]["mean"]) + #print(100* list(a['KS']['mean'])[0]) + assert(100* list(a['absolute_error_sum']['mean'])[0] < 1.0) + shutil.rmtree(folder) + +def test_ae_rqae(): + + kernel_configuration ={ + "ae_type": "RQAE", + "epsilon": 0.01, + "gamma": 0.05, + "q": 1.2, + + "mcz_qlm": False, + "multiplexor": True, + "shots": 1000, + "qpu": "c", + "integrals": [0, 1] + } + name = "AE_{}".format(kernel_configuration["ae_type"]) + + benchmark_arguments = { + #Pre benchmark configuration + "pre_benchmark": True, + "pre_samples": None, + "pre_save": True, + #Saving configuration + "save_append" : True, + "saving_folder": "./Results_RQAE/", + "benchmark_times": "{}_times_benchmark.csv".format(name), + "csv_results": "{}_benchmark.csv".format(name), + "summary_results": "{}_SummaryResults.csv".format(name), + #Computing Repetitions configuration + "alpha": None, + "min_meas": None, + "max_meas": 10, + "relative_error": None, + "absolute_error": None, + #List number of qubits tested + "list_of_qbits": [4], + } + + benchmark_arguments.update({"kernel_configuration": kernel_configuration}) + folder = create_folder(benchmark_arguments["saving_folder"]) + ae_bench = AE_CLASS(**benchmark_arguments) + ae_bench.exe() + filename = folder + benchmark_arguments["summary_results"] + a = pd.read_csv(filename, header=[0, 1], index_col=[0, 1]) + print(a["absolute_error_sum"]["mean"]) + assert((a["absolute_error_sum"]["mean"] < 0.01).all()) + #print(100* list(a['KS']['mean'])[0]) + #assert(100* list(a['absolute_error_sum']['mean'])[0] < 1.0) + shutil.rmtree(folder) + +#test_ae_iqae() +#test_ae_mlae() +#test_ae_rqae() diff --git a/tests/test_btc_03_qpe.py b/tests/test_btc_03_qpe.py new file mode 100644 index 0000000..7b22343 --- /dev/null +++ b/tests/test_btc_03_qpe.py @@ -0,0 +1,86 @@ +import os +import shutil +import sys +import pandas as pd +import numpy as np +import re + +folder = os.getcwd() +folder = os.getcwd() +folder = re.sub( + r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) +sys.path.append(folder) +from tnbs.BTC_03_QPE.my_benchmark_execution import KERNEL_BENCHMARK + + +def create_folder(folder_name): + """ + Check if folder exist. If not the function creates it + + Parameters + ---------- + + folder_name : str + Name of the folder + + Returns + ---------- + + folder_name : str + Name of the folder + """ + + # Check if the folder already exists + if not os.path.exists(folder_name): + # If it does not exist, create the folder + os.mkdir(folder_name) + print(f"Folder '{folder_name}' created.") + else: + print(f"Folder '{folder_name}' already exists.") + if folder_name.endswith('/') != True: + folder_name = folder_name + "/" + return folder_name + +def test_qpe(): + + kernel_configuration = { + "angles" : ["random", 'exact'], + "auxiliar_qbits_number" : [8], + "qpu" : "c", #qlmass, python, c + "fidelity_error" : None, + "ks_error" : None, + "time_error": None + } + + benchmark_arguments = { + #Pre benchmark sttuff + "pre_benchmark": True, + "pre_samples": None, + "pre_save": True, + #Saving stuff + "save_append" : True, + "saving_folder": "./Results/", + "benchmark_times": "kernel_times_benchmark.csv", + "csv_results": "kernel_benchmark.csv", + "summary_results": "kernel_SummaryResults.csv", + #Computing Repetitions stuff + "alpha": None, + "min_meas": None, + "max_meas": None, + #List number of qubits tested + "list_of_qbits": [6], + } + + benchmark_arguments.update({"kernel_configuration": kernel_configuration}) + folder = create_folder(benchmark_arguments["saving_folder"]) + kernel_bench = KERNEL_BENCHMARK(**benchmark_arguments) + kernel_bench.exe() + filename = "./Results/kernel_SummaryResults.csv" + index_columns = [0, 1, 2, 3, 4, 5] + a = pd.read_csv(filename, header=[0, 1], index_col=index_columns) + a= a.reset_index() + assert((a[a['angle_method']=="exact"]['fidelity']['mean'] > 0.999).all()) + assert((a[a['angle_method']=="random"]['KS']['mean'] < 0.05).all()) + shutil.rmtree(folder) + +#test_qpe() diff --git a/tnbs/BTC_02_AE/ae_sine_integral.py b/tnbs/BTC_02_AE/ae_sine_integral.py index d86502b..0a3c711 100644 --- a/tnbs/BTC_02_AE/ae_sine_integral.py +++ b/tnbs/BTC_02_AE/ae_sine_integral.py @@ -2,16 +2,28 @@ Mandatory code for softaware implemetation of the Benchmark Test Case of AE kernel """ + +import sys +import os import json import time +import re +from copy import deepcopy import numpy as np import pandas as pd -from copy import deepcopy import sys -sys.path.append('../') -from QQuantLib.utils.benchmark_utils import combination_for_list -from QQuantLib.utils.qlm_solver import get_qpu -from QQuantLib.finance.quantum_integration import q_solve_integral + + +folder = os.getcwd() +folder = re.sub( + r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) +sys.path.append(folder) +sys.path.append(folder) + + +from tnbs.BTC_02_AE.QQuantLib.utils.benchmark_utils import combination_for_list +from tnbs.BTC_02_AE.QQuantLib.utils.qlm_solver import get_qpu +from tnbs.BTC_02_AE.QQuantLib.finance.quantum_integration import q_solve_integral def sine_integral(n_qbits, interval, ae_dictionary): """ @@ -165,19 +177,23 @@ def select_ae(ae_method): """ + folder_json = os.getcwd() + folder_json = re.sub( + r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark", folder) + folder_json = folder_json + "/tnbs/BTC_02_AE/jsons/" lista_ae_ = [] if ae_method == "MLAE": - lista_ae_.append("jsons/integral_mlae_configuration.json") + lista_ae_.append(folder_json + "integral_mlae_configuration.json") elif ae_method == "IQAE": - lista_ae_.append("jsons/integral_iqae_configuration.json") + lista_ae_.append(folder_json + "integral_iqae_configuration.json") elif ae_method == "RQAE": - lista_ae_.append("jsons/integral_rqae_configuration.json") + lista_ae_.append(folder_json + "integral_rqae_configuration.json") elif ae_method == "CQPEAE": - lista_ae_.append("jsons/integral_cqpeae_configuration.json") + lista_ae_.append(folder_json + "integral_cqpeae_configuration.json") elif ae_method == "IQPEAE": - lista_ae_.append("jsons/integral_iqpeae_configuration.json") + lista_ae_.append(folder_json + "integral_iqpeae_configuration.json") elif ae_method == "MCAE": - lista_ae_.append("jsons/integral_mcae_configuration.json") + lista_ae_.append(folder_json + "integral_mcae_configuration.json") else: raise ValueError( "ae_method MUST BE: MLAE, IQAE, RQAE, CQPEAE or IQPEAE") diff --git a/tnbs/BTC_02_AE/my_benchmark_execution.py b/tnbs/BTC_02_AE/my_benchmark_execution.py index 460cc53..c8911b7 100644 --- a/tnbs/BTC_02_AE/my_benchmark_execution.py +++ b/tnbs/BTC_02_AE/my_benchmark_execution.py @@ -2,15 +2,24 @@ Workflow configuration and execution for Benchmark Test Case of AE kernel """ +import sys +import os import json +import re from datetime import datetime +import itertools as it import pandas as pd +folder = os.getcwd() +folder = re.sub( + r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) +sys.path.append(folder) +from tnbs.BTC_02_AE.ae_sine_integral import sine_integral + def build_iterator(**kwargs): """ For building the iterator of the benchmark """ - import itertools as it list4int = [ kwargs['list_of_qbits'], @@ -56,7 +65,6 @@ def run_code(iterator_step, repetitions, stage_bench, **kwargs): n_qbits = iterator_step[0] interval = iterator_step[1] - from ae_sine_integral import sine_integral #Here the code for configuring and execute the benchmark kernel ae_configuration = kwargs.get("kernel_configuration") @@ -292,11 +300,12 @@ def exe(self): if __name__ == "__main__": - from ae_sine_integral import select_ae + from tnbs.BTC_02_AE.ae_sine_integral import select_ae - AE = "IQAE" + AE = "MLAE" #Setting the AE algorithm configuration ae_problem = select_ae(AE) + print(ae_problem) ae_problem.update({ "qpu": "c", diff --git a/tnbs/BTC_03_QPE/QPE/qpe_rz.py b/tnbs/BTC_03_QPE/QPE/qpe_rz.py index 279e767..e774255 100644 --- a/tnbs/BTC_03_QPE/QPE/qpe_rz.py +++ b/tnbs/BTC_03_QPE/QPE/qpe_rz.py @@ -6,12 +6,17 @@ """ import time +import sys +import os +import re import numpy as np import pandas as pd from scipy.stats import norm, entropy, chisquare, chi2 -import sys -sys.path.append('../') -import QPE.rz_lib as rz_lib +folder = os.getcwd() +folder = re.sub( + r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) +sys.path.append(folder) +from tnbs.BTC_03_QPE.QPE import rz_lib class QPE_RZ: """ diff --git a/tnbs/BTC_03_QPE/QPE/rz_lib.py b/tnbs/BTC_03_QPE/QPE/rz_lib.py index f1d9278..d1bf88a 100644 --- a/tnbs/BTC_03_QPE/QPE/rz_lib.py +++ b/tnbs/BTC_03_QPE/QPE/rz_lib.py @@ -5,11 +5,18 @@ Author: Gonzalo Ferro """ +import sys +import os +import re import numpy as np import pandas as pd import qat.lang.AQASM as qlm -from QPE.utils.qpe import CQPE +folder = os.getcwd() +folder = re.sub( + r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) +sys.path.append(folder) +from tnbs.BTC_03_QPE.QPE.utils.qpe import CQPE def get_qpu(qpu=None): """ diff --git a/tnbs/BTC_03_QPE/my_benchmark_execution.py b/tnbs/BTC_03_QPE/my_benchmark_execution.py index 7ae8521..49a7a0a 100644 --- a/tnbs/BTC_03_QPE/my_benchmark_execution.py +++ b/tnbs/BTC_03_QPE/my_benchmark_execution.py @@ -2,11 +2,20 @@ Template for generic Benchmark Test Case Workflow """ +import sys +import os +import re from datetime import datetime from copy import deepcopy import numpy as np import pandas as pd +folder = os.getcwd() +folder = re.sub( + r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) +sys.path.append(folder) +from tnbs.BTC_03_QPE.QPE.qpe_rz import QPE_RZ +from tnbs.BTC_03_QPE.QPE.rz_lib import get_qpu def build_iterator(**kwargs): """ @@ -48,8 +57,6 @@ def run_code(iterator_step, repetitions, stage_bench, **kwargs): Desired name for saving the results of the execution """ - from QPE.qpe_rz import QPE_RZ - from QPE.rz_lib import get_qpu # if n_qbits is None: # raise ValueError("n_qbits CAN NOT BE None") diff --git a/tnbs/BTC_01_PL/PL/__init__.py b/tnbs/btc_01_pl/PL/__init__.py similarity index 100% rename from tnbs/BTC_01_PL/PL/__init__.py rename to tnbs/btc_01_pl/PL/__init__.py diff --git a/tnbs/BTC_01_PL/PL/data_loading.py b/tnbs/btc_01_pl/PL/data_loading.py similarity index 98% rename from tnbs/BTC_01_PL/PL/data_loading.py rename to tnbs/btc_01_pl/PL/data_loading.py index df82982..abcada6 100644 --- a/tnbs/BTC_01_PL/PL/data_loading.py +++ b/tnbs/btc_01_pl/PL/data_loading.py @@ -18,15 +18,14 @@ """ -import sys import time import random import numpy as np import qat.lang.AQASM as qlm from qat.lang.models import KPTree from scipy.stats import norm -from tnbs.BTC_01_PL.PL.utils.utils import bitfield, left_conditional_probability, fwht -from tnbs.BTC_01_PL.PL.utils.data_extracting import get_results +from tnbs.btc_01_pl.PL.utils.utils import bitfield, left_conditional_probability, fwht +from tnbs.btc_01_pl.PL.utils.data_extracting import get_results def mask(number_qubits, index): diff --git a/tnbs/BTC_01_PL/PL/load_probabilities.py b/tnbs/btc_01_pl/PL/load_probabilities.py similarity index 98% rename from tnbs/BTC_01_PL/PL/load_probabilities.py rename to tnbs/btc_01_pl/PL/load_probabilities.py index 68f19f7..9a9f3b9 100644 --- a/tnbs/BTC_01_PL/PL/load_probabilities.py +++ b/tnbs/btc_01_pl/PL/load_probabilities.py @@ -6,16 +6,16 @@ import sys import os import time +import re import numpy as np import pandas as pd from scipy.stats import entropy, chisquare, chi2 -import re folder = os.getcwd() folder = re.sub( r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) sys.path.append(folder) -from tnbs.BTC_01_PL.PL.data_loading import get_theoric_probability, get_qlm_probability, \ +from tnbs.btc_01_pl.PL.data_loading import get_theoric_probability, get_qlm_probability, \ get_qpu @@ -197,4 +197,3 @@ def summary(self): prob_dens = LoadProbabilityDensity(**configuration) prob_dens.exe() print(prob_dens.pdf) - diff --git a/tnbs/BTC_01_PL/PL/utils/__init__.py b/tnbs/btc_01_pl/PL/utils/__init__.py similarity index 100% rename from tnbs/BTC_01_PL/PL/utils/__init__.py rename to tnbs/btc_01_pl/PL/utils/__init__.py diff --git a/tnbs/BTC_01_PL/PL/utils/data_extracting.py b/tnbs/btc_01_pl/PL/utils/data_extracting.py similarity index 100% rename from tnbs/BTC_01_PL/PL/utils/data_extracting.py rename to tnbs/btc_01_pl/PL/utils/data_extracting.py diff --git a/tnbs/BTC_01_PL/PL/utils/utils.py b/tnbs/btc_01_pl/PL/utils/utils.py similarity index 100% rename from tnbs/BTC_01_PL/PL/utils/utils.py rename to tnbs/btc_01_pl/PL/utils/utils.py diff --git a/tnbs/BTC_01_PL/__init__.py b/tnbs/btc_01_pl/__init__.py similarity index 100% rename from tnbs/BTC_01_PL/__init__.py rename to tnbs/btc_01_pl/__init__.py diff --git a/tnbs/BTC_01_PL/my_benchmark_execution.py b/tnbs/btc_01_pl/my_benchmark_execution.py similarity index 95% rename from tnbs/BTC_01_PL/my_benchmark_execution.py rename to tnbs/btc_01_pl/my_benchmark_execution.py index 51da37c..1cb6855 100644 --- a/tnbs/BTC_01_PL/my_benchmark_execution.py +++ b/tnbs/btc_01_pl/my_benchmark_execution.py @@ -4,18 +4,18 @@ import sys import os -import json +import re from datetime import datetime from copy import deepcopy import pandas as pd -import re +from scipy.stats import norm folder = os.getcwd() folder = re.sub( r"WP3_Benchmark/(?=WP3_Benchmark/)*.*","WP3_Benchmark/", folder) sys.path.append(folder) -from tnbs.BTC_01_PL.PL.load_probabilities import LoadProbabilityDensity, get_qpu +from tnbs.btc_01_pl.PL.load_probabilities import LoadProbabilityDensity, get_qpu def build_iterator(**kwargs): """ @@ -106,7 +106,6 @@ def compute_samples(**kwargs): DataFrame with the number of executions for each integration interval """ - from scipy.stats import norm #Configuration for sampling computations @@ -158,8 +157,8 @@ def summarize_results(**kwargs): Create summary with statistics """ - folder = kwargs.get("saving_folder") - csv_results = folder + kwargs.get("csv_results") + folder_ = kwargs.get("saving_folder") + csv_results = folder_ + kwargs.get("csv_results") #Code for summarize the benchamark results. Depending of the #kernel of the benchmark @@ -226,7 +225,7 @@ def __init__(self, **kwargs): self.metrics = None - def save(self, save, save_name, input_pdf, save_mode): + def save(self, save_, save_name, input_pdf, save_mode): """ For saving panda DataFrames to csvs @@ -241,7 +240,7 @@ def save(self, save, save_name, input_pdf, save_mode): save_mode: str saving mode: overwrite (w) or append (a) """ - if save: + if save_: with open(save_name, save_mode) as f_pointer: input_pdf.to_csv( f_pointer, @@ -281,7 +280,7 @@ def exe(self): step_iterator, samples_, 'benchmark', **self.kwargs ) save_name = self.saving_folder + save_name - self.save(self.save, save_name, metrics, self.save_type) + self.save(True, save_name, metrics, self.save_type) end_time = datetime.now().astimezone().isoformat() pdf_times = pd.DataFrame( [start_time, end_time], @@ -297,13 +296,13 @@ def exe(self): if __name__ == "__main__": - kernel_configuration = { + kernel_configuration_ = { "load_method" : "multiplexor", "qpu" : "c", #python, qlmass, default "relative_error": None, "absolute_error": None } - name = "PL_{}".format(kernel_configuration["load_method"]) + name = "PL_{}".format(kernel_configuration_["load_method"]) benchmark_arguments = { #Pre benchmark configuration @@ -325,7 +324,6 @@ def exe(self): } #Configuration for the benchmark kernel - benchmark_arguments.update({"kernel_configuration": kernel_configuration}) + benchmark_arguments.update({"kernel_configuration": kernel_configuration_}) ae_bench = KERNEL_BENCHMARK(**benchmark_arguments) ae_bench.exe() - diff --git a/tnbs/BTC_01_PL/my_benchmark_info.py b/tnbs/btc_01_pl/my_benchmark_info.py similarity index 99% rename from tnbs/BTC_01_PL/my_benchmark_info.py rename to tnbs/btc_01_pl/my_benchmark_info.py index fc77fe5..6825769 100644 --- a/tnbs/BTC_01_PL/my_benchmark_info.py +++ b/tnbs/btc_01_pl/my_benchmark_info.py @@ -304,4 +304,3 @@ def my_benchmark_info(**kwargs): print("\t Benchmark is Valid") except jsonschema.exceptions.ValidationError as ex: print(ex) - diff --git a/tnbs/BTC_01_PL/my_benchmark_summary.py b/tnbs/btc_01_pl/my_benchmark_summary.py similarity index 99% rename from tnbs/BTC_01_PL/my_benchmark_summary.py rename to tnbs/btc_01_pl/my_benchmark_summary.py index 9bf44bd..ed1d800 100644 --- a/tnbs/BTC_01_PL/my_benchmark_summary.py +++ b/tnbs/btc_01_pl/my_benchmark_summary.py @@ -4,8 +4,9 @@ Authors: Gonzalo Ferro """ -from collections import OrderedDict import psutil +from collections import OrderedDict +import pandas as pd def summarize_results(**kwargs): """ @@ -19,7 +20,6 @@ def summarize_results(**kwargs): #Metrics needed for reporting. Depend on the benchmark kernel #list_of_metrics = ["MRSE"] - import pandas as pd benchmark_file = kwargs.get("benchmark_file", None) pdf = pd.read_csv(benchmark_file, header=[0, 1], index_col=[0, 1]) pdf.reset_index(inplace=True) diff --git a/tnbs/BTC_01_PL/my_environment_info.py b/tnbs/btc_01_pl/my_environment_info.py similarity index 99% rename from tnbs/BTC_01_PL/my_environment_info.py rename to tnbs/btc_01_pl/my_environment_info.py index 7b2fb83..90e4274 100644 --- a/tnbs/BTC_01_PL/my_environment_info.py +++ b/tnbs/btc_01_pl/my_environment_info.py @@ -240,5 +240,3 @@ def my_QPUCPUConnection(**kwargs): print("\tQPUCPUConnection is Valid") except jsonschema.exceptions.ValidationError as ex: print(ex) - - diff --git a/tnbs/BTC_01_PL/neasqc_benchmark.py b/tnbs/btc_01_pl/neasqc_benchmark.py similarity index 100% rename from tnbs/BTC_01_PL/neasqc_benchmark.py rename to tnbs/btc_01_pl/neasqc_benchmark.py