diff --git a/doc/_templates/class.rst b/doc/_templates/class.rst index f71c4d49..97a8a622 100644 --- a/doc/_templates/class.rst +++ b/doc/_templates/class.rst @@ -8,3 +8,8 @@ {% block methods %} .. automethod:: __init__ {% endblock %} + +.. _sphx_glr_backreferences_{{ fullname }}: + +.. minigallery:: {{ fullname }} + :add-heading: diff --git a/doc/conf.py b/doc/conf.py index be7d8fee..76c1cc67 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -18,8 +18,7 @@ # mne update path import mne -print(mne.datasets.sample.data_path(update_path=True)) -print(mne.datasets.eegbci.load_data(1, [6, 10, 14], update_path=True)) +print(mne.datasets.sample.data_path(update_path=True, download=False)) matplotlib.use('Agg') import shlex @@ -61,8 +60,11 @@ plot_html_show_source_link = False sphinx_gallery_conf = { - 'examples_dirs': ['../examples', '../tutorials'], - 'gallery_dirs': ['auto_examples'] + 'examples_dirs': ['../examples'], + 'gallery_dirs': ['auto_examples'], + 'doc_module': 'pyriemann_qiskit', + 'backreferences_dir': 'generated', + 'plot_gallery': 'True', } # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/doc/introduction.rst b/doc/introduction.rst index 3a35805d..ae2b10bf 100644 --- a/doc/introduction.rst +++ b/doc/introduction.rst @@ -80,4 +80,4 @@ References How to cite? ================================ -Anton Andreev, Grégoire Cattan, Sylvain Chevallier, and Quentin Barthélemy. ‘PyRiemann-Qiskit: A Sandbox for Quantum Classification Experiments with Riemannian Geometry’. Research Ideas and Outcomes 9 (20 March 2023). https://doi.org/10.3897/rio.9.e101006. +Anton Andreev, Grégoire Cattan, Sylvain Chevallier, and Quentin Barthélemy. ‘pyRiemann-qiskit: A Sandbox for Quantum Classification Experiments with Riemannian Geometry’. Research Ideas and Outcomes 9 (20 March 2023). https://doi.org/10.3897/rio.9.e101006. diff --git a/examples/ERP/noplot_classify_P300_bi_illiteracy.py b/examples/ERP/noplot_classify_P300_bi_illiteracy.py index 5bde4378..6451dd89 100644 --- a/examples/ERP/noplot_classify_P300_bi_illiteracy.py +++ b/examples/ERP/noplot_classify_P300_bi_illiteracy.py @@ -12,24 +12,25 @@ # License: BSD (3-clause) from enum import Enum -from matplotlib import pyplot as plt -import numpy as np -import seaborn as sns import warnings +from matplotlib import pyplot as plt from mne.decoding import Vectorizer from moabb import set_log_level from moabb.datasets.compound_dataset import BI_Il from moabb.evaluations import WithinSessionEvaluation from moabb.paradigms import P300 +import numpy as np from pyriemann.estimation import XdawnCovariances from pyriemann.tangentspace import TangentSpace from pyriemann.classification import MDM from pyriemann.spatialfilters import Xdawn +import seaborn as sns from sklearn.ensemble import VotingClassifier from sklearn.pipeline import make_pipeline, Pipeline from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA from sklearn.svm import SVC + from pyriemann_qiskit.ensemble import JudgeClassifier # inject convex distance and mean to pyriemann (if not done already) @@ -40,7 +41,6 @@ QuantumClassifierWithDefaultRiemannianPipeline, ) - print(__doc__) diff --git a/examples/ERP/noplot_classify_P300_bi_quantum_mdm.py b/examples/ERP/noplot_classify_P300_bi_quantum_mdm.py index a9209853..5a6e9618 100644 --- a/examples/ERP/noplot_classify_P300_bi_quantum_mdm.py +++ b/examples/ERP/noplot_classify_P300_bi_quantum_mdm.py @@ -23,9 +23,9 @@ # Modified from plot_classify_EEG_tangentspace.py of pyRiemann # License: BSD (3-clause) -from matplotlib import pyplot as plt import warnings -import seaborn as sns + +from matplotlib import pyplot as plt from moabb import set_log_level from moabb.datasets import ( # bi2012, @@ -42,6 +42,7 @@ ) from moabb.evaluations import WithinSessionEvaluation from moabb.paradigms import P300 +import seaborn as sns # 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 5dca7bac..6b85bb32 100644 --- a/examples/ERP/noplot_firebase_moabb.py +++ b/examples/ERP/noplot_firebase_moabb.py @@ -23,27 +23,29 @@ # Modified from plot_classify_P300_bi.py # License: BSD (3-clause) +import warnings + +from matplotlib import pyplot as plt +from moabb import set_log_level +from moabb.datasets import bi2012 +from moabb.evaluations import WithinSessionEvaluation +from moabb.paradigms import P300 from pyriemann.estimation import XdawnCovariances from pyriemann.tangentspace import TangentSpace +import seaborn as sns +from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA +from sklearn.pipeline import make_pipeline +from sklearn.decomposition import PCA + from pyriemann_qiskit.utils import ( generate_caches, filter_subjects_by_incomplete_results, add_moabb_dataframe_results_to_caches, convert_caches_to_dataframes, ) -from sklearn.pipeline import make_pipeline -from matplotlib import pyplot as plt -import warnings -import seaborn as sns -from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA -from moabb import set_log_level -from moabb.datasets import bi2012 -from moabb.evaluations import WithinSessionEvaluation -from moabb.paradigms import P300 from pyriemann_qiskit.pipelines import ( QuantumClassifierWithDefaultRiemannianPipeline, ) -from sklearn.decomposition import PCA print(__doc__) diff --git a/examples/ERP/plot_classify_EEG_quantum_svm.py b/examples/ERP/plot_classify_EEG_quantum_svm.py index 1b0cc25b..eb6babfc 100644 --- a/examples/ERP/plot_classify_EEG_quantum_svm.py +++ b/examples/ERP/plot_classify_EEG_quantum_svm.py @@ -13,11 +13,9 @@ # Modified from plot_classify_EEG_tangentspace.py of pyRiemann # License: BSD (3-clause) +from matplotlib import pyplot as plt from pyriemann.estimation import XdawnCovariances from pyriemann.tangentspace import TangentSpace -from pyriemann_qiskit.classification import QuanticSVM -from pyriemann_qiskit.utils.filtering import NaiveDimRed -from pyriemann_qiskit.datasets import get_mne_sample from sklearn.pipeline import make_pipeline from sklearn.model_selection import train_test_split from sklearn.metrics import ( @@ -25,11 +23,14 @@ ConfusionMatrixDisplay, balanced_accuracy_score, ) -from matplotlib import pyplot as plt +from pyriemann_qiskit.classification import QuanticSVM +from pyriemann_qiskit.utils.filtering import NaiveDimRed +from pyriemann_qiskit.datasets import get_mne_sample print(__doc__) +############################################################################## X, y = get_mne_sample(n_trials=-1) diff --git a/examples/ERP/plot_classify_P300_bi.py b/examples/ERP/plot_classify_P300_bi.py index a5ea971d..a8c70930 100644 --- a/examples/ERP/plot_classify_P300_bi.py +++ b/examples/ERP/plot_classify_P300_bi.py @@ -22,21 +22,23 @@ # Modified from plot_classify_EEG_tangentspace.py of pyRiemann # License: BSD (3-clause) -from pyriemann.estimation import XdawnCovariances -from pyriemann.tangentspace import TangentSpace -from sklearn.pipeline import make_pipeline -from matplotlib import pyplot as plt import warnings -import seaborn as sns -from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA + +from matplotlib import pyplot as plt from moabb import set_log_level from moabb.datasets import bi2012 from moabb.evaluations import WithinSessionEvaluation from moabb.paradigms import P300 +from pyriemann.estimation import XdawnCovariances +from pyriemann.tangentspace import TangentSpace +import seaborn as sns +from sklearn.pipeline import make_pipeline +from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA +from sklearn.decomposition import PCA + from pyriemann_qiskit.pipelines import ( QuantumClassifierWithDefaultRiemannianPipeline, ) -from sklearn.decomposition import PCA 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 5baf62b5..7fa6461c 100644 --- a/examples/MI/noplot_classify_alexmi_with_quantum_pipeline.py +++ b/examples/MI/noplot_classify_alexmi_with_quantum_pipeline.py @@ -12,13 +12,14 @@ # Modified from ERP/classify_P300_bi_quantum_mdm.py # License: BSD (3-clause) -from matplotlib import pyplot as plt import warnings -import seaborn as sns + +from matplotlib import pyplot as plt from moabb import set_log_level from moabb.datasets import AlexMI from moabb.evaluations import WithinSessionEvaluation from moabb.paradigms import MotorImagery +import seaborn as sns # inject cpm distance and mean to pyriemann (if not done already) from helpers.alias import ERPCov_MDM diff --git a/examples/MI/noplot_multiclass_classification.py b/examples/MI/noplot_multiclass_classification.py index 722045d6..0076c3c9 100644 --- a/examples/MI/noplot_multiclass_classification.py +++ b/examples/MI/noplot_multiclass_classification.py @@ -13,12 +13,7 @@ # Modified from plot_classify_EEG_quantum_svm # License: BSD (3-clause) -from helpers.alias import ERPCov_MDM -from pyriemann_qiskit.datasets import get_mne_sample -from pyriemann_qiskit.pipelines import ( - QuantumClassifierWithDefaultRiemannianPipeline, - QuantumMDMWithRiemannianPipeline, -) +from matplotlib import pyplot as plt from sklearn.model_selection import train_test_split from sklearn.metrics import ( confusion_matrix, @@ -26,8 +21,13 @@ balanced_accuracy_score, ) from sklearn.decomposition import PCA -from matplotlib import pyplot as plt +from helpers.alias import ERPCov_MDM +from pyriemann_qiskit.datasets import get_mne_sample +from pyriemann_qiskit.pipelines import ( + QuantumClassifierWithDefaultRiemannianPipeline, + QuantumMDMWithRiemannianPipeline, +) print(__doc__) diff --git a/examples/MI/plot_compare_dim_red.py b/examples/MI/plot_compare_dim_red.py index 48febbb9..7eb677e0 100644 --- a/examples/MI/plot_compare_dim_red.py +++ b/examples/MI/plot_compare_dim_red.py @@ -19,16 +19,19 @@ # Author: Gregoire Cattan # License: BSD (3-clause) +from sklearn.decomposition import PCA +from sklearn.model_selection import StratifiedKFold, GridSearchCV + from pyriemann_qiskit.datasets import get_mne_sample from pyriemann_qiskit.pipelines import ( QuantumClassifierWithDefaultRiemannianPipeline, ) from pyriemann_qiskit.utils.filtering import NaiveDimRed -from sklearn.decomposition import PCA -from sklearn.model_selection import StratifiedKFold, GridSearchCV print(__doc__) +############################################################################### + X, y = get_mne_sample(n_trials=10) default_params = { diff --git a/examples/other_datasets/plot_financial_data.py b/examples/other_datasets/plot_financial_data.py index 797006bf..9c75f36c 100644 --- a/examples/other_datasets/plot_financial_data.py +++ b/examples/other_datasets/plot_financial_data.py @@ -30,26 +30,27 @@ # Authors: Gregoire Cattan, Filipe Barroso # License: BSD (3-clause) +import os +import warnings + +from imblearn.under_sampling import NearMiss +from matplotlib import pyplot as plt +import numpy as np +import pandas as pd +from pyriemann.preprocessing import Whitening +from pyriemann.estimation import XdawnCovariances +from pyriemann.utils.viz import plot_waveforms from sklearn.base import TransformerMixin, BaseEstimator, ClassifierMixin from sklearn.experimental import enable_halving_search_cv # noqa -from sklearn.model_selection import HalvingGridSearchCV +from sklearn.model_selection import HalvingGridSearchCV, train_test_split from sklearn.pipeline import make_pipeline -from sklearn.model_selection import train_test_split from sklearn.preprocessing import LabelEncoder from sklearn.ensemble import RandomForestClassifier from sklearn.svm import SVC from sklearn.metrics import balanced_accuracy_score -from imblearn.under_sampling import NearMiss -from pyriemann.preprocessing import Whitening -from pyriemann.estimation import XdawnCovariances -from pyriemann.utils.viz import plot_waveforms + from pyriemann_qiskit.classification import QuanticSVM from pyriemann_qiskit.utils.preprocessing import NdRobustScaler -from matplotlib import pyplot as plt -import warnings -import pandas as pd -import numpy as np -import os print(__doc__) @@ -86,7 +87,6 @@ def plot_ERP(X, title, n=10, ylim=None, add_digest=False): def merge_2axes(fig1, fig2, file_name1="f1.png", file_name2="f2.png"): - # Modified from [4] fig1.savefig(file_name1) fig2.savefig(file_name2) plt.close(fig1) @@ -466,5 +466,3 @@ def predict(self, X): # .. [2] 'Synthetic Data of Transactions for Inmediate Loans Fraud' # https://zenodo.org/records/7418458 # .. [3] https://pyriemann.readthedocs.io/en/latest/auto_examples/ERP/plot_ERP.html -# -# .. [4] https://stackoverflow.com/questions/16748577 diff --git a/examples/other_datasets/plot_tutorial_quantum_svm_titanic_data.py b/examples/other_datasets/plot_tutorial_quantum_svm_titanic_data.py index 6208f988..9909c5cb 100644 --- a/examples/other_datasets/plot_tutorial_quantum_svm_titanic_data.py +++ b/examples/other_datasets/plot_tutorial_quantum_svm_titanic_data.py @@ -10,10 +10,10 @@ # Author: Adrien Veres # License: BSD (3-clause) +import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns -import matplotlib.pyplot as plt from sklearn.impute import KNNImputer from sklearn.preprocessing import LabelEncoder, StandardScaler from sklearn.decomposition import PCA @@ -21,6 +21,7 @@ from sklearn.linear_model import LogisticRegression from sklearn.svm import SVC from sklearn.metrics import balanced_accuracy_score + from pyriemann_qiskit.classification import QuanticSVM print(__doc__) diff --git a/examples/toys_dataset/plot_classifier_comparison.py b/examples/toys_dataset/plot_classifier_comparison.py index cef7c1ee..5c9afac2 100644 --- a/examples/toys_dataset/plot_classifier_comparison.py +++ b/examples/toys_dataset/plot_classifier_comparison.py @@ -12,13 +12,14 @@ # Modified for pyRiemann-qiskit by Gregoire Cattan # License: BSD 3 clause -import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap +import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.datasets import make_moons, make_circles from sklearn.svm import SVC + from pyriemann_qiskit.datasets import ( generate_linearly_separable_dataset, generate_qiskit_dataset, diff --git a/examples/toys_dataset/plot_learning_curve.py b/examples/toys_dataset/plot_learning_curve.py index 544fe35d..3fadf8d1 100644 --- a/examples/toys_dataset/plot_learning_curve.py +++ b/examples/toys_dataset/plot_learning_curve.py @@ -11,13 +11,15 @@ # Author: Gregoire Cattan # License: BSD (3-clause) +import matplotlib.pyplot as plt +from pyriemann.estimation import Shrinkage + from pyriemann_qiskit.datasets.utils import get_mne_sample from pyriemann_qiskit.pipelines import QuantumMDMWithRiemannianPipeline from pyriemann_qiskit.utils.hyper_params_factory import get_spsa -import matplotlib.pyplot as plt from pyriemann_qiskit.datasets import generate_linearly_separable_dataset from pyriemann_qiskit.classification import QuanticVQC -from pyriemann.estimation import Shrinkage + print(__doc__) diff --git a/examples/toys_dataset/plot_qaoa_cv.py b/examples/toys_dataset/plot_qaoa_cv.py index 98d4b0d0..2dfee07c 100644 --- a/examples/toys_dataset/plot_qaoa_cv.py +++ b/examples/toys_dataset/plot_qaoa_cv.py @@ -4,7 +4,7 @@ ==================================================================== QAOA is a parametric quantum circuit, which is usually used to -solve QUBO problems, i.e, problems with binary variables. +solve QUBO problems, i.e, problems with binary variables [1]_. In this example we will show how to use pyRiemann-qiskit implementation of QAOA-CV, which accepts continuous variables. @@ -18,22 +18,22 @@ from docplex.mp.model import Model import matplotlib.pyplot as plt +from qiskit.primitives import BackendSampler +from qiskit_aer import AerSimulator +from qiskit_algorithms.optimizers import COBYLA, SPSA + +from pyriemann_qiskit.utils.docplex import QAOACVOptimizer from pyriemann_qiskit.utils.hyper_params_factory import ( create_mixer_rotational_X_gates, create_mixer_rotational_XY_gates, create_mixer_rotational_XZ_gates, ) -from qiskit.primitives import BackendSampler -from qiskit_aer import AerSimulator -from qiskit_algorithms.optimizers import COBYLA, SPSA -from pyriemann_qiskit.utils.docplex import QAOACVOptimizer ############################################################################### # Run QAOA-CV # # Let's define a handy function to run and plot the result of the QAOA-CV -# def run_qaoa_cv(n_reps, optimizer, create_mixer): @@ -81,7 +81,6 @@ def run_qaoa_cv(n_reps, optimizer, create_mixer): # a cost an mixer operator. # # We will now try different combination of optimizer and mixers. -# maxiter = 500 optimizers = [ @@ -118,4 +117,3 @@ def run_qaoa_cv(n_reps, optimizer, create_mixer): # References # ---------- # .. [1] https://dice.cyfronet.pl/papers/JPlewa_JSienko_msc_v2.pdf -# diff --git a/examples/toys_dataset/plot_quantum_art_vqc.py b/examples/toys_dataset/plot_quantum_art_vqc.py index 987ddd78..611b31ca 100644 --- a/examples/toys_dataset/plot_quantum_art_vqc.py +++ b/examples/toys_dataset/plot_quantum_art_vqc.py @@ -11,8 +11,9 @@ # Author: Gregoire Cattan # License: BSD (3-clause) -from pyriemann_qiskit.utils.hyper_params_factory import gen_two_local import matplotlib.pyplot as plt + +from pyriemann_qiskit.utils.hyper_params_factory import gen_two_local from pyriemann_qiskit.datasets import generate_linearly_separable_dataset from pyriemann_qiskit.classification import QuanticVQC from pyriemann_qiskit.visualization import weights_spiral diff --git a/pyriemann_qiskit/classification.py b/pyriemann_qiskit/classification.py index c629e69c..f1011f10 100644 --- a/pyriemann_qiskit/classification.py +++ b/pyriemann_qiskit/classification.py @@ -5,38 +5,46 @@ quantum computer. """ from datetime import datetime -from pyriemann_qiskit.utils.quantum_provider import get_quantum_kernel -from scipy.special import softmax import logging -import numpy as np +import random from warnings import warn -from sklearn.base import BaseEstimator, ClassifierMixin, TransformerMixin -from pyriemann.utils.distance import distance +from joblib import Parallel, delayed +import numpy as np from pyriemann.classification import MDM -from pyriemann_qiskit.datasets import get_feature_dimension -from pyriemann_qiskit.utils import ( - ClassicalOptimizer, - NaiveQAOAOptimizer, - set_global_optimizer, -) -from pyriemann_qiskit.utils.distance import distance_functions -from pyriemann_qiskit.utils.utils import is_qfunction +from pyriemann.utils.distance import distance from qiskit.primitives import BackendSampler +from qiskit_algorithms.optimizers import SLSQP from qiskit_ibm_runtime import QiskitRuntimeService from qiskit_machine_learning.algorithms import QSVC, VQC, PegasosQSVC from qiskit_optimization.algorithms import ( CobylaOptimizer, SlsqpOptimizer, ) -from qiskit_algorithms.optimizers import SLSQP +from scipy.special import softmax +from sklearn.base import BaseEstimator, ClassifierMixin, TransformerMixin from sklearn.svm import SVC -from .utils.hyper_params_factory import gen_zz_feature_map, gen_two_local, get_spsa -from .utils import get_provider, get_device, get_simulator -from .utils.distance import qdistance_logeuclid_to_convex_hull -from joblib import Parallel, delayed -import random +from .datasets import get_feature_dimension +from .utils import ( + get_provider, + get_device, + get_simulator, + set_global_optimizer, + ClassicalOptimizer, + NaiveQAOAOptimizer, +) +from .utils.distance import ( + distance_functions, + qdistance_logeuclid_to_convex_hull, +) +from .utils.hyper_params_factory import ( + gen_zz_feature_map, + gen_two_local, + get_spsa, +) +from .utils.quantum_provider import get_quantum_kernel +from .utils.utils import is_qfunction logging.basicConfig(level=logging.WARNING) @@ -506,7 +514,7 @@ class QuanticVQC(QuanticClassifierBase): .. versionchanged:: 0.2.0 Add seed parameter .. versionchanged:: 0.3.0 - Add evaluated_values_ attribute. + Add `evaluated_values_` attribute. See Also -------- @@ -1033,7 +1041,7 @@ class QuanticNCH(QuanticClassifierBase): regularization : MixinTransformer | None, default=None Additional post-processing to regularize means. classical_optimizer : OptimizationAlgorithm, default=SlsqpOptimizer() - An instance of OptimizationAlgorithm [3]_. + An instance of OptimizationAlgorithm [1]_. n_jobs : int, default=6 The number of jobs to use for the computation. This works by computing each of the hulls in parallel. @@ -1050,6 +1058,10 @@ class QuanticNCH(QuanticClassifierBase): An instance of a scipy optimizer to find the optimal weights for the parametric circuit (ansatz). + References + ---------- + .. [1] \ + https://qiskit-community.github.io/qiskit-optimization/stubs/qiskit_optimization.algorithms.OptimizationAlgorithm.html#optimizationalgorithm """ def __init__( diff --git a/pyriemann_qiskit/datasets/utils.py b/pyriemann_qiskit/datasets/utils.py index 52013e7a..45fe4d06 100644 --- a/pyriemann_qiskit/datasets/utils.py +++ b/pyriemann_qiskit/datasets/utils.py @@ -2,13 +2,13 @@ Contains helper methods and classes to manage datasets. """ from warnings import warn -import numpy as np try: from mne import io, read_events, pick_types, Epochs from mne.datasets import sample except Exception: warn("mne not available. get_mne_sample will fail.") +import numpy as np from qiskit_machine_learning.datasets import ad_hoc_data from sklearn.datasets import make_classification diff --git a/pyriemann_qiskit/ensemble.py b/pyriemann_qiskit/ensemble.py index e50feed2..50c1ef45 100644 --- a/pyriemann_qiskit/ensemble.py +++ b/pyriemann_qiskit/ensemble.py @@ -2,9 +2,10 @@ Ensemble classifiers. """ import numpy as np -from pyriemann_qiskit.utils import union_of_diff from sklearn.base import ClassifierMixin, BaseEstimator +from .utils import union_of_diff + class JudgeClassifier(BaseEstimator, ClassifierMixin): @@ -19,13 +20,12 @@ class JudgeClassifier(BaseEstimator, ClassifierMixin): Parameters ---------- - clfs : ClassifierMixin[] - A list of ClassifierMixin. - judge : ClassifierMixin - An instance of ClassifierMixin. - This classifier is trained on the labels for which - classifiers clfs obtain different predictions. + Classifier trained on the inputs for which + classifiers `clfs` obtain different predictions. + + clfs : list of ClassifierMixin + Classifiers trained on the balanced dataset. Notes ----- diff --git a/pyriemann_qiskit/pipelines.py b/pyriemann_qiskit/pipelines.py index dd6459ce..d643fa8e 100644 --- a/pyriemann_qiskit/pipelines.py +++ b/pyriemann_qiskit/pipelines.py @@ -1,30 +1,31 @@ """Module for pipelines.""" import numpy as np +from pyriemann.classification import MDM +from pyriemann.estimation import XdawnCovariances, ERPCovariances +from pyriemann.preprocessing import Whitening +from pyriemann.tangentspace import TangentSpace +from qiskit_algorithms.optimizers import SLSQP +from qiskit_optimization.algorithms import SlsqpOptimizer from sklearn.base import BaseEstimator, ClassifierMixin, TransformerMixin from sklearn.decomposition import PCA from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA from sklearn.pipeline import make_pipeline, FeatureUnion from sklearn.ensemble import VotingClassifier -from qiskit_optimization.algorithms import SlsqpOptimizer -from qiskit_algorithms.optimizers import SLSQP -from pyriemann.estimation import XdawnCovariances, ERPCovariances -from pyriemann.tangentspace import TangentSpace -from pyriemann.preprocessing import Whitening -from pyriemann.classification import MDM -from pyriemann_qiskit.utils.utils import is_qfunction -from pyriemann_qiskit.utils.filtering import NoDimRed -from pyriemann_qiskit.utils.hyper_params_factory import ( - # gen_zz_feature_map, - gen_x_feature_map, - gen_two_local, - get_spsa, -) -from pyriemann_qiskit.classification import ( + +from .classification import ( QuanticNCH, QuanticVQC, QuanticSVM, QuanticMDM, ) +from .utils.filtering import NoDimRed +from .utils.hyper_params_factory import ( + # gen_zz_feature_map, + gen_x_feature_map, + gen_two_local, + get_spsa, +) +from .utils.utils import is_qfunction class BasePipeline(BaseEstimator, ClassifierMixin, TransformerMixin): diff --git a/pyriemann_qiskit/utils/distance.py b/pyriemann_qiskit/utils/distance.py index eedbdfc5..fb49b2e9 100644 --- a/pyriemann_qiskit/utils/distance.py +++ b/pyriemann_qiskit/utils/distance.py @@ -1,6 +1,7 @@ -import numpy as np +from typing_extensions import deprecated + from docplex.mp.model import Model -from pyriemann_qiskit.utils.docplex import ClassicalOptimizer, get_global_optimizer +import numpy as np from pyriemann.utils.distance import ( distance_functions, distance_logeuclid, @@ -8,7 +9,8 @@ ) from pyriemann.utils.base import logm from pyriemann.utils.mean import mean_logeuclid -from typing_extensions import deprecated + +from .docplex import ClassicalOptimizer, get_global_optimizer @deprecated( diff --git a/pyriemann_qiskit/utils/docplex.py b/pyriemann_qiskit/utils/docplex.py index db80e1af..10a016a3 100644 --- a/pyriemann_qiskit/utils/docplex.py +++ b/pyriemann_qiskit/utils/docplex.py @@ -8,11 +8,12 @@ import math import time -import numpy as np from docplex.mp.vartype import ContinuousVarType, IntegerVarType, BinaryVarType +import numpy as np +from pyriemann.utils.covariance import normalize +from qiskit.circuit.library import QAOAAnsatz from qiskit.primitives import BackendSampler from qiskit.quantum_info import Statevector -from qiskit.circuit.library import QAOAAnsatz from qiskit_algorithms import QAOA from qiskit_algorithms.optimizers import SLSQP from qiskit_optimization.algorithms import CobylaOptimizer, MinimumEigenOptimizer @@ -20,8 +21,8 @@ from qiskit_optimization.translators import from_docplex_mp from qiskit_optimization.problems import VarType from sklearn.preprocessing import MinMaxScaler -from pyriemann.utils.covariance import normalize -from pyriemann_qiskit.utils import get_simulator + +from .quantum_provider import get_simulator _global_optimizer = [None] @@ -438,7 +439,7 @@ class NaiveQAOAOptimizer(pyQiskitOptimizer): .. versionchanged:: 0.0.4 add get_weights method. .. versionchanged:: 0.3.0 - add evaluated_values_ attribute. + add `evaluated_values_` attribute. add optimizer parameter. Attributes diff --git a/pyriemann_qiskit/utils/firebase_connector.py b/pyriemann_qiskit/utils/firebase_connector.py index b88574ae..e84a16c5 100644 --- a/pyriemann_qiskit/utils/firebase_connector.py +++ b/pyriemann_qiskit/utils/firebase_connector.py @@ -1,6 +1,5 @@ import firebase_admin import os -import pandas as pd from warnings import warn try: @@ -10,6 +9,9 @@ """No firebase_admin found. Firebase connector \ can only run with mock data.""" ) + +import pandas as pd + from .firebase_cert import certificate diff --git a/pyriemann_qiskit/utils/math.py b/pyriemann_qiskit/utils/math.py index c1fd62c3..39296767 100644 --- a/pyriemann_qiskit/utils/math.py +++ b/pyriemann_qiskit/utils/math.py @@ -1,5 +1,6 @@ """Module for mathematical helpers""" from typing_extensions import deprecated + import numpy as np from pyriemann.utils.covariance import normalize diff --git a/pyriemann_qiskit/utils/mean.py b/pyriemann_qiskit/utils/mean.py index a11c642f..a91e056f 100644 --- a/pyriemann_qiskit/utils/mean.py +++ b/pyriemann_qiskit/utils/mean.py @@ -1,10 +1,12 @@ from typing_extensions import deprecated + from docplex.mp.model import Model -from pyriemann.utils.mean import mean_functions -from pyriemann_qiskit.utils.docplex import ClassicalOptimizer, get_global_optimizer from pyriemann.utils.base import logm, expm +from pyriemann.utils.mean import mean_functions from qiskit_optimization.algorithms import ADMMOptimizer +from .docplex import ClassicalOptimizer, get_global_optimizer + @deprecated( "fro_mean_convex is deprecated and will be removed in 0.3.0; " diff --git a/pyriemann_qiskit/utils/quantum_provider.py b/pyriemann_qiskit/utils/quantum_provider.py index 66c4cf84..10e1fe9f 100644 --- a/pyriemann_qiskit/utils/quantum_provider.py +++ b/pyriemann_qiskit/utils/quantum_provider.py @@ -1,15 +1,16 @@ """Module containing helpers for IBM quantum backends providers and simulators.""" -from qiskit_ibm_runtime import QiskitRuntimeService +import logging + from qiskit_aer import AerSimulator 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 ( FidelityStatevectorKernel, FidelityQuantumKernel, ) -from qiskit_algorithms.state_fidelities import ComputeUncompute -import logging def get_provider(): diff --git a/pyriemann_qiskit/visualization/art.py b/pyriemann_qiskit/visualization/art.py index 2e4aff42..3ace3884 100644 --- a/pyriemann_qiskit/visualization/art.py +++ b/pyriemann_qiskit/visualization/art.py @@ -2,8 +2,8 @@ Artistic visualization for quantum. """ -import pandas as pd import numpy as np +import pandas as pd def weights_spiral(axe, vqc, X, y, n_trainings=5): diff --git a/pyriemann_qiskit/visualization/manifold.py b/pyriemann_qiskit/visualization/manifold.py index 83a5a54d..8338ef89 100644 --- a/pyriemann_qiskit/visualization/manifold.py +++ b/pyriemann_qiskit/visualization/manifold.py @@ -2,11 +2,12 @@ Visualization of the covariance matrices on the SPD manifold. """ -import numpy as np import matplotlib.pyplot as plt -from pyriemann_qiskit.utils.math import to_xyz +import numpy as np from scipy.spatial import ConvexHull +from ..utils.math import to_xyz + def plot_cvx_hull(X, ax): """Plot the convex hull of a set of points.