From eb30b6b0e8b042a1f431a1ce7a633856b8b5bcf4 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Fri, 15 Sep 2023 09:37:04 +0200 Subject: [PATCH] Switch from `qiskit.algorithms` to `qiskit_algorithms` (#1252) * refactor: greedily replace qiskit.algorithms with qiskit_algorithms This will still fail some tests because of isinstance checks but I am using the online CI to tell me where it fails. * fix: isinstance checks against qiskit_algorithms classes We need to look at the full hierarchy of subclasses to properly do this. * docs: add explanatory comment for the previous commits' workarond * Update qiskit_algorithms import locations and docs references * Use untyped version of qiskit-algorithms * fix: remove unused type ignore comments * docs: update docs to use qiskit_algorithms * test: update tests to use qiskit_algorithms * fix: minor lint and syntax fixes * Update the use of algorithm_globals - removes the use of `num_processes` because nowadays, `qiskit.tools.parallel_map` has more means to configure the number of parallel processes rendering `algorithm_globals.num_processes` obsolete - replaces all other usage of `qiskit.utils.algorithm_globals` with `qiskit_algorithms.utils.algorithm_globals` * docs: update AdaptVQE guide introduction * Use validate_min from qiskit-algorithms --- docs/conf.py | 1 + docs/getting_started.rst | 12 ++++----- docs/howtos/adapt_vqe.rst | 15 ++++++----- docs/howtos/numpy_eigensolver.rst | 8 +++--- docs/howtos/numpy_minimum_eigensolver.rst | 8 +++--- docs/howtos/vqe_ucc.rst | 10 ++++---- docs/howtos/vqe_uvcc.rst | 10 ++++---- docs/tutorials/01_electronic_structure.ipynb | 2 +- docs/tutorials/02_vibrational_structure.ipynb | 2 +- docs/tutorials/03_ground_state_solvers.ipynb | 12 ++++----- .../tutorials/04_excited_states_solvers.ipynb | 6 ++--- .../07_leveraging_qiskit_runtime.ipynb | 6 ++--- docs/tutorials/10_lattice_models.ipynb | 2 +- .../12_deuteron_binding_energy.ipynb | 6 ++--- qiskit_nature/__init__.py | 4 +-- qiskit_nature/logging.py | 10 ++++---- qiskit_nature/second_q/algorithms/__init__.py | 2 +- .../excited_states_eigensolver.py | 2 +- .../algorithms/excited_states_solvers/qeom.py | 9 +++---- .../qeom_electronic_ops_builder.py | 2 -- .../qeom_vibrational_ops_builder.py | 2 -- .../ground_state_eigensolver.py | 2 +- .../library/initial_states/hartree_fock.py | 2 +- .../second_q/drivers/pyscfd/pyscfdriver.py | 2 +- .../second_q/mappers/qubit_mapper.py | 2 +- .../second_q/mappers/tapered_qubit_mapper.py | 2 +- .../second_q/problems/base_problem.py | 5 ++-- .../second_q/problems/eigenstate_result.py | 25 ++++++++++++------- .../problems/electronic_structure_problem.py | 7 +++--- .../problems/lattice_model_problem.py | 3 +-- .../second_q/problems/lattice_model_result.py | 2 +- .../problems/vibrational_structure_problem.py | 5 ++-- .../problems/vibrational_structure_result.py | 2 +- requirements.txt | 1 + .../test_bosonic_esc_calculation.py | 7 +++--- .../test_excited_states_solvers.py | 7 +++--- ...test_excited_states_solvers_auxiliaries.py | 6 ++--- .../test_qeom_electronic_ops.py | 2 +- .../test_qeom_vibrational_ops.py | 2 +- .../test_advanced_ucc_variants.py | 6 ++--- .../test_groundstate_eigensolver.py | 6 ++--- .../ground_state_solvers/test_swaprz.py | 6 ++--- .../circuit/library/ansatzes/test_chc.py | 6 ++--- .../circuit/library/ansatzes/test_uvcc.py | 6 ++--- .../drivers/test_driver_methods_gsc.py | 2 +- .../formats/fcidump/test_methods_fcidump.py | 2 +- .../operators/test_symmetric_two_body.py | 2 +- .../test_electronic_structure_problem.py | 2 +- .../problems/test_lattice_model_problem.py | 3 +-- .../properties/test_electronic_density.py | 2 +- test/test_end2end_with_vqe.py | 6 ++--- 51 files changed, 128 insertions(+), 136 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 97d39fcdd..c245e130c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -205,6 +205,7 @@ "numpy": ("https://numpy.org/doc/stable/", None), "scipy": ("https://docs.scipy.org/doc/scipy/", None), "qiskit": ("https://qiskit.org/documentation/", None), + "qiskit-algorithms": ("https://qiskit.org/ecosystem/algorithms/", None), "rustworkx": ("https://qiskit.org/ecosystem/rustworkx/", None), "sparse": ("https://sparse.pydata.org/en/stable/", None), } diff --git a/docs/getting_started.rst b/docs/getting_started.rst index 8544532ea..a09105cf2 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -121,7 +121,7 @@ Ready to get going?... ====================== Now that Qiskit Nature is installed, let's try a chemistry application experiment -using the :class:`~qiskit.algorithms.minimum_eigensolvers.VQE` (Variational +using the :class:`~qiskit_algorithms.VQE` (Variational Quantum Eigensolver) algorithm to compute the ground-state (minimum) energy of a molecule. @@ -146,7 +146,7 @@ molecule. mapper = ParityMapper(num_particles=problem.num_particles) # setup the classical optimizer for the VQE - from qiskit.algorithms.optimizers import L_BFGS_B + from qiskit_algorithms.optimizers import L_BFGS_B optimizer = L_BFGS_B() @@ -170,7 +170,7 @@ molecule. ) # set up our actual VQE instance - from qiskit.algorithms.minimum_eigensolvers import VQE + from qiskit_algorithms import VQE vqe = VQE(estimator, ansatz, optimizer) # ensure that the optimizer starts in the all-zero state which corresponds to @@ -224,11 +224,11 @@ are provided to it; a reduction in complexity that is particularly advantageous for NISQ computers. For actually finding the ground state solution, the Variational Quantum -Eigensolver (:class:`~qiskit.algorithms.minimum_eigensolvers.VQE`) algorithm is +Eigensolver (:class:`~qiskit_algorithms.VQE`) algorithm is used. Its main three components are the estimator primitive (:class:`~qiskit.primitives.Estimator`), wavefunction ansatz (:class:`~qiskit_nature.second_q.circuit.library.UCCSD`), and optimizer -(:class:`~qiskit.algorithms.optimizers.L_BFGS_B`). +(:class:`~qiskit_algorithms.optimizers.L_BFGS_B`). The :class:`~qiskit_nature.second_q.circuit.library.UCCSD` component is the only one provided directly by Qiskit Nature and it is usually paired with the :class:`~qiskit_nature.second_q.circuit.library.HartreeFock` initial state and @@ -237,7 +237,7 @@ an all-zero initial point for the optimizer. The entire problem is then solved using a :class:`~qiskit_nature.second_q.algorithms.GroundStateEigensolver` which wraps both, the :class:`~qiskit_nature.second_q.mappers.ParityMapper` and -:class:`~qiskit.algorithms.minimum_eigensolvers.VQE`. Since an +:class:`~qiskit_algorithms.VQE`. Since an :class:`~qiskit_nature.second_q.problems.ElectronicStructureProblem` is provided to it (which was the output of the :class:`~qiskit_nature.second_q.drivers.PySCFDriver`) it also returns an diff --git a/docs/howtos/adapt_vqe.rst b/docs/howtos/adapt_vqe.rst index 19229662e..d3d10615e 100644 --- a/docs/howtos/adapt_vqe.rst +++ b/docs/howtos/adapt_vqe.rst @@ -1,10 +1,9 @@ Find ground state energy using AdaptVQE ======================================= -As of Qiskit Nature v0.5, the :class:`~qiskit.algorithms.minimum_eigensolvers.AdaptVQE` -algorithm has been migrated to Qiskit Terra (released in v0.22). +This guide outlines how the :class:`~qiskit_algorithms.AdaptVQE` algorithm can +be used to find the ground state solutions of natural science problems. -This tutorial outlines how the algorithm can be used. 1. We obtain an :class:`~qiskit_nature.second_q.problems.ElectronicStructureProblem` which we want to solve: @@ -38,22 +37,22 @@ This tutorial outlines how the algorithm can be used. ), ) -4. We setup a :class:`~qiskit.algorithms.minimum_eigensolvers.VQE`: +4. We setup a :class:`~qiskit_algorithms.VQE`: .. testcode:: import numpy as np - from qiskit.algorithms.optimizers import SLSQP - from qiskit.algorithms.minimum_eigensolvers import VQE + from qiskit_algorithms import VQE + from qiskit_algorithms.optimizers import SLSQP from qiskit.primitives import Estimator vqe = VQE(Estimator(), ansatz, SLSQP()) vqe.initial_point = np.zeros(ansatz.num_parameters) -5. We setup the :class:`~qiskit.algorithms.minimum_eigensolvers.AdaptVQE`: +5. We setup the :class:`~qiskit_algorithms.AdaptVQE`: .. testcode:: - from qiskit.algorithms.minimum_eigensolvers import AdaptVQE + from qiskit_algorithms import AdaptVQE adapt_vqe = AdaptVQE(vqe) adapt_vqe.supports_aux_operators = lambda: True # temporary fix diff --git a/docs/howtos/numpy_eigensolver.rst b/docs/howtos/numpy_eigensolver.rst index 9d8e8fc91..563340a8f 100644 --- a/docs/howtos/numpy_eigensolver.rst +++ b/docs/howtos/numpy_eigensolver.rst @@ -4,8 +4,8 @@ Find excited state energies using the NumPyEigensolver ====================================================== In order to ensure a physically meaningful excited states of a hamiltonian are found when using the -:class:`~qiskit.algorithms.eigensolvers.NumPyEigensolver` one needs to set the -:attr:`~qiskit.algorithms.eigensolvers.NumPyEigensolver.filter_criterion` attribute +:class:`~qiskit_algorithms.NumPyEigensolver` one needs to set the +:attr:`~qiskit_algorithms.NumPyEigensolver.filter_criterion` attribute of the solver. Subclasses of :class:`~qiskit_nature.second_q.problems.BaseProblem` in Qiskit Nature provide the @@ -30,11 +30,11 @@ Below we show how you can use this setting. from qiskit_nature.second_q.mappers import JordanWignerMapper mapper = JordanWignerMapper() -3. We setup our :class:`~qiskit.algorithms.eigensolvers.NumPyEigensolver`: +3. We setup our :class:`~qiskit_algorithms.NumPyEigensolver`: .. testcode:: - from qiskit.algorithms.eigensolvers import NumPyEigensolver + from qiskit_algorithms import NumPyEigensolver algo = NumPyEigensolver(k=100) algo.filter_criterion = problem.get_default_filter_criterion() diff --git a/docs/howtos/numpy_minimum_eigensolver.rst b/docs/howtos/numpy_minimum_eigensolver.rst index 15ea8fdc7..d3b649c52 100644 --- a/docs/howtos/numpy_minimum_eigensolver.rst +++ b/docs/howtos/numpy_minimum_eigensolver.rst @@ -4,8 +4,8 @@ Find ground state energy using the NumPyMinimumEigensolver ========================================================== In order to ensure a physically meaningful ground state of a hamiltonian is found when using the -:class:`~qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver` one needs to set the -:attr:`~qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver.filter_criterion` attribute +:class:`~qiskit_algorithms.NumPyMinimumEigensolver` one needs to set the +:attr:`~qiskit_algorithms.NumPyMinimumEigensolver.filter_criterion` attribute of the solver. Subclasses of :class:`~qiskit_nature.second_q.problems.BaseProblem` in Qiskit Nature provide the @@ -30,11 +30,11 @@ Below we show how you can use this setting. from qiskit_nature.second_q.mappers import JordanWignerMapper mapper = JordanWignerMapper() -3. We setup our :class:`~qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver`: +3. We setup our :class:`~qiskit_algorithms.minimum_eigensolvers.NumPyMinimumEigensolver`: .. testcode:: - from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver + from qiskit_algorithms import NumPyMinimumEigensolver algo = NumPyMinimumEigensolver() algo.filter_criterion = problem.get_default_filter_criterion() diff --git a/docs/howtos/vqe_ucc.rst b/docs/howtos/vqe_ucc.rst index 6a63952fa..3ba0b2207 100644 --- a/docs/howtos/vqe_ucc.rst +++ b/docs/howtos/vqe_ucc.rst @@ -4,8 +4,8 @@ Use a UCC-like ansatz with a VQE ================================ When using a :class:`~qiskit_nature.second_q.circuit.library.UCC`-style ansatz with a -:class:`~qiskit.algorithms.minimum_eigensolvers.VQE` one needs to pay particular attention to the -:attr:`~qiskit.algorithms.minimum_eigensolvers.VQE.initial_point` attribute which indicates from +:class:`~qiskit_algorithms.VQE` one needs to pay particular attention to the +:attr:`~qiskit_algorithms.VQE.initial_point` attribute which indicates from which set of initial parameters the optimization routine should start. By default, VQE will start from a *random* initial point. In this how to we show how one can set a custom initial point instead (for example to guarantee that one starts from the @@ -43,13 +43,13 @@ Hartree-Fock state). ), ) -4. We setup a :class:`~qiskit.algorithms.minimum_eigensolvers.VQE`: +4. We setup a :class:`~qiskit_algorithms.VQE`: .. testcode:: import numpy as np - from qiskit.algorithms.optimizers import SLSQP - from qiskit.algorithms.minimum_eigensolvers import VQE + from qiskit_algorithms import VQE + from qiskit_algorithms.optimizers import SLSQP from qiskit.primitives import Estimator vqe = VQE(Estimator(), ansatz, SLSQP()) diff --git a/docs/howtos/vqe_uvcc.rst b/docs/howtos/vqe_uvcc.rst index 539943537..b474e6673 100644 --- a/docs/howtos/vqe_uvcc.rst +++ b/docs/howtos/vqe_uvcc.rst @@ -4,8 +4,8 @@ Use a UVCC-like ansatz with a VQE ================================= When using a :class:`~qiskit_nature.second_q.circuit.library.UVCC`-style ansatz with a -:class:`~qiskit.algorithms.minimum_eigensolvers.VQE` one needs to pay particular attention to the -:attr:`~qiskit.algorithms.minimum_eigensolvers.VQE.initial_point` attribute which indicates from +:class:`~qiskit_algorithms.VQE` one needs to pay particular attention to the +:attr:`~qiskit_algorithms.VQE.initial_point` attribute which indicates from which set of initial parameters the optimization routine should start. By default, VQE will start from a *random* initial point. In this how to we show how one can set a custom initial point instead (for example to guarantee that one starts from the @@ -40,13 +40,13 @@ we will simply show how to use the ), ) -3. We setup a :class:`~qiskit.algorithms.minimum_eigensolvers.VQE`: +3. We setup a :class:`~qiskit_algorithms.VQE`: .. testcode:: import numpy as np - from qiskit.algorithms.optimizers import SLSQP - from qiskit.algorithms.minimum_eigensolvers import VQE + from qiskit_algorithms import VQE + from qiskit_algorithms.optimizers import SLSQP from qiskit.primitives import Estimator vqe = VQE(Estimator(), ansatz, SLSQP()) diff --git a/docs/tutorials/01_electronic_structure.ipynb b/docs/tutorials/01_electronic_structure.ipynb index 6448105fe..d018edcee 100644 --- a/docs/tutorials/01_electronic_structure.ipynb +++ b/docs/tutorials/01_electronic_structure.ipynb @@ -523,7 +523,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n", + "from qiskit_algorithms import NumPyMinimumEigensolver\n", "from qiskit_nature.second_q.algorithms import GroundStateEigensolver\n", "from qiskit_nature.second_q.mappers import JordanWignerMapper\n", "\n", diff --git a/docs/tutorials/02_vibrational_structure.ipynb b/docs/tutorials/02_vibrational_structure.ipynb index 3a7e4c04c..3150b09c9 100644 --- a/docs/tutorials/02_vibrational_structure.ipynb +++ b/docs/tutorials/02_vibrational_structure.ipynb @@ -666,7 +666,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n", + "from qiskit_algorithms import NumPyMinimumEigensolver\n", "from qiskit_nature.second_q.algorithms import GroundStateEigensolver\n", "\n", "solver = GroundStateEigensolver(\n", diff --git a/docs/tutorials/03_ground_state_solvers.ipynb b/docs/tutorials/03_ground_state_solvers.ipynb index 9d63bae6c..452c8c49a 100644 --- a/docs/tutorials/03_ground_state_solvers.ipynb +++ b/docs/tutorials/03_ground_state_solvers.ipynb @@ -77,7 +77,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n", + "from qiskit_algorithms import NumPyMinimumEigensolver\n", "\n", "numpy_solver = NumPyMinimumEigensolver()" ] @@ -99,8 +99,8 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import VQE\n", - "from qiskit.algorithms.optimizers import SLSQP\n", + "from qiskit_algorithms import VQE\n", + "from qiskit_algorithms.optimizers import SLSQP\n", "from qiskit.primitives import Estimator\n", "from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD\n", "\n", @@ -127,7 +127,7 @@ "\n", "1. An Estimator primitive: these were released as part of Qiskit Terra 0.22. To learn more about primitives, check out [this resource](https://qiskit.org/documentation/apidoc/primitives.html).\n", "2. A variational form: here we use the Unitary Coupled Cluster (UCC) ansatz (see for instance [Physical Review A 98.2 (2018): 022322]). Since it is a chemistry standard, a factory is already available allowing a fast initialization of a VQE with UCC. The default is to use all single and double excitations. However, the excitation type (S, D, SD) as well as other parameters can be selected. We also prepend the `UCCSD` variational form with a `HartreeFock` initial state, which initializes the occupation of our qubits according to the problem which we are trying solve.\n", - "3. An optimizer: this is the classical piece of code in charge of optimizing the parameters in our variational form. See [the corresponding documentation of Qiskit Terra](https://qiskit.org/documentation/stubs/qiskit.algorithms.optimizers.html) for more information.\n", + "3. An optimizer: this is the classical piece of code in charge of optimizing the parameters in our variational form. See [the corresponding documentation](https://qiskit.org/ecosystem/algorithms/apidocs/qiskit_algorithms.optimizers.html) for more information.\n", "\n", "One could also use any available ansatz / initial state or even define one's own. For instance," ] @@ -138,7 +138,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import VQE\n", + "from qiskit_algorithms import VQE\n", "from qiskit.circuit.library import TwoLocal\n", "\n", "tl_circuit = TwoLocal(\n", @@ -314,7 +314,7 @@ } ], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n", + "from qiskit_algorithms import NumPyMinimumEigensolver\n", "from qiskit_nature.second_q.drivers import GaussianForcesDriver\n", "from qiskit_nature.second_q.mappers import DirectMapper\n", "from qiskit_nature.second_q.problems import HarmonicBasis\n", diff --git a/docs/tutorials/04_excited_states_solvers.ipynb b/docs/tutorials/04_excited_states_solvers.ipynb index eeeafdb31..c2cb66851 100644 --- a/docs/tutorials/04_excited_states_solvers.ipynb +++ b/docs/tutorials/04_excited_states_solvers.ipynb @@ -78,7 +78,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.eigensolvers import NumPyEigensolver\n", + "from qiskit_algorithms import NumPyEigensolver\n", "\n", "numpy_solver = NumPyEigensolver(k=4, filter_criterion=es_problem.get_default_filter_criterion())" ] @@ -134,8 +134,8 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import VQE\n", - "from qiskit.algorithms.optimizers import SLSQP\n", + "from qiskit_algorithms import VQE\n", + "from qiskit_algorithms.optimizers import SLSQP\n", "from qiskit.primitives import Estimator\n", "from qiskit_nature.second_q.algorithms import GroundStateEigensolver, QEOM, EvaluationRule\n", "from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD\n", diff --git a/docs/tutorials/07_leveraging_qiskit_runtime.ipynb b/docs/tutorials/07_leveraging_qiskit_runtime.ipynb index 3cfef05c2..1b85c125a 100644 --- a/docs/tutorials/07_leveraging_qiskit_runtime.ipynb +++ b/docs/tutorials/07_leveraging_qiskit_runtime.ipynb @@ -104,7 +104,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n", + "from qiskit_algorithms import NumPyMinimumEigensolver\n", "from qiskit_nature.second_q.algorithms.ground_state_solvers import GroundStateEigensolver\n", "\n", "np_solver = NumPyMinimumEigensolver()\n", @@ -207,7 +207,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.optimizers import SPSA\n", + "from qiskit_algorithms.optimizers import SPSA\n", "\n", "optimizer = SPSA(maxiter=100)\n", "\n", @@ -227,7 +227,7 @@ "metadata": {}, "outputs": [], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import VQE\n", + "from qiskit_algorithms import VQE\n", "from qiskit.primitives import Estimator\n", "\n", "estimator = Estimator()\n", diff --git a/docs/tutorials/10_lattice_models.ipynb b/docs/tutorials/10_lattice_models.ipynb index 15de9362c..1d9f42662 100644 --- a/docs/tutorials/10_lattice_models.ipynb +++ b/docs/tutorials/10_lattice_models.ipynb @@ -1116,7 +1116,7 @@ } ], "source": [ - "from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver\n", + "from qiskit_algorithms import NumPyMinimumEigensolver\n", "from qiskit_nature.second_q.algorithms import GroundStateEigensolver\n", "from qiskit_nature.second_q.mappers import JordanWignerMapper\n", "\n", diff --git a/docs/tutorials/12_deuteron_binding_energy.ipynb b/docs/tutorials/12_deuteron_binding_energy.ipynb index 976e09280..db351278c 100644 --- a/docs/tutorials/12_deuteron_binding_energy.ipynb +++ b/docs/tutorials/12_deuteron_binding_energy.ipynb @@ -38,9 +38,9 @@ "import matplotlib.pyplot as plt\n", "from IPython.display import display, clear_output\n", "from qiskit.primitives import Estimator\n", - "from qiskit.algorithms.minimum_eigensolvers import VQE\n", - "from qiskit.algorithms.observables_evaluator import estimate_observables\n", - "from qiskit.algorithms.optimizers import COBYLA, SLSQP\n", + "from qiskit_algorithms import VQE\n", + "from qiskit_algorithms.observables_evaluator import estimate_observables\n", + "from qiskit_algorithms.optimizers import COBYLA, SLSQP\n", "from qiskit.circuit import QuantumCircuit, Parameter\n", "from qiskit.circuit.library import TwoLocal\n", "from qiskit.quantum_info import Pauli, SparsePauliOp\n", diff --git a/qiskit_nature/__init__.py b/qiskit_nature/__init__.py index 23180a1b4..aeb2c1fb6 100644 --- a/qiskit_nature/__init__.py +++ b/qiskit_nature/__init__.py @@ -50,9 +50,7 @@ """ -from qiskit.algorithms.minimum_eigen_solvers.minimum_eigen_solver import ( - ListOrDict as ListOrDictType, -) +from qiskit_algorithms.list_or_dict import ListOrDict as ListOrDictType from .exceptions import QiskitNatureError, UnsupportMethodError from .logging import logging diff --git a/qiskit_nature/logging.py b/qiskit_nature/logging.py index 5d4af9460..80505ea71 100644 --- a/qiskit_nature/logging.py +++ b/qiskit_nature/logging.py @@ -73,7 +73,7 @@ def get_levels_for_names(self, names: List[str]) -> Dict[str, int]: """Return logging levels for module names. Args: - names: list of module names (qiskit_nature.second_q.drivers, qiskit.algorithms etc) + names: list of module names (qiskit_nature.second_q.drivers, qiskit_algorithms etc) Returns: Dictionary mapping names to effective level """ @@ -89,7 +89,7 @@ def set_levels_for_names( """Set logging levels for module names. Args: - name_levels: Dictionary of module names (qiskit_nature.second_q, qiskit.algorithms etc) + name_levels: Dictionary of module names (qiskit_nature.second_q, qiskit_algorithms etc) to desired level add_default_handler: add or not the default stream handler """ @@ -138,7 +138,7 @@ def remove_all_handlers(self, names: List[str]) -> None: """Remove all handlers from modules. Args: - names: list of module names (qiskit_nature.second_q.drivers, qiskit.algorithms etc) + names: list of module names (qiskit_nature.second_q.drivers, qiskit_algorithms etc) """ for name in names: logger = python_logging.getLogger(name) @@ -150,7 +150,7 @@ def remove_default_handler(self, names: List[str]) -> None: """Remove default handler from modules. Args: - names: list of module names (qiskit_nature.second_q.drivers, qiskit.algorithms etc) + names: list of module names (qiskit_nature.second_q.drivers, qiskit_algorithms etc) """ for name in names: logger = python_logging.getLogger(name) @@ -165,7 +165,7 @@ def log_to_file( """Logs modules to file. Args: - names: list of module names (qiskit_nature.second_q.drivers, qiskit.algorithms etc) + names: list of module names (qiskit_nature.second_q.drivers, qiskit_algorithms etc) path: file path mode: file open mode. If it is not specified, 'a' is used to append Returns: diff --git a/qiskit_nature/second_q/algorithms/__init__.py b/qiskit_nature/second_q/algorithms/__init__.py index 3f919b75c..43f04e7ca 100644 --- a/qiskit_nature/second_q/algorithms/__init__.py +++ b/qiskit_nature/second_q/algorithms/__init__.py @@ -78,7 +78,7 @@ Initial Points ++++++++++++++ -When using variational algorithms such as the :class:`~qiskit.algorithms.minimum_eigensolvers.VQE` +When using variational algorithms such as the :class:`~qiskit_algorithms.VQE` it may be necessary to set the initial parameters for the optimizer to a specific value (by default, the optimizer will start from a random point). This depends on the problem one is trying to solve as well as the ansatz used to solve the problem. To this extent, the following submodule provides diff --git a/qiskit_nature/second_q/algorithms/excited_states_solvers/excited_states_eigensolver.py b/qiskit_nature/second_q/algorithms/excited_states_solvers/excited_states_eigensolver.py index 663428023..be5e2883d 100644 --- a/qiskit_nature/second_q/algorithms/excited_states_solvers/excited_states_eigensolver.py +++ b/qiskit_nature/second_q/algorithms/excited_states_solvers/excited_states_eigensolver.py @@ -16,7 +16,7 @@ import logging -from qiskit.algorithms.eigensolvers import Eigensolver +from qiskit_algorithms import Eigensolver from qiskit.quantum_info import SparsePauliOp from qiskit_nature.second_q.mappers import QubitMapper diff --git a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py index 791d8f5c5..8f4c91e88 100644 --- a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py +++ b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom.py @@ -24,14 +24,12 @@ import numpy as np from scipy import linalg -from qiskit.algorithms.eigensolvers import EigensolverResult -from qiskit.algorithms.list_or_dict import ListOrDict as ListOrDictType -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolver -from qiskit.algorithms.observables_evaluator import estimate_observables +from qiskit_algorithms import EigensolverResult, MinimumEigensolver +from qiskit_algorithms.list_or_dict import ListOrDict as ListOrDictType +from qiskit_algorithms.observables_evaluator import estimate_observables from qiskit.circuit import QuantumCircuit from qiskit.tools import parallel_map from qiskit.tools.events import TextProgressBar -from qiskit.utils import algorithm_globals from qiskit.quantum_info import SparsePauliOp from qiskit.primitives import BaseEstimator @@ -504,7 +502,6 @@ def _build_one_sector(available_hopping_ops): self._build_commutator_routine, to_be_computed_list, task_args=(untap_operator,), - num_processes=algorithm_globals.num_processes, ) all_matrix_operators = {} for result in results: diff --git a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_electronic_ops_builder.py b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_electronic_ops_builder.py index 1a39183f8..619e0bda6 100644 --- a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_electronic_ops_builder.py +++ b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_electronic_ops_builder.py @@ -18,7 +18,6 @@ from qiskit.quantum_info import SparsePauliOp from qiskit.tools import parallel_map -from qiskit.utils import algorithm_globals from qiskit_nature import QiskitNatureError from qiskit_nature.second_q.circuit.library import UCC @@ -86,7 +85,6 @@ def build_electronic_ops( _build_single_hopping_operator, to_be_executed_list, task_args=(num_spatial_orbitals, qubit_mapper), - num_processes=algorithm_globals.num_processes, ) for key, res in zip(hopping_operators.keys(), result): diff --git a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_vibrational_ops_builder.py b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_vibrational_ops_builder.py index a9af7ed5e..e2d1d82f3 100644 --- a/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_vibrational_ops_builder.py +++ b/qiskit_nature/second_q/algorithms/excited_states_solvers/qeom_vibrational_ops_builder.py @@ -18,7 +18,6 @@ from qiskit.quantum_info import SparsePauliOp from qiskit.tools import parallel_map -from qiskit.utils import algorithm_globals from qiskit_nature.second_q.circuit.library import UVCC from qiskit_nature.second_q.operators import VibrationalOp @@ -75,7 +74,6 @@ def build_vibrational_ops( _build_single_hopping_operator, to_be_executed_list, task_args=(num_modals, qubit_mapper), - num_processes=algorithm_globals.num_processes, ) for key, res in zip(hopping_operators.keys(), result): diff --git a/qiskit_nature/second_q/algorithms/ground_state_solvers/ground_state_eigensolver.py b/qiskit_nature/second_q/algorithms/ground_state_solvers/ground_state_eigensolver.py index 1936e813a..357b8895a 100644 --- a/qiskit_nature/second_q/algorithms/ground_state_solvers/ground_state_eigensolver.py +++ b/qiskit_nature/second_q/algorithms/ground_state_solvers/ground_state_eigensolver.py @@ -16,7 +16,7 @@ import logging -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolver +from qiskit_algorithms import MinimumEigensolver from qiskit.quantum_info import SparsePauliOp from qiskit_nature.second_q.operators import SparseLabelOp diff --git a/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py b/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py index bd29faabc..f18f95543 100644 --- a/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py +++ b/qiskit_nature/second_q/circuit/library/initial_states/hartree_fock.py @@ -17,7 +17,7 @@ from qiskit import QuantumRegister from qiskit.circuit.library import BlueprintCircuit from qiskit.quantum_info import SparsePauliOp -from qiskit.utils.validation import validate_min +from qiskit_algorithms.utils.validation import validate_min from qiskit_nature.second_q.mappers import ( BravyiKitaevSuperFastMapper, diff --git a/qiskit_nature/second_q/drivers/pyscfd/pyscfdriver.py b/qiskit_nature/second_q/drivers/pyscfd/pyscfdriver.py index 7e02e35aa..4764c48ae 100644 --- a/qiskit_nature/second_q/drivers/pyscfd/pyscfdriver.py +++ b/qiskit_nature/second_q/drivers/pyscfd/pyscfdriver.py @@ -23,7 +23,7 @@ from typing import Any import numpy as np -from qiskit.utils.validation import validate_min +from qiskit_algorithms.utils.validation import validate_min from qiskit_nature.units import DistanceUnit from qiskit_nature.exceptions import QiskitNatureError diff --git a/qiskit_nature/second_q/mappers/qubit_mapper.py b/qiskit_nature/second_q/mappers/qubit_mapper.py index f2150ba96..42926671e 100644 --- a/qiskit_nature/second_q/mappers/qubit_mapper.py +++ b/qiskit_nature/second_q/mappers/qubit_mapper.py @@ -20,7 +20,7 @@ import numpy as np from qiskit.quantum_info.operators import Pauli, SparsePauliOp -from qiskit.algorithms.list_or_dict import ListOrDict as ListOrDictType +from qiskit_algorithms.list_or_dict import ListOrDict as ListOrDictType from qiskit_nature import QiskitNatureError from qiskit_nature.second_q.operators import SparseLabelOp diff --git a/qiskit_nature/second_q/mappers/tapered_qubit_mapper.py b/qiskit_nature/second_q/mappers/tapered_qubit_mapper.py index b6b89496c..ff550ed3b 100644 --- a/qiskit_nature/second_q/mappers/tapered_qubit_mapper.py +++ b/qiskit_nature/second_q/mappers/tapered_qubit_mapper.py @@ -17,7 +17,7 @@ import logging from typing import cast -from qiskit.algorithms.list_or_dict import ListOrDict as ListOrDictType +from qiskit_algorithms.list_or_dict import ListOrDict as ListOrDictType from qiskit.quantum_info.analysis.z2_symmetries import Z2Symmetries from qiskit.quantum_info.operators import SparsePauliOp diff --git a/qiskit_nature/second_q/problems/base_problem.py b/qiskit_nature/second_q/problems/base_problem.py index a9355a726..bd9d0d6dc 100644 --- a/qiskit_nature/second_q/problems/base_problem.py +++ b/qiskit_nature/second_q/problems/base_problem.py @@ -17,8 +17,7 @@ from typing import Callable import numpy as np -from qiskit.algorithms.eigensolvers import EigensolverResult -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolverResult +from qiskit_algorithms import EigensolverResult, MinimumEigensolverResult from qiskit.quantum_info.analysis.z2_symmetries import Z2Symmetries from qiskit_nature.second_q.mappers import QubitMapper, TaperedQubitMapper @@ -144,7 +143,7 @@ def get_default_filter_criterion( ) -> Callable[[list | np.ndarray, float, list[float] | None], bool] | None: """Returns a default filter criterion method to filter the eigenvalues computed by the eigen solver. For more information see also - qiskit.algorithms.eigen_solvers.NumPyEigensolver.filter_criterion. + :meth:`~qiskit_algorithms.NumPyEigensolver.filter_criterion`. In the fermionic case the default filter ensures that the number of particles is being preserved. diff --git a/qiskit_nature/second_q/problems/eigenstate_result.py b/qiskit_nature/second_q/problems/eigenstate_result.py index b157ca9d0..fd88aca77 100644 --- a/qiskit_nature/second_q/problems/eigenstate_result.py +++ b/qiskit_nature/second_q/problems/eigenstate_result.py @@ -18,10 +18,8 @@ import numpy as np -from qiskit.algorithms import AlgorithmResult -from qiskit.algorithms.eigensolvers import EigensolverResult -from qiskit.algorithms.list_or_dict import ListOrDict -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolverResult +from qiskit_algorithms import AlgorithmResult, EigensolverResult, MinimumEigensolverResult +from qiskit_algorithms.list_or_dict import ListOrDict from qiskit.circuit import QuantumCircuit from qiskit.quantum_info import Statevector @@ -87,11 +85,20 @@ def from_result( Returns: The constructed `EigenstateResult`. """ - if isinstance(raw_result, EigenstateResult): + # NOTE: the following inspection of class names is a work-around to handle backwards + # compatibility for the deprecated qiskit.algorithms module without delving into complex + # type unions. This logic can be removed once the qiskit.algorithms module no longer wants + # to be supported. + cls_names = {cls.__name__ for cls in raw_result.__class__.mro()} + + if isinstance(raw_result, EigenstateResult) or "EigenstateResult" in cls_names: return raw_result - if isinstance(raw_result, EigensolverResult): + if isinstance(raw_result, EigensolverResult) or "EigensolverResult" in cls_names: return EigenstateResult.from_eigensolver_result(raw_result) - if isinstance(raw_result, MinimumEigensolverResult): + if ( + isinstance(raw_result, MinimumEigensolverResult) + or "MinimumEigensolverResult" in cls_names + ): return EigenstateResult.from_minimum_eigensolver_result(raw_result) raise TypeError( f"Cannot construct an EigenstateResult from a result of type, {type(raw_result)}." @@ -100,7 +107,7 @@ def from_result( @classmethod def from_eigensolver_result(cls, raw_result: EigensolverResult) -> EigenstateResult: """Constructs an `EigenstateResult` from an - :class:`qiskit.algorithms.eigensolvers.EigensolverResult`. + :class:`~qiskit_algorithms.EigensolverResult`. Args: raw_result: the raw result from which to build the `EigenstateResult`. @@ -133,7 +140,7 @@ def from_minimum_eigensolver_result( cls, raw_result: MinimumEigensolverResult ) -> EigenstateResult: """Constructs an `EigenstateResult` from an - :class:`qiskit.algorithms.minimum_eigensolvers.MinimumEigensolverResult`. + :class:`~qiskit_algorithms.MinimumEigensolverResult`. Args: raw_result: the raw result from which to build the `EigenstateResult`. diff --git a/qiskit_nature/second_q/problems/electronic_structure_problem.py b/qiskit_nature/second_q/problems/electronic_structure_problem.py index e29bae96d..ac09271ab 100644 --- a/qiskit_nature/second_q/problems/electronic_structure_problem.py +++ b/qiskit_nature/second_q/problems/electronic_structure_problem.py @@ -19,8 +19,7 @@ import numpy as np -from qiskit.algorithms.eigensolvers import EigensolverResult -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolverResult +from qiskit_algorithms import EigensolverResult, MinimumEigensolverResult from qiskit.quantum_info.analysis.z2_symmetries import Z2Symmetries from qiskit_nature.exceptions import QiskitNatureError @@ -76,7 +75,7 @@ class ElectronicStructureProblem(BaseProblem): .. code-block:: python import numpy as np - from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver + from qiskit_algorithms import NumPyMinimumEigensolver expected_spin = 2 expected_num_electrons = 6 @@ -250,7 +249,7 @@ def get_default_filter_criterion( ) -> Optional[Callable[[Union[List, np.ndarray], float, Optional[List[float]]], bool]]: """Returns a default filter criterion method to filter the eigenvalues computed by the eigensolver. For more information see also - :class:`qiskit.algorithms.eigensolvers.NumPyEigensolver.filter_criterion`. + :meth:`~qiskit_algorithms.NumPyEigensolver.filter_criterion`. This particular default ensures that the total number of particles is conserved and that the angular momentum (if computed) evaluates to 0. diff --git a/qiskit_nature/second_q/problems/lattice_model_problem.py b/qiskit_nature/second_q/problems/lattice_model_problem.py index 788ae2461..cd8efa3bc 100644 --- a/qiskit_nature/second_q/problems/lattice_model_problem.py +++ b/qiskit_nature/second_q/problems/lattice_model_problem.py @@ -16,8 +16,7 @@ from typing import cast, Union -from qiskit.algorithms.eigensolvers import EigensolverResult -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolverResult +from qiskit_algorithms import EigensolverResult, MinimumEigensolverResult from qiskit_nature.second_q.hamiltonians import LatticeModel from qiskit_nature.second_q.properties import Interpretable diff --git a/qiskit_nature/second_q/problems/lattice_model_result.py b/qiskit_nature/second_q/problems/lattice_model_result.py index e3df05840..a872e08e9 100644 --- a/qiskit_nature/second_q/problems/lattice_model_result.py +++ b/qiskit_nature/second_q/problems/lattice_model_result.py @@ -16,7 +16,7 @@ import numpy as np -from qiskit.algorithms import AlgorithmResult +from qiskit_algorithms import AlgorithmResult from .eigenstate_result import EigenstateResult diff --git a/qiskit_nature/second_q/problems/vibrational_structure_problem.py b/qiskit_nature/second_q/problems/vibrational_structure_problem.py index e337dfc6a..8ef2bc7d0 100644 --- a/qiskit_nature/second_q/problems/vibrational_structure_problem.py +++ b/qiskit_nature/second_q/problems/vibrational_structure_problem.py @@ -19,8 +19,7 @@ import numpy as np -from qiskit.algorithms.eigensolvers import EigensolverResult -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolverResult +from qiskit_algorithms import EigensolverResult, MinimumEigensolverResult from qiskit_nature.second_q.hamiltonians import VibrationalEnergy from qiskit_nature.second_q.properties import Interpretable @@ -91,7 +90,7 @@ def get_default_filter_criterion( ) -> Optional[Callable[[Union[List, np.ndarray], float, Optional[List[float]]], bool]]: """Returns a default filter criterion method to filter the eigenvalues computed by the eigen solver. For more information see also - :class:`qiskit.algorithms.eigensolvers.NumPyEigensolver.filter_criterion`. + :meth:`~qiskit_algorithms.NumPyEigensolver.filter_criterion`. This particular default ensures that the occupation of every mode is (close to) 1. """ diff --git a/qiskit_nature/second_q/problems/vibrational_structure_result.py b/qiskit_nature/second_q/problems/vibrational_structure_result.py index 4b4d54668..8d0a09ec2 100644 --- a/qiskit_nature/second_q/problems/vibrational_structure_result.py +++ b/qiskit_nature/second_q/problems/vibrational_structure_result.py @@ -16,7 +16,7 @@ import numpy as np -from qiskit.algorithms import AlgorithmResult +from qiskit_algorithms import AlgorithmResult from .eigenstate_result import EigenstateResult diff --git a/requirements.txt b/requirements.txt index cb251a023..5e7530dd7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ qiskit>=0.44 +qiskit-algorithms>=0.2.1 scipy>=1.4 numpy>=1.17 psutil>=5 diff --git a/test/second_q/algorithms/excited_state_solvers/test_bosonic_esc_calculation.py b/test/second_q/algorithms/excited_state_solvers/test_bosonic_esc_calculation.py index ff21e32f0..8a63d2fbe 100644 --- a/test/second_q/algorithms/excited_state_solvers/test_bosonic_esc_calculation.py +++ b/test/second_q/algorithms/excited_state_solvers/test_bosonic_esc_calculation.py @@ -20,11 +20,10 @@ import numpy as np -from qiskit.algorithms.eigensolvers import NumPyEigensolver -from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver, VQE -from qiskit.algorithms.optimizers import COBYLA +from qiskit_algorithms import NumPyEigensolver, NumPyMinimumEigensolver, VQE +from qiskit_algorithms.optimizers import COBYLA +from qiskit_algorithms.utils import algorithm_globals from qiskit.primitives import Estimator -from qiskit.utils import algorithm_globals from qiskit_nature.second_q.algorithms import GroundStateEigensolver, QEOM, ExcitedStatesEigensolver from qiskit_nature.second_q.circuit.library import VSCF, UVCCSD diff --git a/test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers.py b/test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers.py index 2f7883af0..473671a8c 100644 --- a/test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers.py +++ b/test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers.py @@ -20,11 +20,10 @@ from ddt import ddt, named_data import numpy as np -from qiskit.algorithms.eigensolvers import NumPyEigensolver -from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver, VQE -from qiskit.algorithms.optimizers import SLSQP +from qiskit_algorithms import NumPyEigensolver, NumPyMinimumEigensolver, VQE +from qiskit_algorithms.optimizers import SLSQP +from qiskit_algorithms.utils import algorithm_globals from qiskit.primitives import Estimator -from qiskit.utils import algorithm_globals from qiskit_nature.units import DistanceUnit from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD diff --git a/test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers_auxiliaries.py b/test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers_auxiliaries.py index ba9b8686f..b7cd66369 100644 --- a/test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers_auxiliaries.py +++ b/test/second_q/algorithms/excited_state_solvers/test_excited_states_solvers_auxiliaries.py @@ -20,10 +20,10 @@ from ddt import ddt, named_data import numpy as np -from qiskit.algorithms.minimum_eigensolvers import VQE -from qiskit.algorithms.optimizers import SLSQP +from qiskit_algorithms import VQE +from qiskit_algorithms.optimizers import SLSQP +from qiskit_algorithms.utils import algorithm_globals from qiskit.primitives import Estimator -from qiskit.utils import algorithm_globals from qiskit_nature.units import DistanceUnit from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD diff --git a/test/second_q/algorithms/excited_state_solvers/test_qeom_electronic_ops.py b/test/second_q/algorithms/excited_state_solvers/test_qeom_electronic_ops.py index 9b98b31f5..3ee24664f 100644 --- a/test/second_q/algorithms/excited_state_solvers/test_qeom_electronic_ops.py +++ b/test/second_q/algorithms/excited_state_solvers/test_qeom_electronic_ops.py @@ -14,7 +14,7 @@ import unittest from test import QiskitNatureTestCase -from qiskit.utils import algorithm_globals +from qiskit_algorithms.utils import algorithm_globals from qiskit_nature.units import DistanceUnit from qiskit_nature.second_q.mappers import JordanWignerMapper, TaperedQubitMapper diff --git a/test/second_q/algorithms/excited_state_solvers/test_qeom_vibrational_ops.py b/test/second_q/algorithms/excited_state_solvers/test_qeom_vibrational_ops.py index 2ae80f163..546f0b662 100644 --- a/test/second_q/algorithms/excited_state_solvers/test_qeom_vibrational_ops.py +++ b/test/second_q/algorithms/excited_state_solvers/test_qeom_vibrational_ops.py @@ -16,7 +16,7 @@ import unittest -from qiskit.utils import algorithm_globals +from qiskit_algorithms.utils import algorithm_globals from qiskit_nature.second_q.algorithms.excited_states_solvers.qeom_vibrational_ops_builder import ( build_vibrational_ops, diff --git a/test/second_q/algorithms/ground_state_solvers/test_advanced_ucc_variants.py b/test/second_q/algorithms/ground_state_solvers/test_advanced_ucc_variants.py index 40428a731..747103465 100644 --- a/test/second_q/algorithms/ground_state_solvers/test_advanced_ucc_variants.py +++ b/test/second_q/algorithms/ground_state_solvers/test_advanced_ucc_variants.py @@ -16,11 +16,11 @@ from test import QiskitNatureTestCase -from qiskit.algorithms.minimum_eigensolvers import VQE -from qiskit.algorithms.optimizers import SLSQP +from qiskit_algorithms import VQE +from qiskit_algorithms.optimizers import SLSQP +from qiskit_algorithms.utils import algorithm_globals from qiskit.primitives import Estimator from qiskit.test import slow_test -from qiskit.utils import algorithm_globals from qiskit_nature.second_q.algorithms import GroundStateEigensolver from qiskit_nature.second_q.circuit.library import HartreeFock, SUCCD, PUCCD diff --git a/test/second_q/algorithms/ground_state_solvers/test_groundstate_eigensolver.py b/test/second_q/algorithms/ground_state_solvers/test_groundstate_eigensolver.py index abca34ee6..7b9543e37 100644 --- a/test/second_q/algorithms/ground_state_solvers/test_groundstate_eigensolver.py +++ b/test/second_q/algorithms/ground_state_solvers/test_groundstate_eigensolver.py @@ -21,11 +21,11 @@ import numpy as np -from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver, VQE -from qiskit.algorithms.optimizers import SLSQP, SPSA +from qiskit_algorithms import NumPyMinimumEigensolver, VQE +from qiskit_algorithms.optimizers import SLSQP, SPSA +from qiskit_algorithms.utils import algorithm_globals from qiskit.primitives import Estimator from qiskit.test import slow_test -from qiskit.utils import algorithm_globals import qiskit_nature.optionals as _optionals from qiskit_nature.second_q.algorithms import GroundStateEigensolver diff --git a/test/second_q/algorithms/ground_state_solvers/test_swaprz.py b/test/second_q/algorithms/ground_state_solvers/test_swaprz.py index 50069e141..f51fa5079 100644 --- a/test/second_q/algorithms/ground_state_solvers/test_swaprz.py +++ b/test/second_q/algorithms/ground_state_solvers/test_swaprz.py @@ -15,12 +15,12 @@ import unittest from test import QiskitNatureTestCase -from qiskit.algorithms.minimum_eigensolvers import VQE -from qiskit.algorithms.optimizers import SLSQP +from qiskit_algorithms import VQE +from qiskit_algorithms.optimizers import SLSQP +from qiskit_algorithms.utils import algorithm_globals from qiskit.primitives import Estimator from qiskit.circuit.library import ExcitationPreserving from qiskit.test import slow_test -from qiskit.utils import algorithm_globals import qiskit_nature.optionals as _optionals from qiskit_nature.second_q.algorithms import GroundStateEigensolver from qiskit_nature.second_q.circuit.library import HartreeFock diff --git a/test/second_q/circuit/library/ansatzes/test_chc.py b/test/second_q/circuit/library/ansatzes/test_chc.py index ae0d78848..a6020a603 100644 --- a/test/second_q/circuit/library/ansatzes/test_chc.py +++ b/test/second_q/circuit/library/ansatzes/test_chc.py @@ -17,10 +17,10 @@ from test import QiskitNatureTestCase from test.second_q.circuit.library.ansatzes.utils.vibrational_op_label_creator import _create_labels -from qiskit.utils import algorithm_globals -from qiskit.algorithms.minimum_eigensolvers import VQE -from qiskit.algorithms.optimizers import COBYLA from qiskit.primitives import Estimator +from qiskit_algorithms import VQE +from qiskit_algorithms.optimizers import COBYLA +from qiskit_algorithms.utils import algorithm_globals from qiskit_nature.second_q.circuit.library import CHC, VSCF from qiskit_nature.second_q.circuit.library.ansatzes.utils.vibration_excitation_generator import ( generate_vibration_excitations, diff --git a/test/second_q/circuit/library/ansatzes/test_uvcc.py b/test/second_q/circuit/library/ansatzes/test_uvcc.py index 40bfa3d4a..c39753c2a 100644 --- a/test/second_q/circuit/library/ansatzes/test_uvcc.py +++ b/test/second_q/circuit/library/ansatzes/test_uvcc.py @@ -20,10 +20,10 @@ from ddt import ddt, data, unpack from qiskit import transpile -from qiskit.utils import algorithm_globals -from qiskit.algorithms.minimum_eigensolvers import VQE -from qiskit.algorithms.optimizers import COBYLA from qiskit.primitives import Estimator +from qiskit_algorithms import VQE +from qiskit_algorithms.optimizers import COBYLA +from qiskit_algorithms.utils import algorithm_globals from qiskit_nature.second_q.circuit.library import UVCC, VSCF from qiskit_nature.second_q.mappers import DirectMapper from qiskit_nature.second_q.operators import VibrationalOp diff --git a/test/second_q/drivers/test_driver_methods_gsc.py b/test/second_q/drivers/test_driver_methods_gsc.py index ecce0e77c..77de68915 100644 --- a/test/second_q/drivers/test_driver_methods_gsc.py +++ b/test/second_q/drivers/test_driver_methods_gsc.py @@ -17,7 +17,7 @@ import unittest from test import QiskitNatureTestCase -from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver +from qiskit_algorithms import NumPyMinimumEigensolver from qiskit_nature.second_q.algorithms import GroundStateEigensolver from qiskit_nature.second_q.drivers import ElectronicStructureDriver from qiskit_nature.second_q.mappers import JordanWignerMapper, QubitMapper diff --git a/test/second_q/formats/fcidump/test_methods_fcidump.py b/test/second_q/formats/fcidump/test_methods_fcidump.py index fee45c65e..5adf3d9ba 100644 --- a/test/second_q/formats/fcidump/test_methods_fcidump.py +++ b/test/second_q/formats/fcidump/test_methods_fcidump.py @@ -17,7 +17,7 @@ from test.second_q.drivers.test_driver_methods_gsc import TestDriverMethods -from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver +from qiskit_algorithms import NumPyMinimumEigensolver from qiskit_nature.second_q.algorithms import GroundStateEigensolver from qiskit_nature.second_q.formats.fcidump_translator import fcidump_to_problem from qiskit_nature.second_q.formats.fcidump import FCIDump diff --git a/test/second_q/operators/test_symmetric_two_body.py b/test/second_q/operators/test_symmetric_two_body.py index f66e0ffd8..1a46b92ee 100644 --- a/test/second_q/operators/test_symmetric_two_body.py +++ b/test/second_q/operators/test_symmetric_two_body.py @@ -19,7 +19,7 @@ import numpy as np from ddt import data, ddt -from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver +from qiskit_algorithms import NumPyMinimumEigensolver import qiskit_nature.optionals as _optionals from qiskit_nature.second_q.algorithms import GroundStateEigensolver diff --git a/test/second_q/problems/test_electronic_structure_problem.py b/test/second_q/problems/test_electronic_structure_problem.py index b1959e456..eaa4962f8 100644 --- a/test/second_q/problems/test_electronic_structure_problem.py +++ b/test/second_q/problems/test_electronic_structure_problem.py @@ -17,7 +17,7 @@ import json import numpy as np -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolverResult +from qiskit_algorithms import MinimumEigensolverResult import qiskit_nature.optionals as _optionals from qiskit_nature.second_q.drivers import PySCFDriver diff --git a/test/second_q/problems/test_lattice_model_problem.py b/test/second_q/problems/test_lattice_model_problem.py index 5439cb28d..ef0a701c2 100644 --- a/test/second_q/problems/test_lattice_model_problem.py +++ b/test/second_q/problems/test_lattice_model_problem.py @@ -17,8 +17,7 @@ import numpy as np -from qiskit.algorithms.eigensolvers import EigensolverResult -from qiskit.algorithms.minimum_eigensolvers import MinimumEigensolverResult +from qiskit_algorithms import EigensolverResult, MinimumEigensolverResult from qiskit_nature.second_q.hamiltonians import FermiHubbardModel from qiskit_nature.second_q.problems import LatticeModelProblem from qiskit_nature.second_q.hamiltonians.lattices import ( diff --git a/test/second_q/properties/test_electronic_density.py b/test/second_q/properties/test_electronic_density.py index b23880bce..75bf048aa 100644 --- a/test/second_q/properties/test_electronic_density.py +++ b/test/second_q/properties/test_electronic_density.py @@ -21,7 +21,7 @@ import numpy as np from ddt import ddt, data, unpack -from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver +from qiskit_algorithms import NumPyMinimumEigensolver import qiskit_nature.optionals as _optionals diff --git a/test/test_end2end_with_vqe.py b/test/test_end2end_with_vqe.py index 6e7524573..859244965 100644 --- a/test/test_end2end_with_vqe.py +++ b/test/test_end2end_with_vqe.py @@ -16,11 +16,11 @@ from test import QiskitNatureTestCase -from qiskit.algorithms.minimum_eigensolvers import VQE -from qiskit.algorithms.optimizers import COBYLA +from qiskit_algorithms import VQE +from qiskit_algorithms.optimizers import COBYLA +from qiskit_algorithms.utils import algorithm_globals from qiskit.circuit.library import TwoLocal from qiskit.primitives import Estimator -from qiskit.utils import algorithm_globals import qiskit_nature.optionals as _optionals from qiskit_nature.second_q.drivers import PySCFDriver from qiskit_nature.second_q.mappers import ParityMapper