From 250c7e3807d2819ae75d8f5e0fd2b9cf61aa8b07 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 18:58:38 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks --- benchmarks/heavy_benchmark.py | 30 ++++++++++++++----- benchmarks/light_benchmark.py | 3 +- benchmarks/light_benchmark_nch_qaoacv.py | 3 +- doc/conf.py | 1 + .../ERP/noplot_classify_P300_bi_illiteracy.py | 7 +++-- .../noplot_classify_P300_bi_quantum_mdm.py | 7 +++-- examples/ERP/noplot_firebase_moabb.py | 13 ++++---- examples/ERP/plot_classify_EEG_quantum_svm.py | 7 +++-- examples/ERP/plot_classify_P300_bi.py | 3 +- ...t_classify_alexmi_with_quantum_pipeline.py | 1 + .../MI/noplot_multiclass_classification.py | 10 +++++-- examples/MI/plot_compare_dim_red.py | 3 +- .../plot_classifier_comparison.py | 11 ++++--- examples/toys_dataset/plot_qaoa_cv.py | 7 +++-- pyriemann_qiskit/classification.py | 24 +++++++++------ pyriemann_qiskit/datasets/__init__.py | 10 +++++-- pyriemann_qiskit/utils/__init__.py | 25 +++++++++++----- pyriemann_qiskit/utils/distance.py | 7 +++-- pyriemann_qiskit/utils/docplex.py | 6 ++-- .../utils/hyper_params_factory.py | 3 +- pyriemann_qiskit/utils/quantum_provider.py | 6 ++-- tests/test_classification.py | 8 +++-- tests/test_docplex.py | 14 +++++---- tests/test_pipelines.py | 3 +- tests/test_utils_distance.py | 12 +++++--- tests/test_utils_hyper_params_factory.py | 15 ++++++---- tests/test_utils_mean.py | 8 +++-- 27 files changed, 160 insertions(+), 87 deletions(-) diff --git a/benchmarks/heavy_benchmark.py b/benchmarks/heavy_benchmark.py index f1d94f6f..d46bb476 100644 --- a/benchmarks/heavy_benchmark.py +++ b/benchmarks/heavy_benchmark.py @@ -23,17 +23,33 @@ import seaborn as sns from matplotlib import pyplot as plt from moabb import set_log_level -from moabb.analysis.meta_analysis import (compute_dataset_statistics, - find_significant_differences) +from moabb.analysis.meta_analysis import ( + compute_dataset_statistics, + find_significant_differences, +) + # Motor imagery databases # P300 databases from moabb.datasets import Lee2019_MI # new from moabb.datasets import Schirrmeister2017 # new -from moabb.datasets import (BNCI2014_001, BNCI2014_004, BNCI2014_008, - BNCI2014_009, BNCI2015_003, BI2013a, BI2014a, - BI2014b, BI2015a, BI2015b, Cho2017, - GrosseWentrup2009, PhysionetMI, Shin2017A, - Weibo2014, Zhou2016) +from moabb.datasets import ( + BNCI2014_001, + BNCI2014_004, + BNCI2014_008, + BNCI2014_009, + BNCI2015_003, + BI2013a, + BI2014a, + BI2014b, + BI2015a, + BI2015b, + Cho2017, + GrosseWentrup2009, + PhysionetMI, + Shin2017A, + Weibo2014, + Zhou2016, +) from moabb.evaluations import CrossSubjectEvaluation, WithinSessionEvaluation from moabb.paradigms import P300, LeftRightImagery, MotorImagery from pyriemann.estimation import Covariances diff --git a/benchmarks/light_benchmark.py b/benchmarks/light_benchmark.py index 1dbd5f1d..2c4bc907 100644 --- a/benchmarks/light_benchmark.py +++ b/benchmarks/light_benchmark.py @@ -23,7 +23,8 @@ from pyriemann_qiskit.pipelines import ( QuantumClassifierWithDefaultRiemannianPipeline, - QuantumMDMWithRiemannianPipeline) + QuantumMDMWithRiemannianPipeline, +) from pyriemann_qiskit.utils import distance, mean # noqa print(__doc__) diff --git a/benchmarks/light_benchmark_nch_qaoacv.py b/benchmarks/light_benchmark_nch_qaoacv.py index daab7b1a..f7c7ae45 100644 --- a/benchmarks/light_benchmark_nch_qaoacv.py +++ b/benchmarks/light_benchmark_nch_qaoacv.py @@ -21,8 +21,7 @@ from pyriemann_qiskit.classification import QuanticNCH from pyriemann_qiskit.utils import distance, mean # noqa -from pyriemann_qiskit.utils.hyper_params_factory import \ - create_mixer_rotational_X_gates +from pyriemann_qiskit.utils.hyper_params_factory import create_mixer_rotational_X_gates print(__doc__) diff --git a/doc/conf.py b/doc/conf.py index 90c4bee9..da50a856 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -16,6 +16,7 @@ import sys import matplotlib + # mne update path import mne diff --git a/examples/ERP/noplot_classify_P300_bi_illiteracy.py b/examples/ERP/noplot_classify_P300_bi_illiteracy.py index c4d479a7..1c9d5570 100644 --- a/examples/ERP/noplot_classify_P300_bi_illiteracy.py +++ b/examples/ERP/noplot_classify_P300_bi_illiteracy.py @@ -33,8 +33,11 @@ from pyriemann_qiskit.ensemble import JudgeClassifier from pyriemann_qiskit.pipelines import ( - QuantumClassifierWithDefaultRiemannianPipeline, QuantumMDMVotingClassifier, - QuantumMDMWithRiemannianPipeline) + QuantumClassifierWithDefaultRiemannianPipeline, + QuantumMDMVotingClassifier, + QuantumMDMWithRiemannianPipeline, +) + # inject convex distance and mean to pyriemann (if not done already) from pyriemann_qiskit.utils import distance, mean # noqa diff --git a/examples/ERP/noplot_classify_P300_bi_quantum_mdm.py b/examples/ERP/noplot_classify_P300_bi_quantum_mdm.py index 7c4188d3..02d0f221 100644 --- a/examples/ERP/noplot_classify_P300_bi_quantum_mdm.py +++ b/examples/ERP/noplot_classify_P300_bi_quantum_mdm.py @@ -32,8 +32,11 @@ from moabb.evaluations import WithinSessionEvaluation from moabb.paradigms import P300 -from pyriemann_qiskit.pipelines import (QuantumMDMVotingClassifier, - QuantumMDMWithRiemannianPipeline) +from pyriemann_qiskit.pipelines import ( + QuantumMDMVotingClassifier, + QuantumMDMWithRiemannianPipeline, +) + # inject cpm distance and mean to pyriemann (if not done already) from pyriemann_qiskit.utils import distance, mean # noqa diff --git a/examples/ERP/noplot_firebase_moabb.py b/examples/ERP/noplot_firebase_moabb.py index 715e4f9b..930a3420 100644 --- a/examples/ERP/noplot_firebase_moabb.py +++ b/examples/ERP/noplot_firebase_moabb.py @@ -37,12 +37,13 @@ from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA from sklearn.pipeline import make_pipeline -from pyriemann_qiskit.pipelines import \ - QuantumClassifierWithDefaultRiemannianPipeline -from pyriemann_qiskit.utils import (add_moabb_dataframe_results_to_caches, - convert_caches_to_dataframes, - filter_subjects_by_incomplete_results, - generate_caches) +from pyriemann_qiskit.pipelines import QuantumClassifierWithDefaultRiemannianPipeline +from pyriemann_qiskit.utils import ( + add_moabb_dataframe_results_to_caches, + convert_caches_to_dataframes, + filter_subjects_by_incomplete_results, + generate_caches, +) print(__doc__) diff --git a/examples/ERP/plot_classify_EEG_quantum_svm.py b/examples/ERP/plot_classify_EEG_quantum_svm.py index 4400bdae..276ebf3a 100644 --- a/examples/ERP/plot_classify_EEG_quantum_svm.py +++ b/examples/ERP/plot_classify_EEG_quantum_svm.py @@ -16,8 +16,11 @@ from matplotlib import pyplot as plt from pyriemann.estimation import XdawnCovariances from pyriemann.tangentspace import TangentSpace -from sklearn.metrics import (ConfusionMatrixDisplay, balanced_accuracy_score, - confusion_matrix) +from sklearn.metrics import ( + ConfusionMatrixDisplay, + balanced_accuracy_score, + confusion_matrix, +) from sklearn.model_selection import train_test_split from sklearn.pipeline import make_pipeline diff --git a/examples/ERP/plot_classify_P300_bi.py b/examples/ERP/plot_classify_P300_bi.py index 4c081c3b..24eac79e 100644 --- a/examples/ERP/plot_classify_P300_bi.py +++ b/examples/ERP/plot_classify_P300_bi.py @@ -36,8 +36,7 @@ from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA from sklearn.pipeline import make_pipeline -from pyriemann_qiskit.pipelines import \ - QuantumClassifierWithDefaultRiemannianPipeline +from pyriemann_qiskit.pipelines import QuantumClassifierWithDefaultRiemannianPipeline print(__doc__) diff --git a/examples/MI/noplot_classify_alexmi_with_quantum_pipeline.py b/examples/MI/noplot_classify_alexmi_with_quantum_pipeline.py index 1549d8e2..423e2c0f 100644 --- a/examples/MI/noplot_classify_alexmi_with_quantum_pipeline.py +++ b/examples/MI/noplot_classify_alexmi_with_quantum_pipeline.py @@ -15,6 +15,7 @@ import warnings import seaborn as sns + # inject cpm distance and mean to pyriemann (if not done already) from helpers.alias import ERPCov_MDM from matplotlib import pyplot as plt diff --git a/examples/MI/noplot_multiclass_classification.py b/examples/MI/noplot_multiclass_classification.py index efc459fb..50e3d309 100644 --- a/examples/MI/noplot_multiclass_classification.py +++ b/examples/MI/noplot_multiclass_classification.py @@ -16,14 +16,18 @@ from helpers.alias import ERPCov_MDM from matplotlib import pyplot as plt from sklearn.decomposition import PCA -from sklearn.metrics import (ConfusionMatrixDisplay, balanced_accuracy_score, - confusion_matrix) +from sklearn.metrics import ( + ConfusionMatrixDisplay, + balanced_accuracy_score, + confusion_matrix, +) from sklearn.model_selection import train_test_split from pyriemann_qiskit.datasets import get_mne_sample from pyriemann_qiskit.pipelines import ( QuantumClassifierWithDefaultRiemannianPipeline, - QuantumMDMWithRiemannianPipeline) + QuantumMDMWithRiemannianPipeline, +) print(__doc__) diff --git a/examples/MI/plot_compare_dim_red.py b/examples/MI/plot_compare_dim_red.py index 87e374ec..317a8eab 100644 --- a/examples/MI/plot_compare_dim_red.py +++ b/examples/MI/plot_compare_dim_red.py @@ -23,8 +23,7 @@ from sklearn.model_selection import GridSearchCV, StratifiedKFold from pyriemann_qiskit.datasets import get_mne_sample -from pyriemann_qiskit.pipelines import \ - QuantumClassifierWithDefaultRiemannianPipeline +from pyriemann_qiskit.pipelines import QuantumClassifierWithDefaultRiemannianPipeline from pyriemann_qiskit.utils.filtering import NaiveDimRed print(__doc__) diff --git a/examples/toys_dataset/plot_classifier_comparison.py b/examples/toys_dataset/plot_classifier_comparison.py index 743e83a7..5b607051 100644 --- a/examples/toys_dataset/plot_classifier_comparison.py +++ b/examples/toys_dataset/plot_classifier_comparison.py @@ -20,10 +20,13 @@ from sklearn.preprocessing import StandardScaler from sklearn.svm import SVC -from pyriemann_qiskit.classification import \ - QuanticSVM # uncomment to run comparison with QuanticVQC (disabled for CI/CD); QuanticVQC -from pyriemann_qiskit.datasets import (generate_linearly_separable_dataset, - generate_qiskit_dataset) +from pyriemann_qiskit.classification import ( # uncomment to run comparison with QuanticVQC (disabled for CI/CD); QuanticVQC + QuanticSVM, +) +from pyriemann_qiskit.datasets import ( + generate_linearly_separable_dataset, + generate_qiskit_dataset, +) # uncomment to run comparison with QuanticVQC (disabled for CI/CD) # from pyriemann_qiskit.classification import QuanticVQC diff --git a/examples/toys_dataset/plot_qaoa_cv.py b/examples/toys_dataset/plot_qaoa_cv.py index 36394a03..4de7be58 100644 --- a/examples/toys_dataset/plot_qaoa_cv.py +++ b/examples/toys_dataset/plot_qaoa_cv.py @@ -22,8 +22,11 @@ from pyriemann_qiskit.utils.docplex import QAOACVOptimizer from pyriemann_qiskit.utils.hyper_params_factory import ( - create_mixer_qiskit_default, create_mixer_rotational_X_gates, - create_mixer_rotational_XY_gates, create_mixer_rotational_XZ_gates) + create_mixer_qiskit_default, + create_mixer_rotational_X_gates, + create_mixer_rotational_XY_gates, + create_mixer_rotational_XZ_gates, +) ############################################################################### # Run QAOA-CV diff --git a/pyriemann_qiskit/classification.py b/pyriemann_qiskit/classification.py index 7c75d1bb..301c8068 100644 --- a/pyriemann_qiskit/classification.py +++ b/pyriemann_qiskit/classification.py @@ -23,15 +23,21 @@ from sklearn.svm import SVC from .datasets import get_feature_dimension -from .utils.distance import (distance_functions, - qdistance_logeuclid_to_convex_hull) -from .utils.docplex import (ClassicalOptimizer, NaiveQAOAOptimizer, - QAOACVOptimizer, get_global_optimizer, - set_global_optimizer) -from .utils.hyper_params_factory import (gen_two_local, gen_zz_feature_map, - get_spsa) -from .utils.quantum_provider import (get_device, get_provider, - get_quantum_kernel, get_simulator) +from .utils.distance import distance_functions, qdistance_logeuclid_to_convex_hull +from .utils.docplex import ( + ClassicalOptimizer, + NaiveQAOAOptimizer, + QAOACVOptimizer, + get_global_optimizer, + set_global_optimizer, +) +from .utils.hyper_params_factory import gen_two_local, gen_zz_feature_map, get_spsa +from .utils.quantum_provider import ( + get_device, + get_provider, + get_quantum_kernel, + get_simulator, +) from .utils.utils import is_qfunction logging.basicConfig(level=logging.WARNING) diff --git a/pyriemann_qiskit/datasets/__init__.py b/pyriemann_qiskit/datasets/__init__.py index a931a386..6255e064 100644 --- a/pyriemann_qiskit/datasets/__init__.py +++ b/pyriemann_qiskit/datasets/__init__.py @@ -1,6 +1,10 @@ -from .utils import (MockDataset, generate_linearly_separable_dataset, - generate_qiskit_dataset, get_feature_dimension, - get_mne_sample) +from .utils import ( + MockDataset, + generate_linearly_separable_dataset, + generate_qiskit_dataset, + get_feature_dimension, + get_mne_sample, +) __all__ = [ "get_mne_sample", diff --git a/pyriemann_qiskit/utils/__init__.py b/pyriemann_qiskit/utils/__init__.py index 2263801b..5e6b146a 100644 --- a/pyriemann_qiskit/utils/__init__.py +++ b/pyriemann_qiskit/utils/__init__.py @@ -1,10 +1,21 @@ -from . import (distance, docplex, filtering, hyper_params_factory, mean, - preprocessing, quantum_provider, utils) -from .firebase_connector import (Cache, FirebaseConnector, - add_moabb_dataframe_results_to_caches, - convert_caches_to_dataframes, - filter_subjects_by_incomplete_results, - generate_caches) +from . import ( + distance, + docplex, + filtering, + hyper_params_factory, + mean, + preprocessing, + quantum_provider, + utils, +) +from .firebase_connector import ( + Cache, + FirebaseConnector, + add_moabb_dataframe_results_to_caches, + convert_caches_to_dataframes, + filter_subjects_by_incomplete_results, + generate_caches, +) from .math import cov_to_corr_matrix, union_of_diff __all__ = [ diff --git a/pyriemann_qiskit/utils/distance.py b/pyriemann_qiskit/utils/distance.py index 69e80417..60910207 100644 --- a/pyriemann_qiskit/utils/distance.py +++ b/pyriemann_qiskit/utils/distance.py @@ -1,8 +1,11 @@ import numpy as np from docplex.mp.model import Model from pyriemann.utils.base import logm -from pyriemann.utils.distance import (distance_euclid, distance_functions, - distance_logeuclid) +from pyriemann.utils.distance import ( + distance_euclid, + distance_functions, + distance_logeuclid, +) from pyriemann.utils.mean import mean_logeuclid from typing_extensions import deprecated diff --git a/pyriemann_qiskit/utils/docplex.py b/pyriemann_qiskit/utils/docplex.py index b92c3cd9..6555cdf9 100644 --- a/pyriemann_qiskit/utils/docplex.py +++ b/pyriemann_qiskit/utils/docplex.py @@ -16,10 +16,8 @@ from qiskit.quantum_info import Statevector from qiskit_algorithms import QAOA from qiskit_algorithms.optimizers import SLSQP, SPSA -from qiskit_optimization.algorithms import (CobylaOptimizer, - MinimumEigenOptimizer) -from qiskit_optimization.converters import (IntegerToBinary, - LinearEqualityToPenalty) +from qiskit_optimization.algorithms import CobylaOptimizer, MinimumEigenOptimizer +from qiskit_optimization.converters import IntegerToBinary, LinearEqualityToPenalty from qiskit_optimization.problems import VarType from qiskit_optimization.translators import from_docplex_mp from sklearn.preprocessing import MinMaxScaler diff --git a/pyriemann_qiskit/utils/hyper_params_factory.py b/pyriemann_qiskit/utils/hyper_params_factory.py index fb812161..e528b4d0 100644 --- a/pyriemann_qiskit/utils/hyper_params_factory.py +++ b/pyriemann_qiskit/utils/hyper_params_factory.py @@ -1,8 +1,7 @@ import inspect from qiskit.circuit import Parameter, QuantumCircuit, QuantumRegister -from qiskit.circuit.library import (PauliFeatureMap, TwoLocal, ZFeatureMap, - ZZFeatureMap) +from qiskit.circuit.library import PauliFeatureMap, TwoLocal, ZFeatureMap, ZZFeatureMap from qiskit_algorithms.optimizers import SPSA diff --git a/pyriemann_qiskit/utils/quantum_provider.py b/pyriemann_qiskit/utils/quantum_provider.py index be2a732f..691e3f61 100644 --- a/pyriemann_qiskit/utils/quantum_provider.py +++ b/pyriemann_qiskit/utils/quantum_provider.py @@ -11,8 +11,10 @@ from qiskit_aer.quantum_info import AerStatevector from qiskit_algorithms.state_fidelities import ComputeUncompute from qiskit_ibm_runtime import QiskitRuntimeService -from qiskit_machine_learning.kernels import (FidelityQuantumKernel, - FidelityStatevectorKernel) +from qiskit_machine_learning.kernels import ( + FidelityQuantumKernel, + FidelityStatevectorKernel, +) try: from qiskit_symb.quantum_info import Statevector diff --git a/tests/test_classification.py b/tests/test_classification.py index 09343756..4c00d74d 100644 --- a/tests/test_classification.py +++ b/tests/test_classification.py @@ -6,8 +6,12 @@ from sklearn.model_selection import StratifiedKFold, cross_val_score from sklearn.pipeline import make_pipeline -from pyriemann_qiskit.classification import (QuanticMDM, QuanticNCH, - QuanticSVM, QuanticVQC) +from pyriemann_qiskit.classification import ( + QuanticMDM, + QuanticNCH, + QuanticSVM, + QuanticVQC, +) from pyriemann_qiskit.datasets import get_mne_sample from pyriemann_qiskit.utils.filtering import NaiveDimRed diff --git a/tests/test_docplex.py b/tests/test_docplex.py index 8e6556a9..47231097 100644 --- a/tests/test_docplex.py +++ b/tests/test_docplex.py @@ -2,12 +2,14 @@ from docplex.mp.model import Model from docplex.mp.vartype import BinaryVarType, ContinuousVarType, IntegerVarType -from pyriemann_qiskit.utils.docplex import (ClassicalOptimizer, - NaiveQAOAOptimizer, - QAOACVOptimizer, - square_bin_mat_var, - square_cont_mat_var, - square_int_mat_var) +from pyriemann_qiskit.utils.docplex import ( + ClassicalOptimizer, + NaiveQAOAOptimizer, + QAOACVOptimizer, + square_bin_mat_var, + square_cont_mat_var, + square_int_mat_var, +) @pytest.mark.parametrize( diff --git a/tests/test_pipelines.py b/tests/test_pipelines.py index 85dc7314..d7da775c 100644 --- a/tests/test_pipelines.py +++ b/tests/test_pipelines.py @@ -3,8 +3,7 @@ from sklearn.model_selection import StratifiedKFold, cross_val_score from pyriemann_qiskit.datasets import get_mne_sample -from pyriemann_qiskit.pipelines import \ - QuantumClassifierWithDefaultRiemannianPipeline +from pyriemann_qiskit.pipelines import QuantumClassifierWithDefaultRiemannianPipeline @pytest.mark.parametrize( diff --git a/tests/test_utils_distance.py b/tests/test_utils_distance.py index 8fe236cd..81fead44 100644 --- a/tests/test_utils_distance.py +++ b/tests/test_utils_distance.py @@ -8,10 +8,14 @@ from pyriemann_qiskit.classification import QuanticMDM from pyriemann_qiskit.datasets import get_mne_sample from pyriemann_qiskit.utils.distance import ( - qdistance_logeuclid_to_convex_hull, weights_logeuclid_to_convex_hull) -from pyriemann_qiskit.utils.docplex import (ClassicalOptimizer, - NaiveQAOAOptimizer, - QAOACVOptimizer) + qdistance_logeuclid_to_convex_hull, + weights_logeuclid_to_convex_hull, +) +from pyriemann_qiskit.utils.docplex import ( + ClassicalOptimizer, + NaiveQAOAOptimizer, + QAOACVOptimizer, +) @pytest.mark.parametrize( diff --git a/tests/test_utils_hyper_params_factory.py b/tests/test_utils_hyper_params_factory.py index 8605ef3d..5c665320 100644 --- a/tests/test_utils_hyper_params_factory.py +++ b/tests/test_utils_hyper_params_factory.py @@ -1,12 +1,15 @@ import pytest from qiskit.circuit.parametertable import ParameterView -from pyriemann_qiskit.utils.hyper_params_factory import (gates, gen_two_local, - gen_x_feature_map, - gen_z_feature_map, - gen_zz_feature_map, - get_spsa, - get_spsa_parameters) +from pyriemann_qiskit.utils.hyper_params_factory import ( + gates, + gen_two_local, + gen_x_feature_map, + gen_z_feature_map, + gen_zz_feature_map, + get_spsa, + get_spsa_parameters, +) class TestGenXFeatureMapParams: diff --git a/tests/test_utils_mean.py b/tests/test_utils_mean.py index 4c21ab9c..c00f9393 100644 --- a/tests/test_utils_mean.py +++ b/tests/test_utils_mean.py @@ -8,9 +8,11 @@ from pyriemann_qiskit.classification import QuanticMDM from pyriemann_qiskit.datasets import get_mne_sample -from pyriemann_qiskit.utils.docplex import (ClassicalOptimizer, - NaiveQAOAOptimizer, - QAOACVOptimizer) +from pyriemann_qiskit.utils.docplex import ( + ClassicalOptimizer, + NaiveQAOAOptimizer, + QAOACVOptimizer, +) from pyriemann_qiskit.utils.mean import qmean_euclid, qmean_logeuclid