Skip to content

Commit

Permalink
Gc/fix token incorrect with rg default pipeline (#47)
Browse files Browse the repository at this point in the history
* Implements:
- #40
- #45

* fix test

* update tests

Co-authored-by: gcattan <[email protected]>
  • Loading branch information
gcattan and gcattan authored May 2, 2022
1 parent a5eda74 commit 4e73938
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 14 additions & 4 deletions pyriemann_qiskit/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class QuanticClassifierBase(BaseEstimator, ClassifierMixin):
- If false, will perform classical computing instead
q_account_token : string (default:None)
If quantum==True and q_account_token provided,
the classification task will be running on a IBM quantum backend
the classification task will be running on a IBM quantum backend.
If `load_account` is provided, the classifier will use the previous
token saved with `IBMQ.save_account()`.
verbose : bool (default:True)
If true will output all intermediate results and logs
shots : int (default:1024)
Expand Down Expand Up @@ -94,8 +96,9 @@ def _init_quantum(self):
self._log("seed = ", aqua_globals.random_seed)
if self.q_account_token:
self._log("Real quantum computation will be performed")
IBMQ.delete_account()
IBMQ.save_account(self.q_account_token)
if not self.q_account_token == "load_account":
IBMQ.delete_account()
IBMQ.save_account(self.q_account_token)
IBMQ.load_account()
self._log("Getting provider...")
self._provider = IBMQ.get_provider(hub='ibm-q')
Expand Down Expand Up @@ -467,6 +470,11 @@ class QuantumClassifierWithDefaultRiemannianPipeline(BaseEstimator,
Maximum number of iterations to perform using SPSA optimizer.
two_local_reps : int (default: 3)
The number of repetition for the two-local cricuit.
params: Dict (default: {})
Additional parameters to pass to the nested instance
of the quantum classifier.
See QuanticClassifierBase, QuanticVQC and QuanticSVM for
a complete list of the parameters.
Notes
-----
Expand All @@ -481,6 +489,7 @@ class QuantumClassifierWithDefaultRiemannianPipeline(BaseEstimator,
get_spsa
QuanticVQC
QuanticSVM
QuanticClassifierBase
References
----------
Expand All @@ -495,7 +504,7 @@ class QuantumClassifierWithDefaultRiemannianPipeline(BaseEstimator,
def __init__(self, nfilter=1, dim_red=PCA(),
gamma=None, shots=1024, feature_entanglement='full',
feature_reps=2, spsa_trials=None, two_local_reps=None,
**params):
params={}):

self.nfilter = nfilter
self.dim_red = dim_red
Expand All @@ -505,6 +514,7 @@ def __init__(self, nfilter=1, dim_red=PCA(),
self.feature_reps = feature_reps
self.spsa_trials = spsa_trials
self.two_local_reps = two_local_reps
self.params = params

is_vqc = spsa_trials and two_local_reps
is_quantum = shots is not None
Expand Down
4 changes: 3 additions & 1 deletion tests/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ class TestQuantumClassifierWithDefaultRiemannianPipeline(BinaryFVT):
"""Functional testing for riemann quantum classifier."""
def get_params(self):
quantum_instance = \
QuantumClassifierWithDefaultRiemannianPipeline(verbose=False)
QuantumClassifierWithDefaultRiemannianPipeline(
params={"verbose": False}
)
return {
"n_samples": 4,
"n_features": 4,
Expand Down

0 comments on commit 4e73938

Please sign in to comment.