From cda6a004fe2867360ea89c27a4788f1128ef5e16 Mon Sep 17 00:00:00 2001 From: gcattan Date: Tue, 17 Sep 2024 21:37:55 +0200 Subject: [PATCH] Separate import from docplex and quantum_provider (#311) * do not import specific function from docplex module in init file * expose only quantum_provider too * [pre-commit.ci] auto fixes from pre-commit.com hooks * missing modification in test_utils_mean * group imports * [pre-commit.ci] auto fixes from pre-commit.com hooks --------- Co-authored-by: Gregoire Cattan Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- pyriemann_qiskit/classification.py | 12 +++++++----- pyriemann_qiskit/utils/__init__.py | 26 ++++---------------------- tests/test_docplex.py | 2 +- tests/test_utils_distance.py | 2 +- tests/test_utils_mean.py | 2 +- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/pyriemann_qiskit/classification.py b/pyriemann_qiskit/classification.py index f1011f10..683d036b 100644 --- a/pyriemann_qiskit/classification.py +++ b/pyriemann_qiskit/classification.py @@ -26,10 +26,7 @@ from sklearn.svm import SVC from .datasets import get_feature_dimension -from .utils import ( - get_provider, - get_device, - get_simulator, +from .utils.docplex import ( set_global_optimizer, ClassicalOptimizer, NaiveQAOAOptimizer, @@ -43,7 +40,12 @@ gen_two_local, get_spsa, ) -from .utils.quantum_provider import get_quantum_kernel +from .utils.quantum_provider import ( + get_quantum_kernel, + get_simulator, + get_provider, + get_device, +) from .utils.utils import is_qfunction logging.basicConfig(level=logging.WARNING) diff --git a/pyriemann_qiskit/utils/__init__.py b/pyriemann_qiskit/utils/__init__.py index c511d813..bcd331b3 100644 --- a/pyriemann_qiskit/utils/__init__.py +++ b/pyriemann_qiskit/utils/__init__.py @@ -1,16 +1,7 @@ from . import hyper_params_factory, filtering, preprocessing -from .quantum_provider import get_provider, get_device, get_simulator +from . import quantum_provider from .math import cov_to_corr_matrix, union_of_diff -from .docplex import ( - square_cont_mat_var, - square_int_mat_var, - square_bin_mat_var, - ClassicalOptimizer, - NaiveQAOAOptimizer, - QAOACVOptimizer, - set_global_optimizer, - get_global_optimizer, -) +from . import docplex from .firebase_connector import ( FirebaseConnector, Cache, @@ -27,19 +18,10 @@ "hyper_params_factory", "filtering", "preprocessing", - "get_provider", - "get_device", - "get_simulator", + "quantum_provider", "cov_to_corr_matrix", "union_of_diff", - "square_cont_mat_var", - "square_int_mat_var", - "square_bin_mat_var", - "ClassicalOptimizer", - "NaiveQAOAOptimizer", - "QAOACVOptimizer", - "set_global_optimizer", - "get_global_optimizer", + "docplex", "distance", "mean", "FirebaseConnector", diff --git a/tests/test_docplex.py b/tests/test_docplex.py index fe8b69da..c75ae376 100644 --- a/tests/test_docplex.py +++ b/tests/test_docplex.py @@ -1,7 +1,7 @@ import pytest from docplex.mp.model import Model from docplex.mp.vartype import ContinuousVarType, IntegerVarType, BinaryVarType -from pyriemann_qiskit.utils import ( +from pyriemann_qiskit.utils.docplex import ( square_cont_mat_var, square_int_mat_var, square_bin_mat_var, diff --git a/tests/test_utils_distance.py b/tests/test_utils_distance.py index 90fd7dd3..530d6d4b 100644 --- a/tests/test_utils_distance.py +++ b/tests/test_utils_distance.py @@ -1,6 +1,6 @@ import pytest import numpy as np -from pyriemann_qiskit.utils import ( +from pyriemann_qiskit.utils.docplex import ( ClassicalOptimizer, NaiveQAOAOptimizer, ) diff --git a/tests/test_utils_mean.py b/tests/test_utils_mean.py index c14975b4..00c9b997 100644 --- a/tests/test_utils_mean.py +++ b/tests/test_utils_mean.py @@ -5,7 +5,7 @@ from sklearn.pipeline import make_pipeline from sklearn.model_selection import StratifiedKFold, cross_val_score from pyriemann_qiskit.utils.mean import qmean_euclid, qmean_logeuclid -from pyriemann_qiskit.utils import ClassicalOptimizer, NaiveQAOAOptimizer +from pyriemann_qiskit.utils.docplex import ClassicalOptimizer, NaiveQAOAOptimizer from pyriemann_qiskit.classification import QuanticMDM from pyriemann_qiskit.datasets import get_mne_sample from qiskit_optimization.algorithms import ADMMOptimizer