Skip to content

Commit

Permalink
Fixed Test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
gonfeco committed Sep 12, 2023
1 parent 3079546 commit 8889043
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 3 deletions.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand

sys.path.append("tnbs/BTC_01_PL")
#sys.path.append("tnbs/BTC_01_PL")
#sys.path.append("tnbs/BTC_02_AE")
#sys.path.append("tnbs/BTC_03_QPE")

class PyTest(TestCommand):
"""
Expand Down
8 changes: 6 additions & 2 deletions tests/test_btc_01_pl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import sys
import pandas as pd
import numpy as np
import re

sys.path.append("../tnbs/BTC_01_PL")
folder = os.getcwd()
folder = re.sub(r"WP3_Benchmark/.*", "WP3_Benchmark/", folder)
folder = folder + "tnbs/BTC_01_PL"
sys.path.append(folder)
from my_benchmark_execution import KERNEL_BENCHMARK


Expand Down Expand Up @@ -75,4 +79,4 @@ def test_pl():
assert(100* list(a['KS']['mean'])[0] < 1.0)

shutil.rmtree(folder)
test_pl()
#test_pl()
189 changes: 189 additions & 0 deletions tests/test_btc_02_ae.py
Original file line number Diff line number Diff line change
@@ -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/", folder)
folder = folder + "tnbs/BTC_02_AE"
sys.path.append(folder)
from 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_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/",
"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 = KERNEL_BENCHMARK(**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/",
"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 = KERNEL_BENCHMARK(**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/",
"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 = KERNEL_BENCHMARK(**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()
85 changes: 85 additions & 0 deletions tests/test_btc_03_qpe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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/", folder)
folder = folder + "tnbs/BTC_03_QPE"
sys.path.append(folder)
from 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()

0 comments on commit 8889043

Please sign in to comment.