Hi @qiqihannah,
Thanks for sharing Quito's source code.
To the best of my knowledge there are two ways to run Quito on a given ini file:
Option (a), i.e., using https://github.com/Simula-COMPLEX/quito/blob/main/Quito_CoverageRunning/quito.py:
python quito.py
# And then press 3
# And then give Quito the path to the ini file
or Option (b), i.e., using https://github.com/Simula-COMPLEX/quito/blob/main/ex3/quito.py:
from quito.quito_coverage import quito
quito('__PATH_TO_THE_INI_FILE__')
Besides the obvious difference (i.e., Option (a) requires one to manually provide the necessary inputs and Option (b) could be automatized/parameterized to any ini file), there are a couple other major differences. Please find below the diff between https://github.com/Simula-COMPLEX/quito/blob/main/Quito_CoverageRunning/quito.py vs https://github.com/Simula-COMPLEX/quito/blob/main/ex3/quito.py. (Note: I've normalized functions names between both versions, organized imports, ..., so that we could focus on the two important differences.)
diff --git a/https://github.com/Simula-COMPLEX/quito/blob/main/Quito_CoverageRunning/quito.py b/https://github.com/Simula-COMPLEX/quito/blob/main/ex3/quito.py
index 6b380b2..0d2dfc6 100644
--- a/https://github.com/Simula-COMPLEX/quito/blob/main/Quito_CoverageRunning/quito.py
+++ b/https://github.com/Simula-COMPLEX/quito/blob/main/ex3/quito.py
@@ -16,6 +16,7 @@ import os.path
import importlib
import time
import warnings
+from scipy.stats import wilcoxon
K = 200
M = 20
@@ -26,20 +27,13 @@ T1 = 0
T2 = 0
START = 0
-curPath = os.path.abspath(os.path.dirname(__file__))
-rootPath = os.path.split(curPath)[0]
-sys.path.append(os.path.split(rootPath)[0])
-if sys.platform.startswith('win32'):
- ROOT='\\'
-elif sys.platform.startswith('linux'):
- ROOT='/'
-elif sys.platform.startswith('darwin'):
- ROOT='/'
-from rpy2 import robjects as robjects
-import logging
-from rpy2.rinterface_lib.callbacks import logger as rpy2_logger
-rpy2_logger.setLevel(logging.ERROR) # will display errors, but not warnings
+ROOT = '/'
+def quito(
+ con_file: str
+):
+ warnings.filterwarnings('ignore')
+ _quito_run(con_file)
def _check_unique(l):
return len(l) == len(set(l))
@@ -133,7 +127,7 @@ def _execute_quantum_program(inputID, outputID, num_qubit, i, module_name):
module = importlib.import_module(module_name)
run_method = getattr(module,"run")
run_method(qc)
- result = execute(qc, Aer.get_backend('qasm_simulator'), shots=1).result().get_counts(qc)
+ result = execute(qc, Aer.get_backend('aer_simulator'), shots=1).result().get_counts(qc)
return result
def _check_same(l,value):
@@ -160,18 +154,9 @@ def _wilcoxon(fre,p):
elif _check_same(fre[i],p[i]) == True:
pvalue.append(1)
else:
- fre_r = robjects.FloatVector(fre[i])
- # print('fre='+str(fre[i]))
- # print('p='+str(p[i]))
- robjects.r('''
- wtest<-function(data,exp,c_level){
- test_result <- wilcox.test(data, mu = exp, conf.int = TRUE, conf.level = 1-c_level)
- pvalue = test_result$p.value
- return (pvalue)
- }
- ''')
- t = robjects.r['wtest'](fre_r, p[i], C_LEVEL)
- pvalue.append(t[0])
+ fre_np = np.array(fre[i], dtype=float)
+ result = wilcoxon(fre_np, correction=True, y=np.repeat(p[i], len(fre[i])))
+ pvalue.append(result[1])
return pvalue
def _judge_ass_result(inputs, outputs, pvalue, f):
@@ -961,11 +946,10 @@ def check_bin(bin_str, n):
_end_running()
-def quito_run():
+def _quito_run(root_con):
global START
- print("please enter the root of your configuration file.(.ini file)")
#get configuration file
- root_con = input()
+ # root_con = input()
START = time.time()
if os.path.isfile(root_con) == True:
config = configparser.ConfigParser(allow_no_value=True)
@@ -1112,133 +1096,5 @@ def quito_run():
elif coverage_criterion == 'IOC':
input_output_coverage_partial(inputID, valid_input, valid_output, num_qubit, outputID, p, module_name, program_folder)
-def user_input():
- print('\n')
- text1 = "1. Check the template of the configuration file.(.ini file)"
- print(text1)
- print("\n")
- text2 = "2. Check the example of the configuration file.(.ini file)"
- print(text2)
- print('\n')
- text3 = "3. Upload your configuration.(.ini file)"
- print(text3)
- print('\n')
- print("Your choice?[1/2/3]",end=' ')
- user_choice = input()
- print('\n')
- return user_choice
-
-def template_file():
- print("The template is shown below:")
- program = '''
-[program]
-root=
-;(Required)
-;Description: The absolute root of your quantum program file.
-num_qubit=
-;(Required)
-;Description: The total number of qubit of your quantum program.
-inputID=
-;(Required)
-;Description: The ID of input qubits.
-outputID=
-;(Required)
-;Description: The ID of output qubits which are the qubits to be measured.
-;Format: A non-repeating sequence separated by commas.
- '''
- quito_configuration = '''
-[quito_configuration]
-coverage_criterion=
-;Description: The coverage criterion you choose.
-;Choice: IC/OC/IOC
-K=
-;(Optional)
-;Description: The total number of test suites, K=200 by default.
-M=
-;(Optional)
-;Description: The number of test suite groups, M=20 by default.
-BUDGET=
-;(Optional)
-;Description: The budget of the number of test cases in one test suite, BUDGET=10*number of inputs by default.
-confidence_level=
-;(Optional)
-;Description: The confidence level for statistical test, confidence_level=0.01 by default.
-statistical_test=
-;(Optional)
-;Description: The statistical test for assessment, statistical_test=one-sample Wilcoxon signed rank test by default.
-'''
- program_specification_category = '''
-[program_specification_category]
-ps_category=
-;(Required) Description: The category of your program specification. (full/partial/no)
-'''
- program_specification = '''
-[program_specification]
-;(Required for full and partial program specification)
-;Description: The program specification.
-;Format:input string,output string=probability
-'''
- print(program)
- print(quito_configuration)
- print(program_specification_category)
- print(program_specification)
- print('\n')
-def example_file():
- print("The example is shown below:")
- example = '''
-[program]
-root=C:\program_run.py
-num_qubit=3
-inputID=0,1
-outputID=2
-
-[program_specification_category]
-ps_category=full
-
-[quito_configuration]
-coverage_criterion=IC
-K=200
-M=10
-BUDGET=20
-confidence_level=0.01
-statistical_test=one-sample Wilcoxon signed rank test
-
-[program_specification]
-01,1=0.5
-01,0=0.5
-00,1=1
-11,1=1
-10,1=0.5
-10,0=0.5
-'''
- print(example)
-
-if __name__ == '__main__':
- warnings.filterwarnings('ignore')
- print("".center(60,"="))
- print('\n')
- print("Welcome to Quito".center(60))
- print('\n')
- print("".center(60,"="))
- user_choice = user_input()
- while user_choice != '3':
- if user_choice != '1' and user_choice != '2':
- print("Error: Please type in '1', '2' or '3'.")
- user_choice = user_input()
- elif user_choice == '1':
- print("template")
- template_file()
- user_choice = user_input()
- elif user_choice == '2':
- print("example")
- example_file()
- user_choice = user_input()
- if user_choice == '3':
- #start = time.time()
- quito_run()
- end = time.time()
- T1 = end - START
- print('\n')
- print("The total run time is "+"{:.2f}".format(T1)+"s.")
- print('The execution time of the quantum program is ' + "{:.2f}".format(T2) + "s.")
Difference 1
Are both implementations equivalent? If not, which one should I use? (Personally, I prefer not to rely on R, given Quito is a Python-based library.)
Difference 2
Are they equivalent in the sense that I would have the same result with either backend?
Hi @qiqihannah,
Thanks for sharing Quito's source code.
To the best of my knowledge there are two ways to run Quito on a given
inifile:Option (a), i.e., using https://github.com/Simula-COMPLEX/quito/blob/main/Quito_CoverageRunning/quito.py:
or Option (b), i.e., using https://github.com/Simula-COMPLEX/quito/blob/main/ex3/quito.py:
Besides the obvious difference (i.e., Option (a) requires one to manually provide the necessary inputs and Option (b) could be automatized/parameterized to any
inifile), there are a couple other major differences. Please find below the diff between https://github.com/Simula-COMPLEX/quito/blob/main/Quito_CoverageRunning/quito.py vs https://github.com/Simula-COMPLEX/quito/blob/main/ex3/quito.py. (Note: I've normalized functions names between both versions, organized imports, ..., so that we could focus on the two important differences.)Difference 1
Are both implementations equivalent? If not, which one should I use? (Personally, I prefer not to rely on R, given Quito is a Python-based library.)
Difference 2
qasm_simulatoras backend.aer_simulatoras backend.Are they equivalent in the sense that I would have the same result with either backend?