Skip to content

Commit 6df1d16

Browse files
High-level Quantum Reservoir Computing Implementation (#290)
1 parent 4fa8c32 commit 6df1d16

17 files changed

Lines changed: 1215 additions & 43 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ examples/qnn/*_log.csv
169169
examples/**/*.log
170170

171171
#Example caches
172-
examples/**/_cache
172+
**/_cache
173173
examples/integration/mlruns
174174

175175
# Genereated doc images

docs/modules/classes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ QML Regressors
2020
kernel.ml.QKRR
2121
kernel.ml.QGPR
2222
qnn.QNNRegressor
23+
qrc.QRCRegressor
2324

2425

2526
QML Classifiers
@@ -35,7 +36,7 @@ QML Classifiers
3536
kernel.ml.QSVC
3637
kernel.ml.QGPC
3738
qnn.QNNClassifier
38-
39+
qrc.QRCClassifier
3940

4041
Circuit Design
4142
====================================
@@ -283,6 +284,7 @@ Base Classes
283284
optimizers.optimizer_base.OptimizerBase
284285
qnn.base_qnn.BaseQNN
285286
qnn.loss.LossBase
287+
qrc.base_qrc.BaseQRC
286288

287289

288290

examples/qnn/example_minibatch.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
"name": "python",
296296
"nbconvert_exporter": "python",
297297
"pygments_lexer": "ipython3",
298-
"version": "3.10.10"
298+
"version": "3.9.13"
299299
},
300300
"orig_nbformat": 4
301301
},

examples/qrc/qrc_classification.ipynb

Lines changed: 205 additions & 0 deletions
Large diffs are not rendered by default.

examples/qrc/qrc_regression.ipynb

Lines changed: 207 additions & 0 deletions
Large diffs are not rendered by default.

examples/tutorials/quantum_bayesian_optimization.ipynb

Lines changed: 23 additions & 23 deletions
Large diffs are not rendered by default.

src/squlearn/kernel/matrix/projected_quantum_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def __init__(
439439

440440
# Set-up of the QNN
441441
self._qnn = LowLevelQNN(
442-
self._encoding_circuit, self._measurement, executor, result_caching=self._caching
442+
self._encoding_circuit, self._measurement, executor, caching=self._caching
443443
)
444444

445445
# Set-up of the outer kernel

src/squlearn/qnn/base_qnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def _fit(self, X, y, weights: np.ndarray = None) -> None:
324324

325325
def _initialize_lowlevel_qnn(self):
326326
self._qnn = LowLevelQNN(
327-
self.encoding_circuit, self.operator, self.executor, result_caching=self.caching
327+
self.encoding_circuit, self.operator, self.executor, caching=self.caching
328328
)
329329

330330
def _validate_input(self, X, y, incremental, reset):

src/squlearn/qnn/lowlevel_qnn_pennylane.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class LowLevelQNNPennyLane(LowLevelQNNBase):
8484
operator (Union[ObservableBase,list]): Operator that is used in the expectation
8585
value of the QNN. Can be a list for multiple outputs.
8686
executor (Executor) : Executor that is used for the evaluation of the QNN
87-
result_caching : Caching of the result for each `x`, `param`, `param_op` combination
87+
caching : Caching of the result for each `x`, `param`, `param_op` combination
8888
(default = True)
8989
9090
Attributes:
@@ -110,13 +110,13 @@ def __init__(
110110
parameterized_quantum_circuit: EncodingCircuitBase,
111111
observable: Union[ObservableBase, list],
112112
executor: Executor,
113-
result_caching: bool = True,
113+
caching: bool = True,
114114
) -> None:
115115

116116
super().__init__(parameterized_quantum_circuit, observable, executor)
117117

118118
# Initialize result cache
119-
self._result_caching = result_caching
119+
self.caching = caching
120120
self.result_container = {}
121121

122122
self._initialize_pennylane_circuit()
@@ -341,7 +341,7 @@ def evaluate(
341341

342342
# return dictionary for input data, it will be empty
343343
# if the combination of x,param,param_op is touched the first time
344-
if self._result_caching == True:
344+
if self.caching == True:
345345
caching_tuple = (
346346
to_tuple(x),
347347
to_tuple(param),
@@ -460,7 +460,7 @@ def evaluate(
460460
value_dict[post.key] = post.evaluation_function(value_dict)
461461

462462
# Store the updated dictionary for the theta value
463-
if self._result_caching:
463+
if self.caching:
464464
self.result_container[caching_tuple] = value_dict
465465

466466
return value_dict

src/squlearn/qnn/lowlevel_qnn_qiskit.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,7 @@ class LowLevelQNNQiskit(LowLevelQNNBase):
273273
operator (Union[ObservableBase,list]): Operator that is used in the expectation
274274
value of the QNN. Can be a list for multiple outputs.
275275
executor (Executor) : Executor that is used for the evaluation of the QNN
276-
optree_caching : Caching of the optree expressions (default = True recommended)
277-
result_caching : Caching of the result for each `x`, `param`, `param_op` combination
276+
caching : Caching of the result for each `x`, `param`, `param_op` combination
278277
(default = True)
279278
280279
Attributes:
@@ -300,17 +299,15 @@ def __init__(
300299
parameterized_quantum_circuit: EncodingCircuitBase,
301300
operator: Union[ObservableBase, list],
302301
executor: Executor,
303-
optree_caching=True,
304-
result_caching=True,
302+
caching=True,
305303
) -> None:
306304

307305
parameterized_quantum_circuit = TranspiledEncodingCircuit(
308306
parameterized_quantum_circuit, executor.backend
309307
)
310308
super().__init__(parameterized_quantum_circuit, operator, executor)
311309

312-
self._optree_caching = optree_caching
313-
self._result_caching = result_caching
310+
self.caching = caching
314311

315312
# Set-Up Executor
316313
if self._executor.optree_executor == "estimator":
@@ -405,8 +402,8 @@ def _initilize_derivative(self):
405402
self._observable.set_map(self._pqc.qubit_map, self._pqc.num_physical_qubits)
406403
num_qubits_operator = self._observable.num_qubits
407404

408-
self.operator_derivatives = ObservableDerivatives(self._observable, self._optree_caching)
409-
self.pqc_derivatives = EncodingCircuitDerivatives(self._pqc, self._optree_caching)
405+
self.operator_derivatives = ObservableDerivatives(self._observable)
406+
self.pqc_derivatives = EncodingCircuitDerivatives(self._pqc)
410407

411408
if self._pqc.num_virtual_qubits != num_qubits_operator:
412409
raise ValueError("Number of Qubits are not the same!")
@@ -937,7 +934,7 @@ def add_to_real_todo_dic(item: Expec, real_todo_dic, value_dict):
937934

938935
# return dictionary for input data, it will be empty
939936
# if the combination of x,param,param_op is touched the first time
940-
if self._result_caching == True:
937+
if self.caching == True:
941938
caching_tuple = (
942939
to_tuple(x),
943940
to_tuple(param),
@@ -1120,7 +1117,7 @@ def add_to_real_todo_dic(item: Expec, real_todo_dic, value_dict):
11201117
value_dict["param_op"] = param_op
11211118

11221119
# Store the updated dictionary for the theta value
1123-
if self._result_caching:
1120+
if self.caching:
11241121
self.result_container[caching_tuple] = value_dict
11251122

11261123
return value_dict

0 commit comments

Comments
 (0)