lazyqml 3.0.4__tar.gz → 3.0.6__tar.gz
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-3.0.6/PKG-INFO +255 -0
- lazyqml-3.0.6/README.md +216 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/AmplitudeEmbedding.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/HCzRx.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/HardwareEfficient.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/RxEmbedding.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/RyEmbedding.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/RzEmbedding.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/TreeTensor.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/TwoLocal.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/ZzEmbedding.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Circuits/fCircuits.py +10 -10
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Models/Hybrid.py +3 -6
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Models/QNNBag.py +6 -6
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Models/QNNTorch.py +6 -6
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Models/QSVM.py +3 -3
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Models/fModels.py +4 -4
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Interfaces/iAnsatz.py +1 -1
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/__init__.py +1 -1
- lazyqml-3.0.6/lazyqml.egg-info/PKG-INFO +255 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/pyproject.toml +2 -2
- lazyqml-3.0.4/PKG-INFO +0 -122
- lazyqml-3.0.4/README.md +0 -83
- lazyqml-3.0.4/lazyqml.egg-info/PKG-INFO +0 -122
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.editorconfig +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.github/workflows/docs-build.yml +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.github/workflows/docs.yml +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.github/workflows/installation.yml +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.github/workflows/pypi.yml +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.github/workflows/ubuntu.yml +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/.gitignore +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/AUTHORS.rst +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/LICENSE +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/LICENSE copy +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/MANIFEST.in +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/README copy.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/authors.rst +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/changelog.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/common.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/contributing.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/examples/intro.ipynb +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/faq.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/index.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/installation.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/lazyqml.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/overrides/main.html +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/docs/usage.md +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/experimentallibs.txt +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Dispatchers/Dispatcher.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Models/_QNNPennylane.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Preprocessing/Pca.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Preprocessing/Sanitizer.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Preprocessing/__init__.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/Preprocessing/fPreprocessing.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Factories/__init__.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Global/globalEnums.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Interfaces/__init__.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Interfaces/iCircuit.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Interfaces/iModel.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Interfaces/iPreprocessing.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Utils/Utils.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/Utils/Validator.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml/lazyqml.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml.egg-info/SOURCES.txt +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml.egg-info/dependency_links.txt +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml.egg-info/entry_points.txt +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml.egg-info/requires.txt +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/lazyqml.egg-info/top_level.txt +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/mkdocs.yml +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/requirements.txt +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/requirements_dev.txt +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/setup.cfg +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/tests/__init__.py +0 -0
- {lazyqml-3.0.4 → lazyqml-3.0.6}/tests/test_lazyqml.py +0 -0
lazyqml-3.0.6/PKG-INFO
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: lazyqml
|
|
3
|
+
Version: 3.0.6
|
|
4
|
+
Summary: LazyQML benchmarking utility to test quantum machine learning models.
|
|
5
|
+
Author-email: QHPC Group <qhpcgroup@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
Project-URL: Homepage, https://github.com/QHPC-SP-Research-Lab/LazyQML
|
|
8
|
+
Keywords: lazyqml
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Natural Language :: English
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
License-File: LICENSE copy
|
|
17
|
+
License-File: AUTHORS.rst
|
|
18
|
+
Requires-Dist: wheel
|
|
19
|
+
Requires-Dist: tabulate
|
|
20
|
+
Requires-Dist: torch
|
|
21
|
+
Requires-Dist: torchaudio
|
|
22
|
+
Requires-Dist: torchvision
|
|
23
|
+
Requires-Dist: scipy
|
|
24
|
+
Requires-Dist: scikit-learn
|
|
25
|
+
Requires-Dist: PennyLane
|
|
26
|
+
Requires-Dist: PennyLane_Lightning
|
|
27
|
+
Requires-Dist: PennyLane_Lightning_GPU
|
|
28
|
+
Requires-Dist: custatevec_cu12
|
|
29
|
+
Requires-Dist: ucimlrepo
|
|
30
|
+
Requires-Dist: pydantic
|
|
31
|
+
Requires-Dist: psutil
|
|
32
|
+
Requires-Dist: pandas
|
|
33
|
+
Requires-Dist: joblib
|
|
34
|
+
Requires-Dist: gputil
|
|
35
|
+
Provides-Extra: all
|
|
36
|
+
Requires-Dist: lazyqml[extra]; extra == "all"
|
|
37
|
+
Provides-Extra: extra
|
|
38
|
+
Requires-Dist: pandas; extra == "extra"
|
|
39
|
+
|
|
40
|
+
# LazyQML
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
[](https://pypi.python.org/pypi/lazyqml)
|
|
44
|
+

|
|
45
|
+

|
|
46
|
+

|
|
47
|
+

|
|
48
|
+

|
|
49
|
+

|
|
50
|
+
<img src="https://assets.cloud.pennylane.ai/pennylane_website/generic/logo.svg" alt="Pennylane Logo" style="background-color: white; padding: 2px;" />
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
<!--  -->
|
|
54
|
+
|
|
55
|
+
pLazyQML, a software package designed to accelerate, automate, and streamline experimentation with quantum machine learning models on classical computers. pLazyQML reduces the complexity and time required for developing and testing quantum-enhanced machine learning models.
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
```bash
|
|
59
|
+
$ pip install lazyqml --upgrade
|
|
60
|
+
```
|
|
61
|
+
## Usage
|
|
62
|
+
```python
|
|
63
|
+
from sklearn.datasets import load_iris
|
|
64
|
+
from lazyqml.lazyqml import *
|
|
65
|
+
|
|
66
|
+
# Load data
|
|
67
|
+
data = load_iris()
|
|
68
|
+
X = data.data
|
|
69
|
+
y = data.target
|
|
70
|
+
|
|
71
|
+
classifier = QuantumClassifier(nqubits={4}, classifiers={Model.QNN, Model.QSVM}, epochs=10)
|
|
72
|
+
|
|
73
|
+
# Fit and predict
|
|
74
|
+
classifier.fit(X=X, y=y, test_size=0.4)
|
|
75
|
+
```
|
|
76
|
+
### Output
|
|
77
|
+
| Qubits | Model | Embedding | Ansatz | Time taken | Accuracy | Balanced Accuracy | F1 Score |
|
|
78
|
+
|---------:|:-----------|:--------------|:---------------------------|-------------:|-----------:|--------------------:|-----------:|
|
|
79
|
+
| 4 | Model.QSVM | Embedding.RZ | | 18.2478 | 0.966667 | 0.966667 | 0.966583 |
|
|
80
|
+
| 4 | Model.QSVM | Embedding.RY | | 13.8088 | 0.966667 | 0.966667 | 0.966583 |
|
|
81
|
+
| 4 | Model.QSVM | Embedding.RX | | 13.7079 | 0.966667 | 0.966667 | 0.966583 |
|
|
82
|
+
| 4 | Model.QNN | Embedding.RX | Ansatzs.HARDWARE_EFFICIENT | 11.1699 | 0.933333 | 0.933333 | 0.932896 |
|
|
83
|
+
| 4 | Model.QNN | Embedding.RZ | Ansatzs.HARDWARE_EFFICIENT | 11.7565 | 0.9 | 0.9 | 0.899206 |
|
|
84
|
+
| 4 | Model.QNN | Embedding.RY | Ansatzs.HARDWARE_EFFICIENT | 11.8614 | 0.9 | 0.9 | 0.899948 |
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## License & Compatibility
|
|
88
|
+
- Free software: MIT License
|
|
89
|
+
- This Python package is only compatible with Linux systems.
|
|
90
|
+
- Hardware acceleration is only enabled using CUDA-compatible devices.
|
|
91
|
+
## Quantum and High Performance Computing (QHPC) - University of Oviedo
|
|
92
|
+
- José Ranilla Pastor - ranilla@uniovi.es
|
|
93
|
+
- Elías Fernández Combarro - efernandezca@uniovi.es
|
|
94
|
+
- Diego García Vega - diegogarciavega@gmail.com
|
|
95
|
+
- Fernando Álvaro Plou Llorente - ploufernando@uniovi.es
|
|
96
|
+
- Alejandro Leal Castaño - lealcalejandro@uniovi.es
|
|
97
|
+
- Group - https://qhpc.uniovi.es
|
|
98
|
+
|
|
99
|
+
## QuantumClassifier Parameters:
|
|
100
|
+
#### Core Parameters:
|
|
101
|
+
- **`nqubits`**: `Set[int]`
|
|
102
|
+
- Description: Set of qubit indices, where each value must be greater than 0.
|
|
103
|
+
- Validation: Ensures that all elements are integers > 0.
|
|
104
|
+
|
|
105
|
+
- **`randomstate`**: `int`
|
|
106
|
+
- Description: Seed value for random number generation.
|
|
107
|
+
- Default: `1234`
|
|
108
|
+
|
|
109
|
+
- **`predictions`**: `bool`
|
|
110
|
+
- Description: Flag to determine if predictions are enabled.
|
|
111
|
+
- Default: `False`
|
|
112
|
+
|
|
113
|
+
#### Model Structure Parameters:
|
|
114
|
+
- **`numPredictors`**: `int`
|
|
115
|
+
- Description: Number of predictors used in the QNN with bagging.
|
|
116
|
+
- Constraints: Must be greater than 0.
|
|
117
|
+
- Default: `10`
|
|
118
|
+
|
|
119
|
+
- **`numLayers`**: `int`
|
|
120
|
+
- Description: Number of layers in the Quantum Neural Networks.
|
|
121
|
+
- Constraints: Must be greater than 0.
|
|
122
|
+
- Default: `5`
|
|
123
|
+
|
|
124
|
+
#### Set-Based Configuration Parameters:
|
|
125
|
+
- **`classifiers`**: `Set[Model]`
|
|
126
|
+
- Description: Set of classifier models.
|
|
127
|
+
- Constraints: Must contain at least one classifier.
|
|
128
|
+
- Default: `{Model.ALL}`
|
|
129
|
+
- Options: `{Model.QNN, Model.QSVM, Model.QNN_BAG}`
|
|
130
|
+
|
|
131
|
+
- **`ansatzs`**: `Set[Ansatzs]`
|
|
132
|
+
- Description: Set of quantum ansatz configurations.
|
|
133
|
+
- Constraints: Must contain at least one ansatz.
|
|
134
|
+
- Default: `{Ansatzs.ALL}`
|
|
135
|
+
- Options: `{Ansatzs.RX, Ansatzs.RZ, Ansatzs.RY, Ansatzs.ZZ, Ansatzs.AMP}`
|
|
136
|
+
|
|
137
|
+
- **`embeddings`**: `Set[Embedding]`
|
|
138
|
+
- Description: Set of embedding strategies.
|
|
139
|
+
- Constraints: Must contain at least one embedding.
|
|
140
|
+
- Default: `{Embedding.ALL}`
|
|
141
|
+
- Options: `{Embedding.HCZRX, Embedding.TREE_TENSOR, Embedding.TWO_LOCAL, Embedding.HARDWARE_EFFICENT}`
|
|
142
|
+
|
|
143
|
+
- **`features`**: `Set[float]`
|
|
144
|
+
- Description: Set of feature values (must be between 0 and 1).
|
|
145
|
+
- Constraints: Values > 0 and <= 1.
|
|
146
|
+
- Default: `{0.3, 0.5, 0.8}`
|
|
147
|
+
|
|
148
|
+
#### Training Parameters:
|
|
149
|
+
- **`learningRate`**: `float`
|
|
150
|
+
- Description: Learning rate for optimization.
|
|
151
|
+
- Constraints: Must be greater than 0.
|
|
152
|
+
- Default: `0.01`
|
|
153
|
+
|
|
154
|
+
- **`epochs`**: `int`
|
|
155
|
+
- Description: Number of training epochs.
|
|
156
|
+
- Constraints: Must be greater than 0.
|
|
157
|
+
- Default: `100`
|
|
158
|
+
|
|
159
|
+
- **`batchSize`**: `int`
|
|
160
|
+
- Description: Size of each batch during training.
|
|
161
|
+
- Constraints: Must be greater than 0.
|
|
162
|
+
- Default: `8`
|
|
163
|
+
|
|
164
|
+
#### Threshold and Sampling:
|
|
165
|
+
- **`threshold`**: `int`
|
|
166
|
+
- Description: Decision threshold for parallelization, if the model is bigger than this threshold it will use GPU.
|
|
167
|
+
- Constraints: Must be greater than 0.
|
|
168
|
+
- Default: `22`
|
|
169
|
+
|
|
170
|
+
- **`maxSamples`**: `float`
|
|
171
|
+
- Description: Maximum proportion of samples to be used from the dataset characteristics.
|
|
172
|
+
- Constraints: Between 0 and 1.
|
|
173
|
+
- Default: `1.0`
|
|
174
|
+
|
|
175
|
+
#### Logging and Metrics:
|
|
176
|
+
- **`verbose`**: `bool`
|
|
177
|
+
- Description: Flag for detailed output during training.
|
|
178
|
+
- Default: `False`
|
|
179
|
+
|
|
180
|
+
- **`customMetric`**: `Optional[Callable]`
|
|
181
|
+
- Description: User-defined metric function for evaluation.
|
|
182
|
+
- Validation:
|
|
183
|
+
- Function must accept `y_true` and `y_pred` as the first two arguments.
|
|
184
|
+
- Must return a scalar value (int or float).
|
|
185
|
+
- Function execution is validated with dummy arguments.
|
|
186
|
+
- Default: `None`
|
|
187
|
+
|
|
188
|
+
#### Custom Preprocessors:
|
|
189
|
+
- **`customImputerNum`**: `Optional[Any]`
|
|
190
|
+
- Description: Custom numeric data imputer.
|
|
191
|
+
- Validation:
|
|
192
|
+
- Must be an object with `fit`, `transform`, and optionally `fit_transform` methods.
|
|
193
|
+
- Validated with dummy data.
|
|
194
|
+
- Default: `None`
|
|
195
|
+
|
|
196
|
+
- **`customImputerCat`**: `Optional[Any]`
|
|
197
|
+
- Description: Custom categorical data imputer.
|
|
198
|
+
- Validation:
|
|
199
|
+
- Must be an object with `fit`, `transform`, and optionally `fit_transform` methods.
|
|
200
|
+
- Validated with dummy data.
|
|
201
|
+
- Default: `None`
|
|
202
|
+
|
|
203
|
+
## Functions:
|
|
204
|
+
|
|
205
|
+
### **`fit`**
|
|
206
|
+
```python
|
|
207
|
+
fit(self, X, y, test_size=0.4, showTable=True)
|
|
208
|
+
```
|
|
209
|
+
Fits classification algorithms to `X` and `y` using a hold-out approach. Predicts and scores on a test set determined by `test_size`.
|
|
210
|
+
|
|
211
|
+
#### Parameters:
|
|
212
|
+
- **`X`**: Input features (DataFrame or compatible format).
|
|
213
|
+
- **`y`**: Target labels (must be numeric, e.g., via `LabelEncoder` or `OrdinalEncoder`).
|
|
214
|
+
- **`test_size`**: Proportion of the dataset to use as the test set. Default is `0.4`.
|
|
215
|
+
- **`showTable`**: Display a table with results. Default is `True`.
|
|
216
|
+
|
|
217
|
+
#### Behavior:
|
|
218
|
+
- Validates the compatibility of input dimensions.
|
|
219
|
+
- Automatically applies PCA transformation for incompatible dimensions.
|
|
220
|
+
- Requires all categories to be present in training data.
|
|
221
|
+
|
|
222
|
+
### **`repeated_cross_validation`**
|
|
223
|
+
```python
|
|
224
|
+
repeated_cross_validation(self, X, y, n_splits=10, n_repeats=5, showTable=True)
|
|
225
|
+
```
|
|
226
|
+
Performs repeated cross-validation on the dataset using the specified splits and repeats.
|
|
227
|
+
|
|
228
|
+
#### Parameters:
|
|
229
|
+
- **`X`**: Input features (DataFrame or compatible format).
|
|
230
|
+
- **`y`**: Target labels (must be numeric).
|
|
231
|
+
- **`n_splits`**: Number of folds for splitting the dataset. Default is `10`.
|
|
232
|
+
- **`n_repeats`**: Number of times cross-validation is repeated. Default is `5`.
|
|
233
|
+
- **`showTable`**: Display a table with results. Default is `True`.
|
|
234
|
+
|
|
235
|
+
#### Behavior:
|
|
236
|
+
- Uses `RepeatedStratifiedKFold` for generating splits.
|
|
237
|
+
- Aggregates results from multiple train-test splits.
|
|
238
|
+
|
|
239
|
+
### **`leave_one_out`**
|
|
240
|
+
```python
|
|
241
|
+
leave_one_out(self, X, y, showTable=True)
|
|
242
|
+
```
|
|
243
|
+
Performs leave-one-out cross-validation on the dataset.
|
|
244
|
+
|
|
245
|
+
#### Parameters:
|
|
246
|
+
- **`X`**: Input features (DataFrame or compatible format).
|
|
247
|
+
- **`y`**: Target labels (must be numeric).
|
|
248
|
+
- **`showTable`**: Display a table with results. Default is `True`.
|
|
249
|
+
|
|
250
|
+
#### Behavior:
|
|
251
|
+
- Uses `LeaveOneOut` for generating train-test splits.
|
|
252
|
+
- Evaluates the model on each split and aggregates results.
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
lazyqml-3.0.6/README.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# LazyQML
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
[](https://pypi.python.org/pypi/lazyqml)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
<img src="https://assets.cloud.pennylane.ai/pennylane_website/generic/logo.svg" alt="Pennylane Logo" style="background-color: white; padding: 2px;" />
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
<!--  -->
|
|
15
|
+
|
|
16
|
+
pLazyQML, a software package designed to accelerate, automate, and streamline experimentation with quantum machine learning models on classical computers. pLazyQML reduces the complexity and time required for developing and testing quantum-enhanced machine learning models.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
```bash
|
|
20
|
+
$ pip install lazyqml --upgrade
|
|
21
|
+
```
|
|
22
|
+
## Usage
|
|
23
|
+
```python
|
|
24
|
+
from sklearn.datasets import load_iris
|
|
25
|
+
from lazyqml.lazyqml import *
|
|
26
|
+
|
|
27
|
+
# Load data
|
|
28
|
+
data = load_iris()
|
|
29
|
+
X = data.data
|
|
30
|
+
y = data.target
|
|
31
|
+
|
|
32
|
+
classifier = QuantumClassifier(nqubits={4}, classifiers={Model.QNN, Model.QSVM}, epochs=10)
|
|
33
|
+
|
|
34
|
+
# Fit and predict
|
|
35
|
+
classifier.fit(X=X, y=y, test_size=0.4)
|
|
36
|
+
```
|
|
37
|
+
### Output
|
|
38
|
+
| Qubits | Model | Embedding | Ansatz | Time taken | Accuracy | Balanced Accuracy | F1 Score |
|
|
39
|
+
|---------:|:-----------|:--------------|:---------------------------|-------------:|-----------:|--------------------:|-----------:|
|
|
40
|
+
| 4 | Model.QSVM | Embedding.RZ | | 18.2478 | 0.966667 | 0.966667 | 0.966583 |
|
|
41
|
+
| 4 | Model.QSVM | Embedding.RY | | 13.8088 | 0.966667 | 0.966667 | 0.966583 |
|
|
42
|
+
| 4 | Model.QSVM | Embedding.RX | | 13.7079 | 0.966667 | 0.966667 | 0.966583 |
|
|
43
|
+
| 4 | Model.QNN | Embedding.RX | Ansatzs.HARDWARE_EFFICIENT | 11.1699 | 0.933333 | 0.933333 | 0.932896 |
|
|
44
|
+
| 4 | Model.QNN | Embedding.RZ | Ansatzs.HARDWARE_EFFICIENT | 11.7565 | 0.9 | 0.9 | 0.899206 |
|
|
45
|
+
| 4 | Model.QNN | Embedding.RY | Ansatzs.HARDWARE_EFFICIENT | 11.8614 | 0.9 | 0.9 | 0.899948 |
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## License & Compatibility
|
|
49
|
+
- Free software: MIT License
|
|
50
|
+
- This Python package is only compatible with Linux systems.
|
|
51
|
+
- Hardware acceleration is only enabled using CUDA-compatible devices.
|
|
52
|
+
## Quantum and High Performance Computing (QHPC) - University of Oviedo
|
|
53
|
+
- José Ranilla Pastor - ranilla@uniovi.es
|
|
54
|
+
- Elías Fernández Combarro - efernandezca@uniovi.es
|
|
55
|
+
- Diego García Vega - diegogarciavega@gmail.com
|
|
56
|
+
- Fernando Álvaro Plou Llorente - ploufernando@uniovi.es
|
|
57
|
+
- Alejandro Leal Castaño - lealcalejandro@uniovi.es
|
|
58
|
+
- Group - https://qhpc.uniovi.es
|
|
59
|
+
|
|
60
|
+
## QuantumClassifier Parameters:
|
|
61
|
+
#### Core Parameters:
|
|
62
|
+
- **`nqubits`**: `Set[int]`
|
|
63
|
+
- Description: Set of qubit indices, where each value must be greater than 0.
|
|
64
|
+
- Validation: Ensures that all elements are integers > 0.
|
|
65
|
+
|
|
66
|
+
- **`randomstate`**: `int`
|
|
67
|
+
- Description: Seed value for random number generation.
|
|
68
|
+
- Default: `1234`
|
|
69
|
+
|
|
70
|
+
- **`predictions`**: `bool`
|
|
71
|
+
- Description: Flag to determine if predictions are enabled.
|
|
72
|
+
- Default: `False`
|
|
73
|
+
|
|
74
|
+
#### Model Structure Parameters:
|
|
75
|
+
- **`numPredictors`**: `int`
|
|
76
|
+
- Description: Number of predictors used in the QNN with bagging.
|
|
77
|
+
- Constraints: Must be greater than 0.
|
|
78
|
+
- Default: `10`
|
|
79
|
+
|
|
80
|
+
- **`numLayers`**: `int`
|
|
81
|
+
- Description: Number of layers in the Quantum Neural Networks.
|
|
82
|
+
- Constraints: Must be greater than 0.
|
|
83
|
+
- Default: `5`
|
|
84
|
+
|
|
85
|
+
#### Set-Based Configuration Parameters:
|
|
86
|
+
- **`classifiers`**: `Set[Model]`
|
|
87
|
+
- Description: Set of classifier models.
|
|
88
|
+
- Constraints: Must contain at least one classifier.
|
|
89
|
+
- Default: `{Model.ALL}`
|
|
90
|
+
- Options: `{Model.QNN, Model.QSVM, Model.QNN_BAG}`
|
|
91
|
+
|
|
92
|
+
- **`ansatzs`**: `Set[Ansatzs]`
|
|
93
|
+
- Description: Set of quantum ansatz configurations.
|
|
94
|
+
- Constraints: Must contain at least one ansatz.
|
|
95
|
+
- Default: `{Ansatzs.ALL}`
|
|
96
|
+
- Options: `{Ansatzs.RX, Ansatzs.RZ, Ansatzs.RY, Ansatzs.ZZ, Ansatzs.AMP}`
|
|
97
|
+
|
|
98
|
+
- **`embeddings`**: `Set[Embedding]`
|
|
99
|
+
- Description: Set of embedding strategies.
|
|
100
|
+
- Constraints: Must contain at least one embedding.
|
|
101
|
+
- Default: `{Embedding.ALL}`
|
|
102
|
+
- Options: `{Embedding.HCZRX, Embedding.TREE_TENSOR, Embedding.TWO_LOCAL, Embedding.HARDWARE_EFFICENT}`
|
|
103
|
+
|
|
104
|
+
- **`features`**: `Set[float]`
|
|
105
|
+
- Description: Set of feature values (must be between 0 and 1).
|
|
106
|
+
- Constraints: Values > 0 and <= 1.
|
|
107
|
+
- Default: `{0.3, 0.5, 0.8}`
|
|
108
|
+
|
|
109
|
+
#### Training Parameters:
|
|
110
|
+
- **`learningRate`**: `float`
|
|
111
|
+
- Description: Learning rate for optimization.
|
|
112
|
+
- Constraints: Must be greater than 0.
|
|
113
|
+
- Default: `0.01`
|
|
114
|
+
|
|
115
|
+
- **`epochs`**: `int`
|
|
116
|
+
- Description: Number of training epochs.
|
|
117
|
+
- Constraints: Must be greater than 0.
|
|
118
|
+
- Default: `100`
|
|
119
|
+
|
|
120
|
+
- **`batchSize`**: `int`
|
|
121
|
+
- Description: Size of each batch during training.
|
|
122
|
+
- Constraints: Must be greater than 0.
|
|
123
|
+
- Default: `8`
|
|
124
|
+
|
|
125
|
+
#### Threshold and Sampling:
|
|
126
|
+
- **`threshold`**: `int`
|
|
127
|
+
- Description: Decision threshold for parallelization, if the model is bigger than this threshold it will use GPU.
|
|
128
|
+
- Constraints: Must be greater than 0.
|
|
129
|
+
- Default: `22`
|
|
130
|
+
|
|
131
|
+
- **`maxSamples`**: `float`
|
|
132
|
+
- Description: Maximum proportion of samples to be used from the dataset characteristics.
|
|
133
|
+
- Constraints: Between 0 and 1.
|
|
134
|
+
- Default: `1.0`
|
|
135
|
+
|
|
136
|
+
#### Logging and Metrics:
|
|
137
|
+
- **`verbose`**: `bool`
|
|
138
|
+
- Description: Flag for detailed output during training.
|
|
139
|
+
- Default: `False`
|
|
140
|
+
|
|
141
|
+
- **`customMetric`**: `Optional[Callable]`
|
|
142
|
+
- Description: User-defined metric function for evaluation.
|
|
143
|
+
- Validation:
|
|
144
|
+
- Function must accept `y_true` and `y_pred` as the first two arguments.
|
|
145
|
+
- Must return a scalar value (int or float).
|
|
146
|
+
- Function execution is validated with dummy arguments.
|
|
147
|
+
- Default: `None`
|
|
148
|
+
|
|
149
|
+
#### Custom Preprocessors:
|
|
150
|
+
- **`customImputerNum`**: `Optional[Any]`
|
|
151
|
+
- Description: Custom numeric data imputer.
|
|
152
|
+
- Validation:
|
|
153
|
+
- Must be an object with `fit`, `transform`, and optionally `fit_transform` methods.
|
|
154
|
+
- Validated with dummy data.
|
|
155
|
+
- Default: `None`
|
|
156
|
+
|
|
157
|
+
- **`customImputerCat`**: `Optional[Any]`
|
|
158
|
+
- Description: Custom categorical data imputer.
|
|
159
|
+
- Validation:
|
|
160
|
+
- Must be an object with `fit`, `transform`, and optionally `fit_transform` methods.
|
|
161
|
+
- Validated with dummy data.
|
|
162
|
+
- Default: `None`
|
|
163
|
+
|
|
164
|
+
## Functions:
|
|
165
|
+
|
|
166
|
+
### **`fit`**
|
|
167
|
+
```python
|
|
168
|
+
fit(self, X, y, test_size=0.4, showTable=True)
|
|
169
|
+
```
|
|
170
|
+
Fits classification algorithms to `X` and `y` using a hold-out approach. Predicts and scores on a test set determined by `test_size`.
|
|
171
|
+
|
|
172
|
+
#### Parameters:
|
|
173
|
+
- **`X`**: Input features (DataFrame or compatible format).
|
|
174
|
+
- **`y`**: Target labels (must be numeric, e.g., via `LabelEncoder` or `OrdinalEncoder`).
|
|
175
|
+
- **`test_size`**: Proportion of the dataset to use as the test set. Default is `0.4`.
|
|
176
|
+
- **`showTable`**: Display a table with results. Default is `True`.
|
|
177
|
+
|
|
178
|
+
#### Behavior:
|
|
179
|
+
- Validates the compatibility of input dimensions.
|
|
180
|
+
- Automatically applies PCA transformation for incompatible dimensions.
|
|
181
|
+
- Requires all categories to be present in training data.
|
|
182
|
+
|
|
183
|
+
### **`repeated_cross_validation`**
|
|
184
|
+
```python
|
|
185
|
+
repeated_cross_validation(self, X, y, n_splits=10, n_repeats=5, showTable=True)
|
|
186
|
+
```
|
|
187
|
+
Performs repeated cross-validation on the dataset using the specified splits and repeats.
|
|
188
|
+
|
|
189
|
+
#### Parameters:
|
|
190
|
+
- **`X`**: Input features (DataFrame or compatible format).
|
|
191
|
+
- **`y`**: Target labels (must be numeric).
|
|
192
|
+
- **`n_splits`**: Number of folds for splitting the dataset. Default is `10`.
|
|
193
|
+
- **`n_repeats`**: Number of times cross-validation is repeated. Default is `5`.
|
|
194
|
+
- **`showTable`**: Display a table with results. Default is `True`.
|
|
195
|
+
|
|
196
|
+
#### Behavior:
|
|
197
|
+
- Uses `RepeatedStratifiedKFold` for generating splits.
|
|
198
|
+
- Aggregates results from multiple train-test splits.
|
|
199
|
+
|
|
200
|
+
### **`leave_one_out`**
|
|
201
|
+
```python
|
|
202
|
+
leave_one_out(self, X, y, showTable=True)
|
|
203
|
+
```
|
|
204
|
+
Performs leave-one-out cross-validation on the dataset.
|
|
205
|
+
|
|
206
|
+
#### Parameters:
|
|
207
|
+
- **`X`**: Input features (DataFrame or compatible format).
|
|
208
|
+
- **`y`**: Target labels (must be numeric).
|
|
209
|
+
- **`showTable`**: Display a table with results. Default is `True`.
|
|
210
|
+
|
|
211
|
+
#### Behavior:
|
|
212
|
+
- Uses `LeaveOneOut` for generating train-test splits.
|
|
213
|
+
- Evaluates the model on each split and aggregates results.
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Importing Enums
|
|
2
|
-
from Global.globalEnums import Ansatzs, Embedding
|
|
2
|
+
from lazyqml.Global.globalEnums import Ansatzs, Embedding
|
|
3
3
|
# Importing Ansatzs
|
|
4
|
-
from Factories.Circuits.TwoLocal import *
|
|
5
|
-
from Factories.Circuits.HardwareEfficient import *
|
|
6
|
-
from Factories.Circuits.TreeTensor import *
|
|
7
|
-
from Factories.Circuits.HCzRx import *
|
|
4
|
+
from lazyqml.Factories.Circuits.TwoLocal import *
|
|
5
|
+
from lazyqml.Factories.Circuits.HardwareEfficient import *
|
|
6
|
+
from lazyqml.Factories.Circuits.TreeTensor import *
|
|
7
|
+
from lazyqml.Factories.Circuits.HCzRx import *
|
|
8
8
|
# Importing Embeddings
|
|
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 *
|
|
9
|
+
from lazyqml.Factories.Circuits.RxEmbedding import *
|
|
10
|
+
from lazyqml.Factories.Circuits.RyEmbedding import *
|
|
11
|
+
from lazyqml.Factories.Circuits.RzEmbedding import *
|
|
12
|
+
from lazyqml.Factories.Circuits.ZzEmbedding import *
|
|
13
|
+
from lazyqml.Factories.Circuits.AmplitudeEmbedding import *
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class CircuitFactory:
|
|
@@ -3,12 +3,9 @@ import torch.nn as nn
|
|
|
3
3
|
import torch.optim as optim
|
|
4
4
|
import pennylane as qml
|
|
5
5
|
from time import time
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
from Global.globalEnums import *
|
|
10
|
-
from Factories.Circuits.fCircuits import CircuitFactory
|
|
11
|
-
from Utils.Utils import printer
|
|
6
|
+
from lazyqml.Global.globalEnums import *
|
|
7
|
+
from lazyqml.Factories.Circuits.fCircuits import CircuitFactory
|
|
8
|
+
from lazyqml.Utils.Utils import printer
|
|
12
9
|
|
|
13
10
|
|
|
14
11
|
# class HybridQuantumClassicalModel(nn.Module):
|
|
@@ -2,12 +2,12 @@ import torch
|
|
|
2
2
|
import pennylane as qml
|
|
3
3
|
from time import time
|
|
4
4
|
import numpy as np
|
|
5
|
-
from Interfaces.iModel import Model
|
|
6
|
-
from Interfaces.iAnsatz import Ansatz
|
|
7
|
-
from Interfaces.iCircuit import Circuit
|
|
8
|
-
from Factories.Circuits.fCircuits import *
|
|
9
|
-
from Global.globalEnums import Backend
|
|
10
|
-
from Utils.Utils import printer
|
|
5
|
+
from lazyqml.Interfaces.iModel import Model
|
|
6
|
+
from lazyqml.Interfaces.iAnsatz import Ansatz
|
|
7
|
+
from lazyqml.Interfaces.iCircuit import Circuit
|
|
8
|
+
from lazyqml.Factories.Circuits.fCircuits import *
|
|
9
|
+
from lazyqml.Global.globalEnums import Backend
|
|
10
|
+
from lazyqml.Utils.Utils import printer
|
|
11
11
|
import warnings
|
|
12
12
|
|
|
13
13
|
class QNNBag(Model):
|
|
@@ -2,12 +2,12 @@ import torch
|
|
|
2
2
|
import pennylane as qml
|
|
3
3
|
from time import time
|
|
4
4
|
import numpy as np
|
|
5
|
-
from Interfaces.iModel import Model
|
|
6
|
-
from Interfaces.iAnsatz import Ansatz
|
|
7
|
-
from Interfaces.iCircuit import Circuit
|
|
8
|
-
from Factories.Circuits.fCircuits import *
|
|
9
|
-
from Global.globalEnums import Backend
|
|
10
|
-
from Utils.Utils import printer
|
|
5
|
+
from lazyqml.Interfaces.iModel import Model
|
|
6
|
+
from lazyqml.Interfaces.iAnsatz import Ansatz
|
|
7
|
+
from lazyqml.Interfaces.iCircuit import Circuit
|
|
8
|
+
from lazyqml.Factories.Circuits.fCircuits import *
|
|
9
|
+
from lazyqml.Global.globalEnums import Backend
|
|
10
|
+
from lazyqml.Utils.Utils import printer
|
|
11
11
|
import warnings
|
|
12
12
|
|
|
13
13
|
class QNNTorch(Model):
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from Interfaces.iModel import Model
|
|
1
|
+
from lazyqml.Interfaces.iModel import Model
|
|
2
2
|
import numpy as np
|
|
3
3
|
from sklearn.svm import SVC
|
|
4
4
|
from sklearn.preprocessing import StandardScaler
|
|
@@ -6,8 +6,8 @@ from sklearn.model_selection import train_test_split
|
|
|
6
6
|
from sklearn.metrics import accuracy_score, balanced_accuracy_score
|
|
7
7
|
import pennylane as qml
|
|
8
8
|
from time import time
|
|
9
|
-
from Factories.Circuits.fCircuits import CircuitFactory
|
|
10
|
-
from Utils.Utils import printer
|
|
9
|
+
from lazyqml.Factories.Circuits.fCircuits import CircuitFactory
|
|
10
|
+
from lazyqml.Utils.Utils import printer
|
|
11
11
|
|
|
12
12
|
class QSVM(Model):
|
|
13
13
|
def __init__(self, nqubits, embedding, backend, shots, seed=1234):
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
from Factories.Models.QSVM import *
|
|
2
|
-
from Factories.Models.QNNBag import *
|
|
3
|
-
from Factories.Models.QNNTorch import *
|
|
4
|
-
from Global.globalEnums import *
|
|
1
|
+
from lazyqml.Factories.Models.QSVM import *
|
|
2
|
+
from lazyqml.Factories.Models.QNNBag import *
|
|
3
|
+
from lazyqml.Factories.Models.QNNTorch import *
|
|
4
|
+
from lazyqml.Global.globalEnums import *
|
|
5
5
|
|
|
6
6
|
class ModelFactory:
|
|
7
7
|
def __init__(self) -> None:
|