From e10c08b3f29efaee7c9f36409d427892e31ad8e3 Mon Sep 17 00:00:00 2001 From: ksk0629 Date: Fri, 18 Oct 2024 14:23:48 +0100 Subject: [PATCH] #6 Add the callback function --- scripts/run_example_estimator_qnn.py | 3 ++- scripts/run_example_exact_aer_estimator_qnn.py | 3 ++- scripts/run_example_noisy_aer_estimator_qnn.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/run_example_estimator_qnn.py b/scripts/run_example_estimator_qnn.py index e698297..767e4f5 100644 --- a/scripts/run_example_estimator_qnn.py +++ b/scripts/run_example_estimator_qnn.py @@ -4,7 +4,7 @@ from sklearn.model_selection import train_test_split from src.qnn_builder import QNNBuilder -from src.utils import fix_seed, generate_line_dataset +from src.utils import fix_seed, generate_line_dataset, callback_print if __name__ == "__main__": # Fix the random seed. @@ -26,6 +26,7 @@ classifier = NeuralNetworkClassifier( example_estimator_qnn, optimizer=qiskit_algorithms.optimizers.COBYLA(maxiter=200), + callback=callback_print, ) # Fit the model. x = np.asarray(train_images) diff --git a/scripts/run_example_exact_aer_estimator_qnn.py b/scripts/run_example_exact_aer_estimator_qnn.py index 875ea11..967f362 100644 --- a/scripts/run_example_exact_aer_estimator_qnn.py +++ b/scripts/run_example_exact_aer_estimator_qnn.py @@ -4,7 +4,7 @@ from sklearn.model_selection import train_test_split from src.qnn_builder import QNNBuilder -from src.utils import fix_seed, generate_line_dataset +from src.utils import fix_seed, generate_line_dataset, callback_print if __name__ == "__main__": # Fix the random seed. @@ -26,6 +26,7 @@ classifier = NeuralNetworkClassifier( example_estimator_qnn, optimizer=qiskit_algorithms.optimizers.COBYLA(maxiter=200), + callback=callback_print, ) # Fit the model. x = np.asarray(train_images) diff --git a/scripts/run_example_noisy_aer_estimator_qnn.py b/scripts/run_example_noisy_aer_estimator_qnn.py index 3dbc8f5..20fb587 100644 --- a/scripts/run_example_noisy_aer_estimator_qnn.py +++ b/scripts/run_example_noisy_aer_estimator_qnn.py @@ -4,7 +4,7 @@ from sklearn.model_selection import train_test_split from src.qnn_builder import QNNBuilder -from src.utils import fix_seed, generate_line_dataset +from src.utils import fix_seed, generate_line_dataset, callback_print if __name__ == "__main__": # Fix the random seed. @@ -26,6 +26,7 @@ classifier = NeuralNetworkClassifier( example_estimator_qnn, optimizer=qiskit_algorithms.optimizers.COBYLA(maxiter=200), + callback=callback_print, ) # Fit the model. x = np.asarray(train_images)