From 2ba45a8d3ee3124380adb878b1eb3b156d09ae72 Mon Sep 17 00:00:00 2001 From: gonfeco Date: Mon, 11 Sep 2023 15:46:07 +0200 Subject: [PATCH] Added test files --- setup.py | 8 +++-- tests/test_btc_01_pl.py | 78 +++++++++++++++++++++++++++++++++++++++++ tests/test_my_lib.py | 28 --------------- tnbs/__init__.py | 24 ------------- 4 files changed, 83 insertions(+), 55 deletions(-) create mode 100644 tests/test_btc_01_pl.py delete mode 100644 tests/test_my_lib.py delete mode 100644 tnbs/__init__.py diff --git a/setup.py b/setup.py index 5cd8c64..3f06f13 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,8 @@ from setuptools import setup, find_packages from setuptools.command.test import test as TestCommand +sys.path.append("tnbs/BTC_01_PL") + class PyTest(TestCommand): """ A test command to run pytest on a the full repository. @@ -23,13 +25,13 @@ def run_tests(self): sys.exit(errno) setup( - name="mylib", + name="TNBS", version="0.0.1", - author="XXX", + author="Gonzalo Ferro", license="European Union Public License 1.2", packages=find_packages(), - install_requires=["numpy"], + install_requires=["numpy", "pandas", "myqlm", "matplotlib", "scipy"], # Don't change these two lines tests_require=["pytest"], cmdclass={'test': PyTest}, diff --git a/tests/test_btc_01_pl.py b/tests/test_btc_01_pl.py new file mode 100644 index 0000000..fab3645 --- /dev/null +++ b/tests/test_btc_01_pl.py @@ -0,0 +1,78 @@ +import os +import shutil +import sys +import pandas as pd +import numpy as np + +sys.path.append("../tnbs/BTC_01_PL") +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_pl(): + kernel_configuration = { + "load_method" : "multiplexor", + "qpu" : "c", #python, qlmass, default + "relative_error": None, + "absolute_error": None + } + name = "PL_{}".format(kernel_configuration["load_method"]) + print(os.getcwdb()) + + benchmark_arguments = { + #Pre benchmark configuration + "pre_benchmark": True, + "pre_samples": None, + "pre_save": False, + #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": 10, + "max_meas": 15, + #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(100* list(a['KS']['mean'])[0]) + assert(100* list(a['KS']['mean'])[0] < 1.0) + + shutil.rmtree(folder) +test_pl() diff --git a/tests/test_my_lib.py b/tests/test_my_lib.py deleted file mode 100644 index e56af50..0000000 --- a/tests/test_my_lib.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding : utf-8 -*- - -""" -Test for this module -""" - - -# from my_lib import some_function, MyClass -# -# -# class TestMyClass: -# """ -# Testing MyClass -# """ -# -# def test_instantiation(self): -# """ -# Testing the constructor -# """ -# MyClass(1, 1, 2) -# MyClass() -# -# -# def test_some_fucntion(): -# """ -# Testing some_function -# """ -# assert 4 == some_function(2) diff --git a/tnbs/__init__.py b/tnbs/__init__.py deleted file mode 100644 index 9d6c379..0000000 --- a/tnbs/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding : utf-8 -*- - -""" -Modules have doctrings! -""" - - -def some_function(some_integer): - """ - Functions have docstrings. - - Variable and functions are named in snake case - """ - return 2 * some_integer - - -class MyClass: - """ - Classes have docstrings. - Classes are named in camel case. - """ - - def __init__(self, *args): - pass