lazyqml 2.0.4__py2.py3-none-any.whl → 3.0.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lazyqml/Factories/Circuits/AmplitudeEmbedding.py +1 -1
- lazyqml/Factories/Circuits/HCzRx.py +1 -1
- lazyqml/Factories/Circuits/HardwareEfficient.py +1 -1
- lazyqml/Factories/Circuits/RxEmbedding.py +1 -1
- lazyqml/Factories/Circuits/RyEmbedding.py +1 -1
- lazyqml/Factories/Circuits/RzEmbedding.py +1 -1
- lazyqml/Factories/Circuits/TreeTensor.py +1 -1
- lazyqml/Factories/Circuits/TwoLocal.py +1 -1
- lazyqml/Factories/Circuits/ZzEmbedding.py +1 -1
- lazyqml/Factories/Circuits/fCircuits.py +10 -10
- lazyqml/Factories/Dispatchers/Dispatcher.py +264 -85
- lazyqml/Factories/Models/Hybrid.py +460 -0
- lazyqml/Factories/Models/QNNBag.py +6 -6
- lazyqml/Factories/Models/QNNTorch.py +8 -8
- lazyqml/Factories/Models/QSVM.py +3 -3
- lazyqml/Factories/Models/_QNNPennylane.py +4 -4
- lazyqml/Factories/Models/fModels.py +4 -4
- lazyqml/Factories/Preprocessing/Pca.py +2 -2
- lazyqml/Factories/Preprocessing/Sanitizer.py +2 -2
- lazyqml/Factories/Preprocessing/fPreprocessing.py +5 -24
- lazyqml/Global/globalEnums.py +3 -1
- lazyqml/Interfaces/iAnsatz.py +1 -1
- lazyqml/Utils/Utils.py +203 -84
- lazyqml/Utils/Validator.py +4 -7
- lazyqml/__init__.py +1 -1
- lazyqml/lazyqml.py +54 -49
- lazyqml-3.0.0.dist-info/LICENSE +21 -0
- {lazyqml-2.0.4.dist-info → lazyqml-3.0.0.dist-info}/METADATA +48 -35
- lazyqml-3.0.0.dist-info/RECORD +40 -0
- {lazyqml-2.0.4.dist-info → lazyqml-3.0.0.dist-info}/WHEEL +1 -1
- lazyqml/.lazyqmlP.py +0 -293
- lazyqml/.lazyqmlVote.py +0 -303
- lazyqml/Factories/Circuits/_Qkernel.py +0 -16
- lazyqml/Factories/Circuits/_Qnn.py +0 -17
- lazyqml/Factories/Dispatchers/DispatcherCV.py +0 -143
- lazyqml/Factories/Dispatchers/DispatcherNumba.py +0 -226
- lazyqml/Factories/Dispatchers/_Dispatcher.py +0 -188
- lazyqml/Factories/Dispatchers/_DispatcherMultiprocessing.py +0 -201
- lazyqml/Factories/Dispatchers/_QNNBagdispatcher.py +0 -2
- lazyqml/Factories/Dispatchers/_QNNdispatcher.py +0 -2
- lazyqml/Factories/Dispatchers/_QSVMdispatcher.py +0 -112
- lazyqml/Factories/Dispatchers/__Dispatcher.py +0 -193
- lazyqml/Factories/Preprocessing/_PcaAmp.py +0 -22
- lazyqml/Factories/Preprocessing/_PcaTree.py +0 -22
- lazyqml/Factories/Preprocessing/_PcaTreeAmp.py +0 -22
- lazyqml/Lanza copy.sh +0 -32
- lazyqml/Lanza.sh +0 -21
- lazyqml/mem.py +0 -85
- lazyqml-2.0.4.dist-info/RECORD +0 -56
- {lazyqml-2.0.4.dist-info → lazyqml-3.0.0.dist-info}/AUTHORS.rst +0 -0
- /lazyqml-2.0.4.dist-info/LICENSE → /lazyqml-3.0.0.dist-info/LICENSE copy +0 -0
- {lazyqml-2.0.4.dist-info → lazyqml-3.0.0.dist-info}/entry_points.txt +0 -0
- {lazyqml-2.0.4.dist-info → lazyqml-3.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Importing Enums
|
|
2
|
-
from
|
|
2
|
+
from Global.globalEnums import Ansatzs, Embedding
|
|
3
3
|
# Importing Ansatzs
|
|
4
|
-
from
|
|
5
|
-
from
|
|
6
|
-
from
|
|
7
|
-
from
|
|
4
|
+
from Factories.Circuits.TwoLocal import *
|
|
5
|
+
from Factories.Circuits.HardwareEfficient import *
|
|
6
|
+
from Factories.Circuits.TreeTensor import *
|
|
7
|
+
from Factories.Circuits.HCzRx import *
|
|
8
8
|
# Importing Embeddings
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
from
|
|
9
|
+
from Factories.Circuits.RxEmbedding import *
|
|
10
|
+
from Factories.Circuits.RyEmbedding import *
|
|
11
|
+
from Factories.Circuits.RzEmbedding import *
|
|
12
|
+
from Factories.Circuits.ZzEmbedding import *
|
|
13
|
+
from Factories.Circuits.AmplitudeEmbedding import *
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class CircuitFactory:
|
|
@@ -1,90 +1,233 @@
|
|
|
1
|
-
|
|
1
|
+
# Imports
|
|
2
2
|
import numpy as np
|
|
3
3
|
import pandas as pd
|
|
4
4
|
import math
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import multiprocessing as mp
|
|
6
|
+
import os
|
|
7
|
+
import torch
|
|
8
|
+
|
|
9
|
+
# Importing from
|
|
10
|
+
# Internal Dependencies
|
|
11
|
+
from Utils.Utils import *
|
|
12
|
+
from Factories.Models.fModels import *
|
|
13
|
+
from Factories.Preprocessing.fPreprocessing import *
|
|
14
|
+
from Utils.Utils import printer
|
|
15
|
+
# External Libraries
|
|
7
16
|
from sklearn.metrics import f1_score, accuracy_score, balanced_accuracy_score
|
|
8
|
-
import
|
|
9
|
-
from
|
|
17
|
+
from multiprocessing import Queue, Process, Pool, Manager
|
|
18
|
+
from statistics import mean
|
|
19
|
+
from collections import defaultdict
|
|
20
|
+
from time import time, sleep
|
|
10
21
|
|
|
11
22
|
class Dispatcher:
|
|
12
|
-
def __init__(self, sequential=False, threshold=
|
|
23
|
+
def __init__(self, sequential=False, threshold=22, time=True, folds=10, repeats=5):
|
|
13
24
|
self.sequential = sequential
|
|
14
25
|
self.threshold = threshold
|
|
15
26
|
self.timeM = time
|
|
27
|
+
self.fold = folds
|
|
28
|
+
self.repeat = repeats
|
|
16
29
|
|
|
17
|
-
def execute_model(self, model_factory_params, X_train, y_train, X_test, y_test, predictions,
|
|
30
|
+
def execute_model(self, model_factory_params, X_train, y_train, X_test, y_test, predictions, customMetric):
|
|
18
31
|
model = ModelFactory().getModel(**model_factory_params)
|
|
19
32
|
preds = []
|
|
20
|
-
|
|
33
|
+
accuracy, b_accuracy, f1, custom = 0, 0, 0, 0
|
|
21
34
|
custom = None
|
|
22
35
|
|
|
23
|
-
start = time
|
|
24
|
-
for _ in range(runs):
|
|
25
|
-
model.fit(X=X_train, y=y_train)
|
|
26
|
-
y_pred = model.predict(X=X_test)
|
|
27
|
-
|
|
28
|
-
accuracyR += accuracy_score(y_test, y_pred, normalize=True)
|
|
29
|
-
b_accuracyR += balanced_accuracy_score(y_test, y_pred)
|
|
30
|
-
f1R += f1_score(y_test, y_pred, average="weighted")
|
|
31
|
-
if customMetric is not None:
|
|
32
|
-
customR += customMetric(y_test, y_pred)
|
|
36
|
+
start = time()
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
model.fit(X=X_train, y=y_train)
|
|
39
|
+
y_pred = model.predict(X=X_test)
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
b_accuracy = b_accuracyR / runs
|
|
40
|
-
f1 = f1R / runs
|
|
41
|
+
accuracy += accuracy_score(y_test, y_pred, normalize=True)
|
|
42
|
+
b_accuracy += balanced_accuracy_score(y_test, y_pred)
|
|
43
|
+
f1 = f1_score(y_test, y_pred, average="weighted")
|
|
41
44
|
if customMetric is not None:
|
|
42
|
-
custom =
|
|
45
|
+
custom = customMetric(y_test, y_pred)
|
|
46
|
+
|
|
47
|
+
exeT = time() - start
|
|
43
48
|
|
|
44
49
|
return model_factory_params['Nqubits'], model_factory_params['model'], model_factory_params['Embedding'], model_factory_params['Ansatz'], model_factory_params['Max_features'], exeT, accuracy, b_accuracy, f1, custom, preds
|
|
45
50
|
|
|
51
|
+
|
|
52
|
+
def process_gpu_task(self, queue, results):
|
|
53
|
+
torch.set_num_threads(1)
|
|
54
|
+
torch.set_num_interop_threads(1)
|
|
55
|
+
|
|
56
|
+
while not queue.empty():
|
|
57
|
+
try:
|
|
58
|
+
item = queue.get_nowait()
|
|
59
|
+
|
|
60
|
+
results.append(self.execute_model(*item[1])) # Store results if needed
|
|
61
|
+
except queue.Empty:
|
|
62
|
+
break
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def process_cpu_task(self,cpu_queue, gpu_queue, results):
|
|
66
|
+
torch.set_num_interop_threads(1)
|
|
67
|
+
torch.set_num_threads(1)
|
|
68
|
+
numProcs = psutil.cpu_count(logical=False)
|
|
69
|
+
total_memory = calculate_free_memory()
|
|
70
|
+
available_memory = total_memory
|
|
71
|
+
available_cores = numProcs
|
|
72
|
+
|
|
73
|
+
# Lock para el acceso seguro a los recursos compartidos
|
|
74
|
+
manager = Manager()
|
|
75
|
+
resource_lock = manager.Lock()
|
|
76
|
+
|
|
77
|
+
while not cpu_queue.empty():
|
|
78
|
+
try:
|
|
79
|
+
# Determinar número de cores a usar basado en el estado de gpu_queue
|
|
80
|
+
if gpu_queue.empty():
|
|
81
|
+
max_cores = numProcs
|
|
82
|
+
else:
|
|
83
|
+
max_cores = max(1, numProcs - 1)
|
|
84
|
+
|
|
85
|
+
current_batch = []
|
|
86
|
+
current_cores = 0
|
|
87
|
+
|
|
88
|
+
# Recolectar items para procesar mientras haya recursos disponibles
|
|
89
|
+
while current_cores < max_cores and not cpu_queue.empty():
|
|
90
|
+
try:
|
|
91
|
+
item = cpu_queue.get_nowait()
|
|
92
|
+
# printer.print(f"ITEM CPU: {item[0]}")
|
|
93
|
+
_, _, _, _, _, _, _, mem_model = item[0]
|
|
94
|
+
|
|
95
|
+
# Verificar si hay recursos suficientes
|
|
96
|
+
with resource_lock:
|
|
97
|
+
if available_memory >= mem_model and available_cores >= 1:
|
|
98
|
+
# printer.print(f"Available Resources - Memory: {available_memory}, Cores: {available_cores}")
|
|
99
|
+
available_memory -= mem_model
|
|
100
|
+
available_cores -= 1
|
|
101
|
+
current_batch.append(item)
|
|
102
|
+
current_cores += 1
|
|
103
|
+
else:
|
|
104
|
+
# printer.print(f"Unavailable Resources - Requirements: {mem_model}, Available: {available_memory}")
|
|
105
|
+
cpu_queue.put(item)
|
|
106
|
+
break
|
|
107
|
+
|
|
108
|
+
except Queue.Empty:
|
|
109
|
+
break
|
|
110
|
+
|
|
111
|
+
# Procesar el batch actual si no está vacío
|
|
112
|
+
if current_batch:
|
|
113
|
+
# printer.print(f"Executing Batch of {len(current_batch)} Jobs")
|
|
114
|
+
with Pool(processes=len(current_batch)) as pool:
|
|
115
|
+
# Usamos map de forma síncrona para asegurar que todos los items se procesen
|
|
116
|
+
batch_results = pool.starmap(self.execute_model, [params[1] for params in current_batch])
|
|
117
|
+
|
|
118
|
+
# Filtramos los resultados None (errores) y los añadimos a results
|
|
119
|
+
# valid_results = [r for r in batch_results if r is not None]
|
|
120
|
+
results.extend(batch_results)
|
|
121
|
+
|
|
122
|
+
# Liberar recursos después del procesamiento
|
|
123
|
+
with resource_lock:
|
|
124
|
+
# printer.print("Freeing Up Resources")
|
|
125
|
+
for item in current_batch:
|
|
126
|
+
_, _, _, _, _, _, _, mem_model = item[0]
|
|
127
|
+
available_memory += mem_model
|
|
128
|
+
available_cores += 1
|
|
129
|
+
# printer.print(f"Freed - Memory: {available_memory}MB, Cores: {available_cores}")
|
|
130
|
+
|
|
131
|
+
# printer.print("Waiting for next batch")
|
|
132
|
+
sleep(0.1)
|
|
133
|
+
|
|
134
|
+
except Exception as e:
|
|
135
|
+
printer.print(f"Error in the batch: {str(e)}")
|
|
136
|
+
break
|
|
137
|
+
|
|
46
138
|
def dispatch(self, nqubits, randomstate, predictions, shots,
|
|
47
139
|
numPredictors, numLayers, classifiers, ansatzs, backend,
|
|
48
140
|
embeddings, features, learningRate, epochs, runs, batch,
|
|
49
141
|
maxSamples, verbose, customMetric, customImputerNum,
|
|
50
|
-
customImputerCat,
|
|
51
|
-
|
|
52
|
-
|
|
142
|
+
customImputerCat, X, y,
|
|
143
|
+
showTable=True, mode="cross-validation",testsize=0.4):
|
|
144
|
+
|
|
145
|
+
"""
|
|
146
|
+
################################################################################
|
|
147
|
+
Preparing Data Structures & Initializing Variables
|
|
148
|
+
################################################################################
|
|
149
|
+
"""
|
|
150
|
+
# Replace the list-based queues with multiprocessing queues
|
|
151
|
+
manager = Manager()
|
|
152
|
+
gpu_queue = Queue()
|
|
153
|
+
cpu_queue = Queue()
|
|
154
|
+
results = manager.list() # Shared list for results if needed
|
|
155
|
+
# Also keep track of items for printing
|
|
156
|
+
cpu_items = []
|
|
157
|
+
gpu_items = []
|
|
158
|
+
|
|
159
|
+
RAM = calculate_free_memory()
|
|
160
|
+
VRAM = calculate_free_video_memory()
|
|
161
|
+
|
|
162
|
+
"""
|
|
163
|
+
################################################################################
|
|
164
|
+
Generate CV indices once
|
|
165
|
+
################################################################################
|
|
166
|
+
"""
|
|
167
|
+
cv_indices = generate_cv_indices(
|
|
168
|
+
X, y,
|
|
169
|
+
mode=mode,
|
|
170
|
+
n_splits=self.fold,
|
|
171
|
+
n_repeats=self.repeat,
|
|
172
|
+
random_state=randomstate
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
"""
|
|
177
|
+
################################################################################
|
|
178
|
+
Generating Combinations
|
|
179
|
+
################################################################################
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
t_pre = time()
|
|
53
183
|
combinations = create_combinations(qubits=nqubits,
|
|
54
184
|
classifiers=classifiers,
|
|
55
185
|
embeddings=embeddings,
|
|
56
186
|
features=features,
|
|
57
|
-
ansatzs=ansatzs
|
|
58
|
-
|
|
59
|
-
|
|
187
|
+
ansatzs=ansatzs,
|
|
188
|
+
RepeatID=[i for i in range(self.repeat)],
|
|
189
|
+
FoldID=[i for i in range(self.fold)])
|
|
190
|
+
cancelledQubits = set()
|
|
191
|
+
to_remove = []
|
|
192
|
+
|
|
193
|
+
for i, combination in enumerate(combinations):
|
|
194
|
+
modelMem = combination[-1]
|
|
195
|
+
if modelMem > RAM and modelMem > VRAM:
|
|
196
|
+
to_remove.append(combination)
|
|
60
197
|
|
|
61
|
-
|
|
62
|
-
|
|
198
|
+
for combination in to_remove:
|
|
199
|
+
combinations.remove(combination)
|
|
200
|
+
cancelledQubits.add(combination[0])
|
|
63
201
|
|
|
202
|
+
for val in cancelledQubits:
|
|
203
|
+
printer.print(f"Execution with {val} Qubits are cancelled due to memory constrains -> Memory Required: {calculate_quantum_memory(val)/1024:.2f}GB Out of {calculate_free_memory()/1024:.2f}GB")
|
|
64
204
|
|
|
65
|
-
|
|
66
|
-
available_memory = calculate_free_memory()
|
|
67
|
-
quantum_memory = calculate_quantum_memory(num_qubits=max(nqubits))
|
|
68
|
-
max_models_parallel = min(int(available_memory // quantum_memory) if quantum_memory > 0 else float('inf'), psutil.cpu_count(logical=False))
|
|
69
|
-
|
|
70
|
-
for combination in combinations:
|
|
71
|
-
print(combination)
|
|
205
|
+
X = pd.DataFrame(X)
|
|
72
206
|
|
|
73
207
|
# Prepare all model executions
|
|
74
|
-
all_executions = []
|
|
75
208
|
for combination in combinations:
|
|
76
|
-
qubits, name, embedding, ansatz, feature = combination
|
|
209
|
+
qubits, name, embedding, ansatz, feature, repeat, fold, memModel = combination
|
|
77
210
|
feature = feature if feature is not None else "~"
|
|
78
211
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
212
|
+
# Get indices for this repeat/fold combination
|
|
213
|
+
train_idx, test_idx = get_train_test_split(cv_indices, repeat, fold)
|
|
214
|
+
|
|
215
|
+
numClasses = len(np.unique(y))
|
|
216
|
+
adjustedQubits = qubits # or use adjustQubits if needed
|
|
83
217
|
prepFactory = PreprocessingFactory(adjustedQubits)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
218
|
+
|
|
219
|
+
# Process data for this specific combination using pre-generated indices
|
|
220
|
+
X_train_processed, X_test_processed, y_train_processed, y_test_processed = dataProcessing(
|
|
221
|
+
X,
|
|
222
|
+
y,
|
|
223
|
+
prepFactory,
|
|
224
|
+
customImputerCat,
|
|
225
|
+
customImputerNum,
|
|
226
|
+
train_idx,
|
|
227
|
+
test_idx,
|
|
228
|
+
ansatz=ansatz,
|
|
229
|
+
embedding=embedding
|
|
230
|
+
)
|
|
88
231
|
|
|
89
232
|
model_factory_params = {
|
|
90
233
|
"Nqubits": adjustedQubits,
|
|
@@ -94,7 +237,7 @@ class Dispatcher:
|
|
|
94
237
|
"N_class": numClasses,
|
|
95
238
|
"backend": backend,
|
|
96
239
|
"Shots": shots,
|
|
97
|
-
"seed": randomstate,
|
|
240
|
+
"seed": randomstate*repeat,
|
|
98
241
|
"Layers": numLayers,
|
|
99
242
|
"Max_samples": maxSamples,
|
|
100
243
|
"Max_features": feature,
|
|
@@ -103,45 +246,81 @@ class Dispatcher:
|
|
|
103
246
|
"Epoch": epochs,
|
|
104
247
|
"numPredictors": numPredictors
|
|
105
248
|
}
|
|
106
|
-
# print(f"XTEST SHAPE: {X_test.shape}")
|
|
107
|
-
# print(f"YTEST SHAPE: {y_test.shape}")
|
|
108
|
-
# print(f"XTrain SHAPE: {X_train.shape}")
|
|
109
|
-
# print(f"YTrain SHAPE: {y_train.shape}")
|
|
110
|
-
preprocessing = prepFactory.GetPreprocessing(ansatz=ansatz, embedding=embedding)
|
|
111
|
-
X_train_processed = np.array(preprocessing.fit_transform(X_train, y=y_train))
|
|
112
|
-
X_test_processed = np.array(preprocessing.transform(X_test))
|
|
113
|
-
y_test = np.array(y_test)
|
|
114
|
-
y_train = np.array(y_train)
|
|
115
|
-
# print(f"XTEST PROCESSED SHAPE: {X_test_processed.shape}")
|
|
116
249
|
|
|
117
|
-
#
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
print(f"PREPROCESSING TIME: {time.time()-t_pre}")
|
|
123
|
-
# Execute all models in parallel
|
|
124
|
-
t_exe = time.time()
|
|
125
|
-
if self.sequential:
|
|
126
|
-
results = [self.execute_model(*execution_params) for execution_params in all_executions]
|
|
127
|
-
else:
|
|
128
|
-
if auto:
|
|
129
|
-
results = Parallel(n_jobs=max_models_parallel, prefer='processes',batch_size='auto',verbose=10)(
|
|
130
|
-
delayed(self.execute_model)(*execution_params) for execution_params in all_executions
|
|
131
|
-
)
|
|
250
|
+
# When adding items to queues
|
|
251
|
+
if name == Model.QNN and qubits >= self.threshold and VRAM > calculate_quantum_memory(qubits):
|
|
252
|
+
model_factory_params["backend"] = Backend.lightningGPU
|
|
253
|
+
gpu_queue.put((combination,(model_factory_params, X_train_processed, y_train_processed, X_test_processed, y_test_processed, predictions, customMetric)))
|
|
254
|
+
gpu_items.append(combination)
|
|
132
255
|
else:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
)
|
|
256
|
+
model_factory_params["backend"] = Backend.lightningQubit
|
|
257
|
+
cpu_queue.put((combination,(model_factory_params, X_train_processed, y_train_processed, X_test_processed, y_test_processed, predictions, customMetric)))
|
|
258
|
+
cpu_items.append(combination)
|
|
259
|
+
|
|
136
260
|
if self.timeM:
|
|
137
|
-
print(f"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
261
|
+
printer.print(f"PREPROCESSING TIME: {time()-t_pre}")
|
|
262
|
+
|
|
263
|
+
"""
|
|
264
|
+
################################################################################
|
|
265
|
+
Creating processes
|
|
266
|
+
################################################################################
|
|
267
|
+
"""
|
|
268
|
+
executionTime = time()
|
|
269
|
+
gpu_process = None
|
|
270
|
+
# Start GPU process
|
|
271
|
+
if not gpu_queue.empty():
|
|
272
|
+
gpu_process = Process(target=self.process_gpu_task, args=(gpu_queue, results))
|
|
273
|
+
gpu_process.start()
|
|
274
|
+
|
|
275
|
+
# Start CPU processes
|
|
276
|
+
if not cpu_queue.empty():
|
|
277
|
+
self.process_cpu_task(cpu_queue, gpu_queue, results)
|
|
278
|
+
|
|
279
|
+
# Wait for all processes to complete
|
|
280
|
+
if gpu_process is not None:
|
|
281
|
+
gpu_process.join()
|
|
282
|
+
|
|
283
|
+
executionTime = time()-executionTime
|
|
284
|
+
printer.print(f"Execution TIME: {executionTime}")
|
|
285
|
+
|
|
286
|
+
"""
|
|
287
|
+
################################################################################
|
|
288
|
+
Processing results
|
|
289
|
+
################################################################################
|
|
290
|
+
"""
|
|
291
|
+
t_res = time()
|
|
141
292
|
|
|
293
|
+
grouped_results = defaultdict(list)
|
|
294
|
+
for result in list(results):
|
|
295
|
+
key = result[:5]
|
|
296
|
+
grouped_results[key].append(result)
|
|
297
|
+
|
|
298
|
+
summary = []
|
|
299
|
+
for key, group in grouped_results.items():
|
|
300
|
+
time_taken = sum([r[5] for r in group])
|
|
301
|
+
accuracy = mean([r[6] for r in group])
|
|
302
|
+
balanced_accuracy = mean([r[7] for r in group])
|
|
303
|
+
f1_score = mean([r[8] for r in group])
|
|
304
|
+
if customMetric:
|
|
305
|
+
if mode == "hold-out":
|
|
306
|
+
cols = ["Qubits", "Model", "Embedding", "Ansatz", "Features", "Time taken", "Accuracy", "Balanced Accuracy", "F1 Score", "Custom Metric", "Predictions"]
|
|
307
|
+
summary.append((key[0], key[1], key[2], key[3], key[4], time_taken, accuracy, balanced_accuracy, f1_score, custom_metric, []))
|
|
308
|
+
else:
|
|
309
|
+
cols = ["Qubits", "Model", "Embedding", "Ansatz", "Features", "Time taken", "Accuracy", "Balanced Accuracy", "F1 Score", "Custom Metric"]
|
|
310
|
+
custom_metric = mean([r[9] for r in group])
|
|
311
|
+
summary.append((key[0], key[1], key[2], key[3], key[4], time_taken, accuracy, balanced_accuracy, f1_score, custom_metric))
|
|
312
|
+
else:
|
|
313
|
+
if mode == "hold-out":
|
|
314
|
+
cols = ["Qubits", "Model", "Embedding", "Ansatz", "Features", "Time taken", "Accuracy", "Balanced Accuracy", "F1 Score", "Custom Metric", "Predictions"]
|
|
315
|
+
summary.append((key[0], key[1], key[2], key[3], key[4], time_taken, accuracy, balanced_accuracy, f1_score, [], []))
|
|
316
|
+
else:
|
|
317
|
+
cols = ["Qubits", "Model", "Embedding", "Ansatz", "Features", "Time taken", "Accuracy", "Balanced Accuracy", "F1 Score"]
|
|
318
|
+
summary.append((key[0], key[1], key[2], key[3], key[4], time_taken, accuracy, balanced_accuracy, f1_score))
|
|
319
|
+
scores = pd.DataFrame(summary, columns=cols)
|
|
320
|
+
scores = scores.sort_values(by="Balanced Accuracy",ascending=False).reset_index(drop=True)
|
|
142
321
|
if showTable:
|
|
143
322
|
print(scores.to_markdown())
|
|
144
323
|
|
|
145
324
|
if self.timeM:
|
|
146
|
-
print(f"RESULTS TIME: {time
|
|
147
|
-
return scores
|
|
325
|
+
printer.print(f"RESULTS TIME: {time() - t_res}")
|
|
326
|
+
return scores
|