From 9f40c7d50fc0a45d646d4b4a04359d41eb513af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 24 Oct 2023 15:10:29 +0200 Subject: [PATCH 1/7] Update tests to use qiskit_algorithms --- .../machine_learning/test_neural_network_classifier.py | 6 +++--- qiskit_neko/tests/nature/test_ground_state_solver.py | 5 +++-- qiskit_neko/tests/primitives/test_vqe.py | 4 ++-- requirements.txt | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/qiskit_neko/tests/machine_learning/test_neural_network_classifier.py b/qiskit_neko/tests/machine_learning/test_neural_network_classifier.py index ac96f95..914613a 100644 --- a/qiskit_neko/tests/machine_learning/test_neural_network_classifier.py +++ b/qiskit_neko/tests/machine_learning/test_neural_network_classifier.py @@ -13,9 +13,9 @@ """Tests for quantum neural networks classifier.""" import numpy as np from ddt import ddt, data -from qiskit.algorithms.optimizers import COBYLA +from qiskit_algorithms.optimizers import COBYLA +from qiskit_algorithms.utils import algorithm_globals from qiskit.primitives import Sampler as ReferenceSampler -from qiskit.utils import algorithm_globals from qiskit_aer.primitives import Sampler as AerSampler from qiskit_machine_learning.algorithms.classifiers import VQC @@ -49,7 +49,7 @@ def test_neural_network_classifier(self, implementation): num_qubits=2, optimizer=COBYLA(maxiter=100), sampler=sampler, - initial_point=np.zeros((2, 4)), + initial_point=None, ) vqc.fit(x, y01) diff --git a/qiskit_neko/tests/nature/test_ground_state_solver.py b/qiskit_neko/tests/nature/test_ground_state_solver.py index 2363181..7115d01 100644 --- a/qiskit_neko/tests/nature/test_ground_state_solver.py +++ b/qiskit_neko/tests/nature/test_ground_state_solver.py @@ -12,8 +12,8 @@ """Test ground state solvers.""" -from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver, VQE -from qiskit.algorithms.optimizers import SLSQP +from qiskit_algorithms import NumPyMinimumEigensolver, VQE +from qiskit_algorithms.optimizers import SLSQP from qiskit.primitives import Estimator from qiskit_nature.second_q.algorithms import GroundStateEigensolver from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD @@ -49,6 +49,7 @@ def test_ground_state_solver(self): vqe_solver.initial_point = [0.0] * ansatz.num_parameters calc = GroundStateEigensolver(qubit_mapper, vqe_solver) result = calc.solve(es_problem) + # Calculate expected result from numpy solver numpy_solver = NumPyMinimumEigensolver() np_calc = GroundStateEigensolver(qubit_mapper, numpy_solver) diff --git a/qiskit_neko/tests/primitives/test_vqe.py b/qiskit_neko/tests/primitives/test_vqe.py index 0239f1c..6b182e8 100644 --- a/qiskit_neko/tests/primitives/test_vqe.py +++ b/qiskit_neko/tests/primitives/test_vqe.py @@ -12,8 +12,8 @@ """Test primitives with vqe.""" -from qiskit.algorithms.minimum_eigensolvers import VQE, SamplingVQE -from qiskit.algorithms.optimizers import SPSA +from qiskit_algorithms import VQE, SamplingVQE +from qiskit_algorithms.optimizers import SPSA from qiskit.circuit.library import TwoLocal from qiskit.opflow import PauliSumOp from qiskit.primitives import BackendEstimator, BackendSampler diff --git a/requirements.txt b/requirements.txt index 360bea6..d7f8af6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ qiskit-terra +qiskit-algorithms qiskit-aer qiskit-nature[pyscf] qiskit-experiments From b2992f3e92200becdc552188105dc9a9f84a3c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 24 Oct 2023 15:18:44 +0200 Subject: [PATCH 2/7] Update python versions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc9b3d9..6d536ad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: [3.8, 3.9, 3.10] os: ["ubuntu-latest", "macOS-latest", "windows-latest"] steps: - name: Print Concurrency Group From 5803f97c93116ce5136d974d73e742535e61b713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 24 Oct 2023 15:20:45 +0200 Subject: [PATCH 3/7] Add exception for python 3.10 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6d536ad..2570367 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: [3.8, 3.9, 3.10] + python-version: [3.8, 3.9, '3.10'] os: ["ubuntu-latest", "macOS-latest", "windows-latest"] steps: - name: Print Concurrency Group From dcb2a2120b68da99c1e4e033b385f24c4eadb33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Wed, 25 Oct 2023 13:39:30 +0200 Subject: [PATCH 4/7] Skip nature test --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index bf7164f..98204be 100644 --- a/tox.ini +++ b/tox.ini @@ -14,8 +14,9 @@ commands = stestr --test-path ./tests run {posargs} [testenv:neko] +;exclude nature tests until qiskit_nature 0.7 is released commands = - stestr run {posargs} + stestr run --exclude-regex 'test_ground_state_solver' {posargs} [testenv:lint] envdir = .tox/lint From 5949ed259b1aaed5a7dc66e313cbd7445d0cef89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Thu, 26 Oct 2023 17:46:33 +0200 Subject: [PATCH 5/7] Revert "Skip nature test" This reverts commit dcb2a2120b68da99c1e4e033b385f24c4eadb33b. --- tox.ini | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 969ed28..c7564e8 100644 --- a/tox.ini +++ b/tox.ini @@ -14,9 +14,8 @@ commands = stestr --test-path ./tests run {posargs} [testenv:neko] -;exclude nature tests until qiskit_nature 0.7 is released commands = - stestr run --exclude-regex 'test_ground_state_solver' {posargs} + stestr run {posargs} [testenv:lint] envdir = .tox/lint From e4f469b0e967c0ea011b8c95d7bafe0346889279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Thu, 26 Oct 2023 18:34:19 +0200 Subject: [PATCH 6/7] Add conditional skip --- qiskit_neko/tests/nature/test_ground_state_solver.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qiskit_neko/tests/nature/test_ground_state_solver.py b/qiskit_neko/tests/nature/test_ground_state_solver.py index 7115d01..f0d010a 100644 --- a/qiskit_neko/tests/nature/test_ground_state_solver.py +++ b/qiskit_neko/tests/nature/test_ground_state_solver.py @@ -11,10 +11,13 @@ # that they have been altered from the originals. """Test ground state solvers.""" +import unittest from qiskit_algorithms import NumPyMinimumEigensolver, VQE from qiskit_algorithms.optimizers import SLSQP from qiskit.primitives import Estimator + +import qiskit_nature from qiskit_nature.second_q.algorithms import GroundStateEigensolver from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD from qiskit_nature.second_q.drivers import PySCFDriver @@ -27,6 +30,10 @@ class TestGroundStateSolvers(base.BaseTestCase): """Test the use of the execute() method in qiskit-terra.""" + @unittest.skipIf( + tuple(map(int, qiskit_nature.__version__.split("."))) < (0, 7, 0), + "This test is incompatible with qiskit_nature versions below 0.7.0", + ) @decorators.component_attr("terra", "backend", "nature") def test_ground_state_solver(self): """Test the execution of a bell circuit with an explicit shot count.""" From 2074421536d0bf6033dd847e8cd2ba0b9b0b9b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Mon, 30 Oct 2023 11:27:23 +0100 Subject: [PATCH 7/7] Update skip rule --- qiskit_neko/tests/nature/test_ground_state_solver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiskit_neko/tests/nature/test_ground_state_solver.py b/qiskit_neko/tests/nature/test_ground_state_solver.py index f0d010a..ff14c74 100644 --- a/qiskit_neko/tests/nature/test_ground_state_solver.py +++ b/qiskit_neko/tests/nature/test_ground_state_solver.py @@ -31,7 +31,7 @@ class TestGroundStateSolvers(base.BaseTestCase): """Test the use of the execute() method in qiskit-terra.""" @unittest.skipIf( - tuple(map(int, qiskit_nature.__version__.split("."))) < (0, 7, 0), + tuple(map(int, qiskit_nature.__version__.split(".")[:2])) < (0, 7), "This test is incompatible with qiskit_nature versions below 0.7.0", ) @decorators.component_attr("terra", "backend", "nature")