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,112 +0,0 @@
|
|
|
1
|
-
from sklearn.metrics import f1_score, accuracy_score, balanced_accuracy_score, roc_auc_score
|
|
2
|
-
from Factories.Models.fModels import *
|
|
3
|
-
from Factories.Preprocessing.fPreprocessing import *
|
|
4
|
-
import time
|
|
5
|
-
import pandas as pd
|
|
6
|
-
|
|
7
|
-
def executeQSVM(combinations, nqubits, backend, shots, runs, X_train, y_train, X_test, y_test, customImputerCat,customImputerNum, customMetric,seed, predictions,numClasses):
|
|
8
|
-
|
|
9
|
-
NAMES = []
|
|
10
|
-
EMBEDDINGS = []
|
|
11
|
-
ANSATZ = []
|
|
12
|
-
ACCURACY = []
|
|
13
|
-
B_ACCURACY = []
|
|
14
|
-
ROC_AUC = []
|
|
15
|
-
F1 = []
|
|
16
|
-
TIME = []
|
|
17
|
-
PARAMETERS = []
|
|
18
|
-
|
|
19
|
-
predictions = {}
|
|
20
|
-
|
|
21
|
-
models = []
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# Convert input data to pandas DataFrames if they aren't already
|
|
25
|
-
if not isinstance(X_train, pd.DataFrame):
|
|
26
|
-
X_train = pd.DataFrame(X_train)
|
|
27
|
-
if not isinstance(X_test, pd.DataFrame):
|
|
28
|
-
X_test = pd.DataFrame(X_test)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
prepFactory = PreprocessingFactory(nqubits)
|
|
32
|
-
sanitizer = prepFactory.GetSanitizer(customImputerCat, customImputerNum)
|
|
33
|
-
|
|
34
|
-
X_train = sanitizer.fit_transform(X_train)
|
|
35
|
-
X_test = sanitizer.transform(X_test)
|
|
36
|
-
|
|
37
|
-
for i in combinations:
|
|
38
|
-
print(f"Executing {i} combination of {len(combinations)}")
|
|
39
|
-
name, embedding, ansatz, feature = i
|
|
40
|
-
model = ModelFactory(Nqubits=nqubits, Embedding=embedding,Ansatz=ansatz,backend=backend,Shots=shots,seed=seed,N_class=numClasses).GetQSVM()
|
|
41
|
-
|
|
42
|
-
preprocessing = None
|
|
43
|
-
preprocessing = prepFactory.GetPreprocessing(embedding=embedding,ansatz=ansatz)
|
|
44
|
-
|
|
45
|
-
X_train = preprocessing.fit_transform(X=X_train,y=y_train)
|
|
46
|
-
X_test = preprocessing.transform(X=X_test)
|
|
47
|
-
|
|
48
|
-
accuracyR, b_accuracyR, f1R = 0, 0, 0
|
|
49
|
-
for j in range(runs):
|
|
50
|
-
print(f"Executing {j+1} run of {runs}")
|
|
51
|
-
start = time.time()
|
|
52
|
-
model.fit(X=X_train,y=y_train)
|
|
53
|
-
exeT = time.time() - start
|
|
54
|
-
y_pred = model.predict(X=X_test)
|
|
55
|
-
|
|
56
|
-
accuracyR += accuracy_score(y_test, y_pred, normalize=True)
|
|
57
|
-
b_accuracyR += balanced_accuracy_score(y_test, y_pred)
|
|
58
|
-
f1R += f1_score(y_test, y_pred, average="weighted")
|
|
59
|
-
# try:
|
|
60
|
-
# roc_aucR += roc_auc_score(y_test, y_pred)
|
|
61
|
-
# except Exception as exception:
|
|
62
|
-
# roc_aucR += ""
|
|
63
|
-
|
|
64
|
-
accuracy = accuracyR/runs
|
|
65
|
-
b_accuracy = b_accuracyR/runs
|
|
66
|
-
f1 = f1R/runs
|
|
67
|
-
# roc_auc = roc_aucR/runs
|
|
68
|
-
|
|
69
|
-
NAMES.append(name)
|
|
70
|
-
ANSATZ.append(ansatz)
|
|
71
|
-
ACCURACY.append(accuracy)
|
|
72
|
-
B_ACCURACY.append(b_accuracy)
|
|
73
|
-
# ROC_AUC.append(roc_auc)
|
|
74
|
-
EMBEDDINGS.append(embedding)
|
|
75
|
-
F1.append(f1)
|
|
76
|
-
TIME.append(exeT)
|
|
77
|
-
PARAMETERS.append("~")
|
|
78
|
-
|
|
79
|
-
if customMetric is not None:
|
|
80
|
-
customMetricV = customMetric(y_test, y_pred)
|
|
81
|
-
customMetric.append(customMetricV)
|
|
82
|
-
scores = pd.DataFrame(
|
|
83
|
-
{
|
|
84
|
-
"Model": NAMES,
|
|
85
|
-
"Embedding": EMBEDDINGS,
|
|
86
|
-
"Ansatz": ANSATZ,
|
|
87
|
-
"Accuracy": ACCURACY,
|
|
88
|
-
"Balanced Accuracy": B_ACCURACY,
|
|
89
|
-
# "ROC AUC": ROC_AUC,
|
|
90
|
-
"F1 Score": F1,
|
|
91
|
-
customMetric.__name__: customMetric,
|
|
92
|
-
"Trainable Parameters": PARAMETERS,
|
|
93
|
-
"Time taken": TIME,
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
else:
|
|
97
|
-
scores = pd.DataFrame(
|
|
98
|
-
{
|
|
99
|
-
"Model": NAMES,
|
|
100
|
-
"Embedding": EMBEDDINGS,
|
|
101
|
-
"Ansatz": ANSATZ,
|
|
102
|
-
"Accuracy": ACCURACY,
|
|
103
|
-
"Balanced Accuracy": B_ACCURACY,
|
|
104
|
-
# "ROC AUC": ROC_AUC,
|
|
105
|
-
"F1 Score": F1,
|
|
106
|
-
"Trainable Parameters": PARAMETERS,
|
|
107
|
-
"Time taken": TIME,
|
|
108
|
-
}
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
return scores
|
|
112
|
-
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
2
|
-
from queue import Queue, Empty
|
|
3
|
-
from threading import Lock
|
|
4
|
-
import psutil
|
|
5
|
-
import numpy as np
|
|
6
|
-
import pandas as pd
|
|
7
|
-
from sklearn.metrics import f1_score, accuracy_score, balanced_accuracy_score
|
|
8
|
-
from Utils.Utils import *
|
|
9
|
-
from Factories.Preprocessing.fPreprocessing import *
|
|
10
|
-
from Factories.Models.fModels import *
|
|
11
|
-
import math
|
|
12
|
-
import time
|
|
13
|
-
|
|
14
|
-
class Dispatcher:
|
|
15
|
-
def __init__(self, sequential, threshold=27):
|
|
16
|
-
self.sequential = sequential
|
|
17
|
-
self.threshold = threshold
|
|
18
|
-
|
|
19
|
-
def _executeModel(self, model, X_train, y_train, X_test, y_test, predictions, runs, customMetric):
|
|
20
|
-
preds = []
|
|
21
|
-
accuracyR, b_accuracyR, f1R, customR = 0, 0, 0, 0
|
|
22
|
-
custom = None
|
|
23
|
-
exeT = 0
|
|
24
|
-
|
|
25
|
-
for j in range(runs):
|
|
26
|
-
printer.print(f"\tExecuting {j+1} run of {runs}")
|
|
27
|
-
start = time.time()
|
|
28
|
-
model.fit(X=X_train, y=y_train)
|
|
29
|
-
exeT += time.time() - start
|
|
30
|
-
y_pred = model.predict(X=X_test)
|
|
31
|
-
|
|
32
|
-
accuracyR += accuracy_score(y_test, y_pred, normalize=True)
|
|
33
|
-
b_accuracyR += balanced_accuracy_score(y_test, y_pred)
|
|
34
|
-
f1R += f1_score(y_test, y_pred, average="weighted")
|
|
35
|
-
if customMetric is not None:
|
|
36
|
-
customR += customMetric(y_test, y_pred)
|
|
37
|
-
|
|
38
|
-
if predictions:
|
|
39
|
-
preds = y_pred
|
|
40
|
-
accuracy = accuracyR/runs
|
|
41
|
-
b_accuracy = b_accuracyR/runs
|
|
42
|
-
f1 = f1R/runs
|
|
43
|
-
if customMetric is not None:
|
|
44
|
-
custom = customR/runs
|
|
45
|
-
|
|
46
|
-
exeT = exeT/runs # Average execution time
|
|
47
|
-
return exeT, accuracy, b_accuracy, f1, custom, preds
|
|
48
|
-
|
|
49
|
-
def _process_model(self, args):
|
|
50
|
-
model, X_train, y_train, X_test, y_test, predictions, runs, customMetric = args
|
|
51
|
-
return self._executeModel(model, X_train, y_train, X_test, y_test, predictions, runs, customMetric)
|
|
52
|
-
|
|
53
|
-
def dispatch(self, nqubits, randomstate, predictions, shots,
|
|
54
|
-
numPredictors, numLayers, classifiers, ansatzs, backend,
|
|
55
|
-
embeddings, features, learningRate, epochs, runs, batch,
|
|
56
|
-
maxSamples, verbose, customMetric, customImputerNum, customImputerCat,
|
|
57
|
-
X_train, y_train, X_test, y_test, showTable=True):
|
|
58
|
-
|
|
59
|
-
NAMES, EMBEDDINGS, ANSATZ, ACCURACY = [], [], [], []
|
|
60
|
-
B_ACCURACY, FEATURES, F1, TIME, CUSTOM = [], [], [], [], []
|
|
61
|
-
|
|
62
|
-
numClasses = len(np.unique(y_train))
|
|
63
|
-
|
|
64
|
-
# Adjust qubits if necessary
|
|
65
|
-
if (numClasses > 2**math.floor(math.log2(nqubits))):
|
|
66
|
-
printer.print("The number of qubits must exceed the number of classes and be a power of 2 to execute all circuits successfully.")
|
|
67
|
-
adjustedQubits = adjustQubits(nqubits=nqubits, numClasses=numClasses)
|
|
68
|
-
printer.print(f"New number of qubits:\t{adjustedQubits}")
|
|
69
|
-
else:
|
|
70
|
-
adjustedQubits = nqubits
|
|
71
|
-
|
|
72
|
-
# Convert input data to pandas DataFrames
|
|
73
|
-
if not isinstance(X_train, pd.DataFrame):
|
|
74
|
-
X_train = pd.DataFrame(X_train)
|
|
75
|
-
if not isinstance(X_test, pd.DataFrame):
|
|
76
|
-
X_test = pd.DataFrame(X_test)
|
|
77
|
-
|
|
78
|
-
# Preprocessing
|
|
79
|
-
prepFactory = PreprocessingFactory(nqubits)
|
|
80
|
-
sanitizer = prepFactory.GetSanitizer(customImputerCat, customImputerNum)
|
|
81
|
-
X_train = sanitizer.fit_transform(X_train)
|
|
82
|
-
X_test = sanitizer.transform(X_test)
|
|
83
|
-
|
|
84
|
-
combinations = create_combinations(classifiers=classifiers, embeddings=embeddings,
|
|
85
|
-
features=features, ansatzs=ansatzs)
|
|
86
|
-
|
|
87
|
-
models_to_run = []
|
|
88
|
-
for combination in combinations:
|
|
89
|
-
name, embedding, ansatz, feature = combination
|
|
90
|
-
printer.print("="*100)
|
|
91
|
-
feature = feature if feature is not None else "~"
|
|
92
|
-
printer.print(f"Model: {name} Embedding: {embedding} Ansatz:{ansatz} Features: {feature}")
|
|
93
|
-
|
|
94
|
-
model = ModelFactory().getModel(
|
|
95
|
-
Nqubits=adjustedQubits, model=name, Embedding=embedding,
|
|
96
|
-
Ansatz=ansatz, N_class=numClasses, backend=backend,
|
|
97
|
-
Shots=shots, seed=randomstate, Layers=numLayers,
|
|
98
|
-
Max_samples=maxSamples, Max_features=feature,
|
|
99
|
-
LearningRate=learningRate, BatchSize=batch,
|
|
100
|
-
Epoch=epochs, numPredictors=numPredictors
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
preprocessing = prepFactory.GetPreprocessing(ansatz=ansatz, embedding=embedding)
|
|
104
|
-
X_train_processed = preprocessing.fit_transform(X_train, y=y_train)
|
|
105
|
-
X_test_processed = preprocessing.transform(X_test)
|
|
106
|
-
|
|
107
|
-
models_to_run.append((
|
|
108
|
-
model, X_train_processed, y_train, X_test_processed, y_test,
|
|
109
|
-
predictions, runs, customMetric, name, embedding, ansatz, feature
|
|
110
|
-
))
|
|
111
|
-
|
|
112
|
-
if self.sequential or backend == "Lightning.GPU" or nqubits >= self.threshold:
|
|
113
|
-
printer.print("SEQUENTIAL")
|
|
114
|
-
# Sequential execution
|
|
115
|
-
for model_args in models_to_run:
|
|
116
|
-
model, X_train_p, y_train, X_test_p, y_test, preds, runs, custom_metric, \
|
|
117
|
-
name, embedding, ansatz, feature = model_args
|
|
118
|
-
|
|
119
|
-
exeT, accuracy, b_accuracy, f1, custom, _ = self._executeModel(
|
|
120
|
-
model, X_train_p, y_train, X_test_p, y_test, preds, runs, custom_metric
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
self._append_results(NAMES, EMBEDDINGS, ANSATZ, ACCURACY, B_ACCURACY,
|
|
124
|
-
FEATURES, F1, TIME, CUSTOM, name, embedding, ansatz,
|
|
125
|
-
feature, accuracy, b_accuracy, f1, exeT, custom)
|
|
126
|
-
else:
|
|
127
|
-
# Parallel execution
|
|
128
|
-
printer.print("PARALLEL")
|
|
129
|
-
with ThreadPoolExecutor(max_workers=min(len(models_to_run), psutil.cpu_count())) as executor:
|
|
130
|
-
futures = []
|
|
131
|
-
for model_args in models_to_run:
|
|
132
|
-
model, X_train_p, y_train, X_test_p, y_test, preds, runs, custom_metric, \
|
|
133
|
-
name, embedding, ansatz, feature = model_args
|
|
134
|
-
|
|
135
|
-
future = executor.submit(self._executeModel, model, X_train_p, y_train,
|
|
136
|
-
X_test_p, y_test, preds, runs, custom_metric)
|
|
137
|
-
futures.append((future, name, embedding, ansatz, feature))
|
|
138
|
-
|
|
139
|
-
for future, name, embedding, ansatz, feature in futures:
|
|
140
|
-
exeT, accuracy, b_accuracy, f1, custom, _ = future.result()
|
|
141
|
-
self._append_results(NAMES, EMBEDDINGS, ANSATZ, ACCURACY, B_ACCURACY,
|
|
142
|
-
FEATURES, F1, TIME, CUSTOM, name, embedding, ansatz,
|
|
143
|
-
feature, accuracy, b_accuracy, f1, exeT, custom)
|
|
144
|
-
|
|
145
|
-
# Create and return results DataFrame
|
|
146
|
-
return self._create_results_dataframe(NAMES, EMBEDDINGS, ANSATZ, FEATURES,
|
|
147
|
-
ACCURACY, B_ACCURACY, F1, CUSTOM, TIME,
|
|
148
|
-
customMetric, showTable)
|
|
149
|
-
|
|
150
|
-
def _append_results(self, NAMES, EMBEDDINGS, ANSATZ, ACCURACY, B_ACCURACY,
|
|
151
|
-
FEATURES, F1, TIME, CUSTOM, name, embedding, ansatz,
|
|
152
|
-
feature, accuracy, b_accuracy, f1, exeT, custom):
|
|
153
|
-
NAMES.append(name)
|
|
154
|
-
EMBEDDINGS.append(embedding)
|
|
155
|
-
ANSATZ.append(ansatz)
|
|
156
|
-
ACCURACY.append(accuracy)
|
|
157
|
-
B_ACCURACY.append(b_accuracy)
|
|
158
|
-
FEATURES.append(feature)
|
|
159
|
-
F1.append(f1)
|
|
160
|
-
TIME.append(exeT)
|
|
161
|
-
CUSTOM.append(custom)
|
|
162
|
-
|
|
163
|
-
def _create_results_dataframe(self, NAMES, EMBEDDINGS, ANSATZ, FEATURES,
|
|
164
|
-
ACCURACY, B_ACCURACY, F1, CUSTOM, TIME,
|
|
165
|
-
customMetric, showTable):
|
|
166
|
-
if customMetric is None:
|
|
167
|
-
scores = pd.DataFrame({
|
|
168
|
-
"Model": NAMES,
|
|
169
|
-
"Embedding": EMBEDDINGS,
|
|
170
|
-
"Ansatz": ANSATZ,
|
|
171
|
-
"Features": FEATURES,
|
|
172
|
-
"Accuracy": ACCURACY,
|
|
173
|
-
"Balanced Accuracy": B_ACCURACY,
|
|
174
|
-
"F1 Score": F1,
|
|
175
|
-
"Time taken": TIME,
|
|
176
|
-
})
|
|
177
|
-
else:
|
|
178
|
-
scores = pd.DataFrame({
|
|
179
|
-
"Model": NAMES,
|
|
180
|
-
"Embedding": EMBEDDINGS,
|
|
181
|
-
"Ansatz": ANSATZ,
|
|
182
|
-
"Features": FEATURES,
|
|
183
|
-
"Accuracy": ACCURACY,
|
|
184
|
-
"Balanced Accuracy": B_ACCURACY,
|
|
185
|
-
"F1 Score": F1,
|
|
186
|
-
customMetric.__name__: CUSTOM,
|
|
187
|
-
"Time taken": TIME,
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
if showTable:
|
|
191
|
-
print(scores.to_markdown())
|
|
192
|
-
|
|
193
|
-
return scores
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
from Interfaces.iPreprocessing import Preprocessing
|
|
2
|
-
from sklearn.decomposition import PCA
|
|
3
|
-
from sklearn.exceptions import NotFittedError
|
|
4
|
-
|
|
5
|
-
class PcaAmp(Preprocessing):
|
|
6
|
-
def __init__(self, nqubits):
|
|
7
|
-
self.nqubits = nqubits
|
|
8
|
-
self.ncomponents = 2**nqubits
|
|
9
|
-
self.preprocessing = PCA(n_components=self.ncomponents)
|
|
10
|
-
|
|
11
|
-
def fit(self, X, y):
|
|
12
|
-
return self.preprocessing.fit(X, y) if self.ncomponents <= X.shape[1] else X
|
|
13
|
-
|
|
14
|
-
def fit_transform(self, X, y):
|
|
15
|
-
return self.preprocessing.fit_transform(X, y) if self.ncomponents <= X.shape[1] else X
|
|
16
|
-
|
|
17
|
-
def transform(self, X):
|
|
18
|
-
try:
|
|
19
|
-
fitted_X = self.preprocessing.transform(X)
|
|
20
|
-
except NotFittedError as e:
|
|
21
|
-
fitted_X = X
|
|
22
|
-
return fitted_X
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
from Interfaces.iPreprocessing import Preprocessing
|
|
2
|
-
from sklearn.decomposition import PCA
|
|
3
|
-
from sklearn.exceptions import NotFittedError
|
|
4
|
-
|
|
5
|
-
class PcaTree(Preprocessing):
|
|
6
|
-
def __init__(self, nqubits):
|
|
7
|
-
self.nqubits = nqubits
|
|
8
|
-
self.ncomponents = 2**(self.nqubits.bit_length()-1)
|
|
9
|
-
self.preprocessing = PCA(n_components=self.ncomponents)
|
|
10
|
-
|
|
11
|
-
def fit(self, X, y):
|
|
12
|
-
return self.preprocessing.fit(X, y) if self.ncomponents <= X.shape[1] else X
|
|
13
|
-
|
|
14
|
-
def fit_transform(self, X, y):
|
|
15
|
-
return self.preprocessing.fit_transform(X, y) if self.ncomponents <= X.shape[1] else X
|
|
16
|
-
|
|
17
|
-
def transform(self, X):
|
|
18
|
-
try:
|
|
19
|
-
fitted_X = self.preprocessing.transform(X)
|
|
20
|
-
except NotFittedError as e:
|
|
21
|
-
fitted_X = X
|
|
22
|
-
return fitted_X
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
from Interfaces.iPreprocessing import Preprocessing
|
|
2
|
-
from sklearn.decomposition import PCA
|
|
3
|
-
from sklearn.exceptions import NotFittedError
|
|
4
|
-
|
|
5
|
-
class PcaTreeAmp(Preprocessing):
|
|
6
|
-
def __init__(self, nqubits):
|
|
7
|
-
self.nqubits = nqubits
|
|
8
|
-
self.ncomponents = 2**(2**(self.nqubits.bit_length()-1))
|
|
9
|
-
self.preprocessing = PCA(n_components=self.ncomponents)
|
|
10
|
-
|
|
11
|
-
def fit(self, X, y):
|
|
12
|
-
return self.preprocessing.fit(X, y) if self.ncomponents <= X.shape[1] else X
|
|
13
|
-
|
|
14
|
-
def fit_transform(self, X, y):
|
|
15
|
-
return self.preprocessing.fit_transform(X, y) if self.ncomponents <= X.shape[1] else X
|
|
16
|
-
|
|
17
|
-
def transform(self, X):
|
|
18
|
-
try:
|
|
19
|
-
fitted_X = self.preprocessing.transform(X)
|
|
20
|
-
except NotFittedError as e:
|
|
21
|
-
fitted_X = X
|
|
22
|
-
return fitted_X
|
lazyqml/Lanza copy.sh
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# SLRNGPU=A6000
|
|
3
|
-
# SLRGPUS=
|
|
4
|
-
SLRNAME=slave3
|
|
5
|
-
|
|
6
|
-
# Activar VirtualEnv
|
|
7
|
-
eval "$(/opt/miniconda3/bin/conda shell.bash hook)"
|
|
8
|
-
conda init
|
|
9
|
-
conda config --set auto_activate_base false
|
|
10
|
-
conda activate lazyqml
|
|
11
|
-
cd /home/diegogv/LazyQML/lazyqml
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# Lanzar ejecucion del script
|
|
15
|
-
# argumentos
|
|
16
|
-
# Rotationals_family = sys.argv[1].lower() == 'true'
|
|
17
|
-
# Batch_auto = sys.argv[2].lower() == 'true'
|
|
18
|
-
# Sequential = sys.argv[3].lower() == 'true'
|
|
19
|
-
# Node = sys.argv[4].lower()
|
|
20
|
-
|
|
21
|
-
# EXECUTIONS -> Done
|
|
22
|
-
# true true false -> slave4; slave5; slave3
|
|
23
|
-
# true false false -> slave4; slave5; slave3
|
|
24
|
-
# false true false -> slave4; slave5; slave3
|
|
25
|
-
# false false false -> slave4; slave5; slave3
|
|
26
|
-
|
|
27
|
-
# true true true -> slave4; slave5; slave3
|
|
28
|
-
# true false true -> slave4; slave5; slave3
|
|
29
|
-
# false true true -> slave4; slave5; slave3
|
|
30
|
-
# false false true -> slave4; slave5;
|
|
31
|
-
|
|
32
|
-
python lazyqmlP.py true true true slave4
|
lazyqml/Lanza.sh
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# SLRNGPU=A6000
|
|
3
|
-
# SLRGPUS=
|
|
4
|
-
SLRNAME=slave4
|
|
5
|
-
|
|
6
|
-
# Activar VirtualEnv
|
|
7
|
-
eval "$(/opt/miniconda3/bin/conda shell.bash hook)"
|
|
8
|
-
conda init
|
|
9
|
-
conda config --set auto_activate_base false
|
|
10
|
-
conda activate lazyqml
|
|
11
|
-
cd /home/diegogv/LazyQML/lazyqml
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# Lanzar ejecucion del script
|
|
15
|
-
# argumentos
|
|
16
|
-
# Sequential = sys.argv[1].lower() == 'true'
|
|
17
|
-
# Node = sys.argv[2].lower()
|
|
18
|
-
# qubits = int(sys.argv[3])
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
python lazyqmlVote.py true slave4 16 16
|
lazyqml/mem.py
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import psutil
|
|
2
|
-
import pennylane as qml
|
|
3
|
-
|
|
4
|
-
def available_memory():
|
|
5
|
-
"""
|
|
6
|
-
Check the available system memory in bytes using psutil.
|
|
7
|
-
Returns:
|
|
8
|
-
available_mem (int): Available RAM in bytes.
|
|
9
|
-
"""
|
|
10
|
-
mem_info = psutil.virtual_memory()
|
|
11
|
-
return mem_info.available
|
|
12
|
-
|
|
13
|
-
def estimate_required_memory(num_qubits, overhead_factor=1.5):
|
|
14
|
-
"""
|
|
15
|
-
Estimate the required memory for a given number of qubits in a PennyLane circuit.
|
|
16
|
-
Args:
|
|
17
|
-
num_qubits (int): Number of qubits in the circuit.
|
|
18
|
-
overhead_factor (float): Factor to account for memory overhead.
|
|
19
|
-
Returns:
|
|
20
|
-
required_memory (int): Estimated required memory in bytes.
|
|
21
|
-
"""
|
|
22
|
-
# Size of the state vector in bytes: 16 bytes per complex number
|
|
23
|
-
raw_memory = 16 * (2 ** num_qubits)
|
|
24
|
-
# Add an overhead to account for non-optimized memory usage
|
|
25
|
-
required_memory = int(overhead_factor * raw_memory)
|
|
26
|
-
return required_memory
|
|
27
|
-
|
|
28
|
-
def check_and_run_circuit(circuit, num_qubits):
|
|
29
|
-
"""
|
|
30
|
-
Check if the system has sufficient memory to run a PennyLane circuit.
|
|
31
|
-
Args:
|
|
32
|
-
circuit (qml.QNode): The PennyLane circuit to be executed.
|
|
33
|
-
num_qubits (int): Number of qubits in the circuit.
|
|
34
|
-
Returns:
|
|
35
|
-
result (any): Result of the circuit execution if memory is sufficient.
|
|
36
|
-
"""
|
|
37
|
-
# Estimate the required memory
|
|
38
|
-
required_mem = estimate_required_memory(num_qubits)
|
|
39
|
-
# Check the available memory
|
|
40
|
-
available_mem = available_memory()
|
|
41
|
-
|
|
42
|
-
# Print memory details
|
|
43
|
-
print(f"Available Memory: {available_mem / (1024 ** 3):.2f} GB")
|
|
44
|
-
print(f"Estimated Required Memory: {required_mem / (1024 ** 3):.2f} GB")
|
|
45
|
-
|
|
46
|
-
# Check if there is sufficient memory
|
|
47
|
-
if required_mem > available_mem:
|
|
48
|
-
print("Insufficient memory to run the circuit. Aborting execution.")
|
|
49
|
-
return False
|
|
50
|
-
else:
|
|
51
|
-
print("Sufficient memory available. Executing circuit...")
|
|
52
|
-
return True
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def calculate_quantum_memory(num_qubits, overhead=2):
|
|
56
|
-
# Each qubit state requires 2 complex numbers (amplitude and phase)
|
|
57
|
-
# Each complex number uses 2 double-precision floats (16 bytes)
|
|
58
|
-
bytes_per_qubit_state = 16
|
|
59
|
-
|
|
60
|
-
# Number of possible states is 2^n, where n is the number of qubits
|
|
61
|
-
num_states = 2 ** num_qubits
|
|
62
|
-
|
|
63
|
-
# Total memory in bytes
|
|
64
|
-
total_memory_bytes = num_states * bytes_per_qubit_state * overhead
|
|
65
|
-
|
|
66
|
-
# Convert to more readable units
|
|
67
|
-
|
|
68
|
-
return total_memory_bytes / (1024**3)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def print_memory_requirements(num_qubits):
|
|
74
|
-
memory = calculate_quantum_memory(num_qubits)
|
|
75
|
-
print(f"Memory requirements for {num_qubits} qubits:")
|
|
76
|
-
print(f"Bytes: {memory['bytes']:.2f}")
|
|
77
|
-
print(f"Kilobytes: {memory['kilobytes']:.2f}")
|
|
78
|
-
print(f"Megabytes: {memory['megabytes']:.2f}")
|
|
79
|
-
print(f"Gigabytes: {memory['gigabytes']:.2f}")
|
|
80
|
-
print(f"Terabytes: {memory['terabytes']:.2f}")
|
|
81
|
-
|
|
82
|
-
# Example usage
|
|
83
|
-
for qubits in [4, 8, 16, 24, 32, 48]:
|
|
84
|
-
print_memory_requirements(qubits)
|
|
85
|
-
print()
|
lazyqml-2.0.4.dist-info/RECORD
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
lazyqml/.lazyqmlP.py,sha256=WrR6Ojt526lknpYSzvTgJrm3nkIzdtxIBZFrvjttye4,14063
|
|
2
|
-
lazyqml/.lazyqmlVote.py,sha256=PQD9ulY0Pyr_qpJlF6nAals2ymJ6Uh0jdhBZdxFy-ZI,15243
|
|
3
|
-
lazyqml/Lanza copy.sh,sha256=6GVpT67Jbu5NiV0XoN6WTqhKPhlvl1741d6OqjIbcB0,876
|
|
4
|
-
lazyqml/Lanza.sh,sha256=el5dEtYdOlo5-I3iYhX8s0U-wqJQbY_6XzRL16PRgII,435
|
|
5
|
-
lazyqml/__init__.py,sha256=7POJchipxUuWz69eXJ7NQg1p6vRmCmpmJI-6Vj8u6o0,242
|
|
6
|
-
lazyqml/lazyqml.py,sha256=AyndEVMyBfsiaec2hgazCMhJyaFR1RvHYGvnEllNmXI,14161
|
|
7
|
-
lazyqml/mem.py,sha256=ugNznYQPEo3z3bIRywFqhBt6xOPZZePTqyvpLzdZgjQ,2938
|
|
8
|
-
lazyqml/Factories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
lazyqml/Factories/Circuits/AmplitudeEmbedding.py,sha256=alkSF082NuQk_FkBfCh3fMPu_d6q7kBIfyhYBztlhYo,646
|
|
10
|
-
lazyqml/Factories/Circuits/HCzRx.py,sha256=vJ5R48GBaEyfKayDF6-g-JfRE5eYBJd6dX_nOPqBEX8,1165
|
|
11
|
-
lazyqml/Factories/Circuits/HardwareEfficient.py,sha256=5fsPtLnw24Vdke_OWy-uBdCGoW7q4Af1qRvuEVhC-jc,1812
|
|
12
|
-
lazyqml/Factories/Circuits/RxEmbedding.py,sha256=m47VHQG4gurVD5gcFJBZH5DlfZ1EtDK4rWyBjnqv2k8,631
|
|
13
|
-
lazyqml/Factories/Circuits/RyEmbedding.py,sha256=EJ3Dc9PoKsE2oPjBiLofp_jk8bLl10IJJoq1vbHeEeM,631
|
|
14
|
-
lazyqml/Factories/Circuits/RzEmbedding.py,sha256=fKL5Mi7JNWsy9qr6PAOS3FFa97m7XUPtUZ2sWHcHYJA,699
|
|
15
|
-
lazyqml/Factories/Circuits/TreeTensor.py,sha256=FRgLe9VariRKUYiNXqiKp1fxdSEV1AvgFNwAFYyAPlU,1298
|
|
16
|
-
lazyqml/Factories/Circuits/TwoLocal.py,sha256=9TVqLlGTmcaVz92vfJCiTHgjJrcvQoT-9wZJL2O3HEw,970
|
|
17
|
-
lazyqml/Factories/Circuits/ZzEmbedding.py,sha256=x3jRAxJcd1uvacvIYyDL39TE-jNVeHhSTUUIREh4XZE,1070
|
|
18
|
-
lazyqml/Factories/Circuits/_Qkernel.py,sha256=HDJJ31zr-dFh2jEy9bcC4BzzE9Jwx0WvG0aq_f5SVkA,619
|
|
19
|
-
lazyqml/Factories/Circuits/_Qnn.py,sha256=ksYeo1w32Getk5sN7MgXbjBGbwQKerkM0ONRJttjfgc,566
|
|
20
|
-
lazyqml/Factories/Circuits/fCircuits.py,sha256=s7t_o5ieKiq8t34qCZhPw_Hww6GmLBwM8Lbo74yrC38,1740
|
|
21
|
-
lazyqml/Factories/Dispatchers/Dispatcher.py,sha256=jPVjEeNOYpMMNEth4wjv64aen2r_1BIHB4NlWbOSLAc,6457
|
|
22
|
-
lazyqml/Factories/Dispatchers/DispatcherCV.py,sha256=Ok4Baz1PSDEkKrJBQ3MxEMxeUTKxtGZiSjGKaw6pruQ,6443
|
|
23
|
-
lazyqml/Factories/Dispatchers/DispatcherNumba.py,sha256=NyibTqImjjuyMU-P4Wn4VFEUrh3FLG8UzbGeh-D4STE,9392
|
|
24
|
-
lazyqml/Factories/Dispatchers/_Dispatcher.py,sha256=0I0AANujQbQVU-PfpAZRpCcdvv42oFWu7qHQQyA0Z7I,8632
|
|
25
|
-
lazyqml/Factories/Dispatchers/_DispatcherMultiprocessing.py,sha256=NLzF4yAdfqf7YF0v0leAZYkrsS8kbmes5Buv8eAopLI,8830
|
|
26
|
-
lazyqml/Factories/Dispatchers/_QNNBagdispatcher.py,sha256=825K5sbEe1mn1gK2zjj07nUXKmXBHOyAca9nfl6hZFo,41
|
|
27
|
-
lazyqml/Factories/Dispatchers/_QNNdispatcher.py,sha256=lqlRxKbx2echnWIu4oyBqi0IEH0_CliC9Fas4ABKx0U,38
|
|
28
|
-
lazyqml/Factories/Dispatchers/_QSVMdispatcher.py,sha256=N9D5OrswlNwqu05QfO2y0LCy8_FoFCYMaSiEq1mpLlc,3923
|
|
29
|
-
lazyqml/Factories/Dispatchers/__Dispatcher.py,sha256=tmTcl_9whBCXFObla8YudsC_qKeSwDIZtDYHacwBZ-o,8794
|
|
30
|
-
lazyqml/Factories/Models/QNNBag.py,sha256=OUaZkEJ97WieFxHYx5lk-AixQGEmI7qp2oFJ_xS_Qms,6608
|
|
31
|
-
lazyqml/Factories/Models/QNNTorch.py,sha256=tln-vO2jRCLVF0IaA63O04768fSIUHs7XLbY4fj0XAM,6577
|
|
32
|
-
lazyqml/Factories/Models/QSVM.py,sha256=X3NUqZTck-rJwg24zqfhqy6xAU5ejPqNYRVgwlO_qws,3249
|
|
33
|
-
lazyqml/Factories/Models/_QNNPennylane.py,sha256=Jpao8PDGA6wrjw651GA8OmmrlAxFciJHj97T2_voamw,3412
|
|
34
|
-
lazyqml/Factories/Models/fModels.py,sha256=0WMazRhDrf9y-DUovZmFDtd-26WXK71MvYq31wav7oE,1374
|
|
35
|
-
lazyqml/Factories/Preprocessing/Pca.py,sha256=TbU2_Y83Eqaha6BhY8wm0YQOzFkcIn6rwVwY8eCvf8g,1000
|
|
36
|
-
lazyqml/Factories/Preprocessing/Sanitizer.py,sha256=iTlu94bPGUJdiyvT7m710wmn55F0F7QuKRzo4lM0sfA,1101
|
|
37
|
-
lazyqml/Factories/Preprocessing/_PcaAmp.py,sha256=HPnH98HF9pQYOV_xUkudmTPPHRpYdXdjYQVDckLtLfc,756
|
|
38
|
-
lazyqml/Factories/Preprocessing/_PcaTree.py,sha256=9QCnj56WyJf3qw4pKwpvX1YjDGuWymt8e1P9drwDqSs,779
|
|
39
|
-
lazyqml/Factories/Preprocessing/_PcaTreeAmp.py,sha256=9yndmz7ntEUKCP2D-F2kSKOool359DiRaqT4Sc_lTas,787
|
|
40
|
-
lazyqml/Factories/Preprocessing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
41
|
-
lazyqml/Factories/Preprocessing/fPreprocessing.py,sha256=tD12zgWmeyAgZ0-fIdaLAYiXOClSQ3ml1xh8mh-ekT0,1418
|
|
42
|
-
lazyqml/Global/globalEnums.py,sha256=eALA2Zulcu4Pkw9wGmT8I-k9NlBqyuDiw64Wv9P8whE,728
|
|
43
|
-
lazyqml/Interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
44
|
-
lazyqml/Interfaces/iAnsatz.py,sha256=BzXiM9Ed4iav6jq0TrNRxOTOorPQazZA9a07JsdKbW0,164
|
|
45
|
-
lazyqml/Interfaces/iCircuit.py,sha256=L-GbUQmJ2s0uc5AjJj4zIruWP7XSycpG-C8xI4_wnxc,115
|
|
46
|
-
lazyqml/Interfaces/iModel.py,sha256=W_yYoZd7hS8ZKGvNAyl-waJ6f7F0kIM6zrg9WqyPt_I,176
|
|
47
|
-
lazyqml/Interfaces/iPreprocessing.py,sha256=O9f2tCnWTbjkHi4_XKaPWsE2SWKsdI1pj2lCyBWih9o,255
|
|
48
|
-
lazyqml/Utils/Utils.py,sha256=eIX3ah5I51PZWjlZdf2z0kkmaeKdlDKtAKLpgiYQvmU,5328
|
|
49
|
-
lazyqml/Utils/Validator.py,sha256=1KD9NGb5Bw9koyjmPLLdiJ8pbuWIcjIt4eAHAkLZ2_w,4789
|
|
50
|
-
lazyqml-2.0.4.dist-info/AUTHORS.rst,sha256=Y_bDRslOAz5wcAYrTAnjDlmlW-51LfVF0Xwf09TbW3Y,245
|
|
51
|
-
lazyqml-2.0.4.dist-info/LICENSE,sha256=y9EYvUN_l9ZWDuiVcxHE1NWbfy_HR9Z-8G19719ynbQ,1077
|
|
52
|
-
lazyqml-2.0.4.dist-info/METADATA,sha256=d5ouNueIr_e36RZbTIwWDFobF2mn63llKaTZqF84nlE,8728
|
|
53
|
-
lazyqml-2.0.4.dist-info/WHEEL,sha256=B03JAMGq6-VHSCrtDNma_J9UaPCNDvoQGYRXpzGHxgg,109
|
|
54
|
-
lazyqml-2.0.4.dist-info/entry_points.txt,sha256=I0WR08yVIeXjSa8XBSGZ9SsZtM8uMvKwZOdU1qQajao,45
|
|
55
|
-
lazyqml-2.0.4.dist-info/top_level.txt,sha256=x2ffpytT-NeXmC7YaZLSQNMLK0pLfUiRmGOqwNbyjZE,8
|
|
56
|
-
lazyqml-2.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|