-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
363 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/)*.*","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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.