Skip to content

Commit

Permalink
Fix FakeToronto import
Browse files Browse the repository at this point in the history
  • Loading branch information
manoelmarques committed Jun 24, 2022
1 parent fb307ee commit dedb679
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
10 changes: 6 additions & 4 deletions test/algorithms/classifiers/test_neural_network_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import numpy as np
import scipy
from ddt import ddt, data, idata, unpack
from qiskit import Aer, QuantumCircuit
import qiskit
from qiskit.algorithms.optimizers import COBYLA, L_BFGS_B, SPSA, Optimizer
from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import RealAmplitudes, ZZFeatureMap
from qiskit.utils import QuantumInstance, algorithm_globals
from qiskit.utils import QuantumInstance, algorithm_globals, optionals

from qiskit_machine_learning.algorithms import SerializableModelMixin
from qiskit_machine_learning.algorithms.classifiers import NeuralNetworkClassifier
Expand All @@ -48,18 +49,19 @@ def _one_hot_encode(y: np.ndarray) -> np.ndarray:
class TestNeuralNetworkClassifier(QiskitMachineLearningTestCase):
"""Neural Network Classifier Tests."""

@unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test")
def setUp(self):
super().setUp()

# specify quantum instances
algorithm_globals.random_seed = 12345
self.sv_quantum_instance = QuantumInstance(
Aer.get_backend("aer_simulator_statevector"),
qiskit.providers.aer.Aer.get_backend("aer_simulator_statevector"),
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
)
self.qasm_quantum_instance = QuantumInstance(
Aer.get_backend("aer_simulator"),
qiskit.providers.aer.Aer.get_backend("aer_simulator"),
shots=100,
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
Expand Down
9 changes: 5 additions & 4 deletions test/algorithms/classifiers/test_vqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
from sklearn.datasets import make_classification
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder

from qiskit import Aer
import qiskit
from qiskit.algorithms.optimizers import COBYLA, L_BFGS_B
from qiskit.circuit.library import RealAmplitudes, ZZFeatureMap
from qiskit.utils import QuantumInstance, algorithm_globals
from qiskit.utils import QuantumInstance, algorithm_globals, optionals

from qiskit_machine_learning.algorithms import VQC
from qiskit_machine_learning.exceptions import QiskitMachineLearningError
Expand Down Expand Up @@ -70,19 +70,20 @@ def _create_dataset(n_samples: int, n_classes: int, one_hot=True) -> _Dataset:
class TestVQC(QiskitMachineLearningTestCase):
"""VQC Tests."""

@unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test")
def setUp(self):
super().setUp()
algorithm_globals.random_seed = 1111111
self.num_classes_by_batch = []

# Set-up the quantum instances.
statevector = QuantumInstance(
Aer.get_backend("aer_simulator_statevector"),
qiskit.providers.aer.Aer.get_backend("aer_simulator_statevector"),
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
)
qasm = QuantumInstance(
Aer.get_backend("aer_simulator"),
qiskit.providers.aer.Aer.get_backend("aer_simulator"),
shots=100,
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
Expand Down
16 changes: 11 additions & 5 deletions test/algorithms/regressors/test_neural_network_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
""" Test Neural Network Regressor """
import unittest
import itertools
import os
import tempfile
Expand All @@ -19,12 +20,12 @@

import numpy as np
from ddt import ddt, unpack, idata
from qiskit import Aer, QuantumCircuit
import qiskit
from qiskit.algorithms.optimizers import COBYLA, L_BFGS_B, SPSA
from qiskit.circuit import Parameter
from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.circuit.library import ZZFeatureMap, RealAmplitudes
from qiskit.opflow import PauliSumOp
from qiskit.utils import QuantumInstance, algorithm_globals
from qiskit.utils import QuantumInstance, algorithm_globals, optionals

from qiskit_machine_learning import QiskitMachineLearningError
from qiskit_machine_learning.algorithms import SerializableModelMixin
Expand All @@ -40,18 +41,19 @@
class TestNeuralNetworkRegressor(QiskitMachineLearningTestCase):
"""Test Neural Network Regressor."""

@unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test")
def setUp(self):
super().setUp()

# specify quantum instances
algorithm_globals.random_seed = 12345
self.sv_quantum_instance = QuantumInstance(
Aer.get_backend("aer_simulator_statevector"),
qiskit.providers.aer.Aer.get_backend("aer_simulator_statevector"),
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
)
self.qasm_quantum_instance = QuantumInstance(
Aer.get_backend("aer_simulator"),
qiskit.providers.aer.Aer.get_backend("aer_simulator"),
shots=100,
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
Expand Down Expand Up @@ -239,3 +241,7 @@ def store_loss(_, loss):
regressor.fit(features, labels)

self.assertEqual(len(loss_history), 3)


if __name__ == "__main__":
unittest.main()
13 changes: 7 additions & 6 deletions test/algorithms/regressors/test_vqr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2021.
# (C) Copyright IBM 2018, 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -18,29 +18,30 @@
import numpy as np
from ddt import data, ddt

from qiskit import Aer, QuantumCircuit
import qiskit
from qiskit.algorithms.optimizers import COBYLA, L_BFGS_B
from qiskit.circuit import Parameter
from qiskit.utils import QuantumInstance, algorithm_globals
from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.utils import QuantumInstance, algorithm_globals, optionals
from qiskit_machine_learning.algorithms import VQR


@ddt
class TestVQR(QiskitMachineLearningTestCase):
"""VQR Tests."""

@unittest.skipUnless(optionals.HAS_AER, "qiskit-aer is required to run this test")
def setUp(self):
super().setUp()

# specify quantum instances
algorithm_globals.random_seed = 12345
self.sv_quantum_instance = QuantumInstance(
Aer.get_backend("aer_simulator_statevector"),
qiskit.providers.aer.Aer.get_backend("aer_simulator_statevector"),
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
)
self.qasm_quantum_instance = QuantumInstance(
Aer.get_backend("aer_simulator"),
qiskit.providers.aer.Aer.get_backend("aer_simulator"),
shots=100,
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
Expand Down
2 changes: 1 addition & 1 deletion test/connectors/test_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setup_test(self):
algorithm_globals.random_seed = 12345
# specify quantum instances
self._sv_quantum_instance = QuantumInstance(
qiskit.Aer.get_backend("aer_simulator_statevector"),
qiskit.providers.aer.Aer.get_backend("aer_simulator_statevector"),
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
)
Expand Down
4 changes: 2 additions & 2 deletions test/neural_networks/test_circuit_qnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from qiskit.circuit.library import RealAmplitudes, ZZFeatureMap
from qiskit.utils import QuantumInstance, algorithm_globals, optionals
from qiskit.compiler.transpiler import PassManagerConfig, level_1_pass_manager, level_2_pass_manager
from qiskit.test.mock import FakeToronto
from qiskit.providers.fake_provider import FakeToronto

from qiskit_machine_learning import QiskitMachineLearningError
from qiskit_machine_learning.neural_networks import CircuitQNN
Expand All @@ -52,7 +52,7 @@ def setUp(self):
algorithm_globals.random_seed = 12345
# specify "run configuration"
self.quantum_instance_sv = QuantumInstance(
qiskit.Aer.get_backend("aer_simulator_statevector"),
qiskit.providers.aer.Aer.get_backend("aer_simulator_statevector"),
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
)
Expand Down
2 changes: 1 addition & 1 deletion test/neural_networks/test_opflow_qnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setUp(self):
algorithm_globals.random_seed = 12345
# specify quantum instances
self.sv_quantum_instance = QuantumInstance(
qiskit.Aer.get_backend("aer_simulator_statevector"),
qiskit.providers.aer.Aer.get_backend("aer_simulator_statevector"),
seed_simulator=algorithm_globals.random_seed,
seed_transpiler=algorithm_globals.random_seed,
)
Expand Down

0 comments on commit dedb679

Please sign in to comment.