Changed test_ae.py back to master
# =============================================================================
import unittest
-from test.common import QiskitAquaTestCase
import numpy as np
-from qiskit_aqua.algorithms.single_sample import AmplitudeEstimation
+from parameterized import parameterized
+
+from qiskit import LegacySimulators
+from qiskit_aqua.algorithms import AmplitudeEstimation
from qiskit_aqua.components.uncertainty_problems import EuropeanCallExpectedValue, EuropeanCallDelta, FixedIncomeExpectedValue
from qiskit_aqua.components.random_distributions import LogNormalDistribution, MultivariateNormalDistribution
-from qiskit import BasicAer
+
+from test.common import QiskitAquaTestCase
class TestEuropeanCallOption(QiskitAquaTestCase):
- def test_expected_value(self):
+ @parameterized.expand([
+ 'qasm_simulator',
+ 'statevector_simulator'
+ ])
+ def test_expected_value(self, simulator):
# number of qubits to represent the uncertainty
num_uncertainty_qubits = 3
@@ -71,12 +78,16 @@ class TestEuropeanCallOption(QiskitAquaTestCase):
# construct amplitude estimation
ae = AmplitudeEstimation(m, european_call)
- # result = ae.run(quantum_instance=Aer.get_backend('qasm_simulator_py'), shots=100)
- result = ae.run(quantum_instance=BasicAer.get_backend('statevector_simulator'))
+ result = ae.run(quantum_instance=LegacySimulators.get_backend(simulator))
+ # result = ae.run(quantum_instance=LegacySimulators.get_backend('statevector_simulator'))
self.assertEqual(0.0, np.round(result['estimation'] - 0.045705353233, decimals=4))
- def test_delta(self):
+ @parameterized.expand([
+ 'qasm_simulator',
+ 'statevector_simulator'
+ ])
+ def test_delta(self, simulator):
# number of qubits to represent the uncertainty
num_uncertainty_qubits = 3
@@ -116,8 +127,8 @@ class TestEuropeanCallOption(QiskitAquaTestCase):
# construct amplitude estimation
ae = AmplitudeEstimation(m, european_call_delta)
- # result = ae.run(quantum_instance=Aer.get_backend('qasm_simulator_py'), shots=100)
- result = ae.run(quantum_instance=BasicAer.get_backend('statevector_simulator'))
+ result = ae.run(quantum_instance=LegacySimulators.get_backend(simulator))
+ # result = ae.run(quantum_instance=LegacySimulators.get_backend('statevector_simulator'))
self.assertEqual(0.0, np.round(result['estimation'] - 0.5000, decimals=4))
