-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shots and feature map exposure (#14)
* hyperparams object? * Revert "hyperparams object?" This reverts commit 2ad611f. * expose `shots` parameter * expose `feature map` * push factory * add pooch in setup requirements * Revert "add pooch in setup requirements" This reverts commit 6501bc9. * update doc requirements according to a3e4e650b83a2a9ccfa5eb9a8b4234d99577d00d * add documentation for factory * flake8 * add gen_zz_feature_map to API * move import of gen_zz_feature_map to the end of import section * Improve documentation for gen_zz_feature_map * Update pyriemann_qiskit/classification.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * install git in gh action * approval missing * Revert "approval missing" This reverts commit 78b9677. * Revert "install git in gh action" This reverts commit f16bd5d. * update pyriemann requirements? * Revert "update pyriemann requirements?" This reverts commit cd20619. * upgrade pip in doc pipeline * typo in ghpages * Revert "typo in ghpages" This reverts commit c771e53. * improve ghpages pipeline * install git * fix requirement in setup.py https://stackoverflow.com/questions/32688688/how-to-write-setup-py-to-include-a-git-repository-as-a-dependency * missing -y option * Update pyriemann_qiskit/classification.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * Update pyriemann_qiskit/utils/hyper_params_factory.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * Update pyriemann_qiskit/classification.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * Update pyriemann_qiskit/utils/hyper_params_factory.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * Update pyriemann_qiskit/utils/hyper_params_factory.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * Update pyriemann_qiskit/utils/hyper_params_factory.py Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com> * fix typing of entanglement attribute * - add tests - correct and improve description of gen_zz_feature_map * various refactoring and linting * typo * generalize -> string value -> value * rename feature_dim -> n_features * use pytest.raises(ValueError) Co-authored-by: gcattan <gregoire.cattan@ibm.com> Co-authored-by: Quentin Barthélemy <q.barthelemy@gmail.com>
- Loading branch information
1 parent
274d5b4
commit f945753
Showing
9 changed files
with
155 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ sphinx-gallery | |
sphinx-bootstrap_theme | ||
numpydoc | ||
cython | ||
mne | ||
mne[data]>=0.24 | ||
seaborn | ||
scikit-learn | ||
joblib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from . import hyper_params_factory | ||
|
||
__all__ = [ | ||
'hyper_params_factory', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from qiskit.circuit.library import ZZFeatureMap | ||
|
||
|
||
def gen_zz_feature_map(reps=2, entanglement='linear'): | ||
"""Return a callable that generate a ZZFeatureMap. | ||
A feature map encodes data into a quantum state. | ||
A ZZFeatureMap is a second-order Pauli-Z evolution circuit. | ||
Parameters | ||
---------- | ||
reps : int (default 2) | ||
The number of repeated circuits, greater or equal to 1. | ||
entanglement : str | list[list[list[int]]] | \ | ||
Callable[int, list[list[list[int]]]] | ||
Specifies the entanglement structure. | ||
Entanglement structure can be provided with indices or string. | ||
Possible string values are: 'full', 'linear', 'circular' and 'sca'. | ||
Consult [1]_ for more details on entanglement structure. | ||
Returns | ||
------- | ||
ret : ZZFeatureMap | ||
An instance of ZZFeatureMap | ||
References | ||
---------- | ||
.. [1] \ | ||
https://qiskit.org/documentation/stable/0.19/stubs/qiskit.circuit.library.NLocal.html | ||
""" | ||
if reps < 1: | ||
raise ValueError("Parameter reps must be superior \ | ||
or equal to 1 (Got %d)" % reps) | ||
|
||
return lambda n_features: ZZFeatureMap(feature_dimension=n_features, | ||
reps=reps, | ||
entanglement=entanglement) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
from pyriemann_qiskit.utils.hyper_params_factory import gen_zz_feature_map | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'entanglement', ['full', 'linear', 'circular', 'sca'] | ||
) | ||
def test_gen_zz_feature_map_entangl_strings(entanglement): | ||
"""Test gen_zz_feature_map with different string options of entanglement""" | ||
n_features = 2 | ||
feature_map = gen_zz_feature_map(entanglement=entanglement)(n_features) | ||
assert isinstance(feature_map.parameters, set) | ||
|
||
|
||
def test_gen_zz_feature_map_entangl_idx(get_pauli_z_linear_entangl_idx): | ||
"""Test gen_zz_feature_map with valid indices value""" | ||
n_features = 2 | ||
reps = 2 | ||
indices = get_pauli_z_linear_entangl_idx(reps, n_features) | ||
feature_map_handle = gen_zz_feature_map(reps=reps, entanglement=indices) | ||
feature_map = feature_map_handle(n_features) | ||
assert isinstance(feature_map.parameters, set) | ||
|
||
|
||
def test_gen_zz_feature_map_entangl_handle(get_pauli_z_linear_entangl_handle): | ||
"""Test gen_zz_feature_map with a valid callable""" | ||
n_features = 2 | ||
indices = get_pauli_z_linear_entangl_handle(n_features) | ||
feature_map = gen_zz_feature_map(entanglement=indices)(n_features) | ||
assert isinstance(feature_map.parameters, set) | ||
|
||
|
||
def test_gen_zz_feature_map_entangl_invalid_value(): | ||
"""Test gen_zz_feature_map with uncorrect value""" | ||
n_features = 2 | ||
feature_map = gen_zz_feature_map(entanglement="invalid")(n_features) | ||
with pytest.raises(ValueError): | ||
feature_map.parameters |