From e0753ff82b1aa6b2489938488dd2f6a81bccaeae Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Fri, 14 Apr 2023 17:19:45 +0200 Subject: [PATCH 1/6] Upgrade to Qiskit Nature 0.6.0 (cherry picked from commit 4ad204ff0de9c77ebfe98ffb16e8f8564da75698) # Conflicts: # requirements.txt --- .pylintdict | 3 +++ README.md | 40 +++++++++++++++++++++++----- docs/index.rst | 10 +++++++ qiskit_nature_pyscf/qiskit_solver.py | 31 +++++++++++++++------ requirements.txt | 6 +++++ test/test_qiskit_solver.py | 23 ++++++++-------- 6 files changed, 87 insertions(+), 26 deletions(-) diff --git a/.pylintdict b/.pylintdict index 98f03d9..ee37094 100644 --- a/.pylintdict +++ b/.pylintdict @@ -1,3 +1,4 @@ +ansatz args autosummary bool @@ -18,6 +19,8 @@ kwargs makefile mcscf mol +nalpha +nbeta ndarray nelec norb diff --git a/README.md b/README.md index 3bf42d2..9660760 100644 --- a/README.md +++ b/README.md @@ -35,11 +35,14 @@ Below we show a simple example of how to do this. ```python from pyscf import gto, scf, mcscf +import numpy as np + +from qiskit.algorithms.minimum_eigensolvers import VQE from qiskit.algorithms.optimizers import SLSQP from qiskit.primitives import Estimator -from qiskit_nature.second_q.algorithms import GroundStateEigensolver, VQEUCCFactory -from qiskit_nature.second_q.circuit.library import UCCSD -from qiskit_nature.second_q.mappers import ParityMapper, QubitConverter +from qiskit_nature.second_q.algorithms import GroundStateEigensolver +from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD +from qiskit_nature.second_q.mappers import ParityMapper from qiskit_nature_pyscf import QiskitSolver @@ -47,15 +50,29 @@ mol = gto.M(atom="Li 0 0 0; H 0 0 1.6", basis="sto-3g") h_f = scf.RHF(mol).run() -norb, nelec = 2, 2 +norb = 2 +nalpha, nbeta = 1, 1 +nelec = nalpha + nbeta cas = mcscf.CASCI(h_f, norb, nelec) -converter = QubitConverter(ParityMapper(), two_qubit_reduction=True) +mapper = ParityMapper(num_particles=(nalpha, nbeta)) + +ansatz = UCCSD( + norb, + (nalpha, nbeta), + mapper, + initial_state=HartreeFock( + norb, + (nalpha, nbeta), + mapper, + ), +) -vqe = VQEUCCFactory(Estimator(), UCCSD(), SLSQP()) +vqe = VQE(Estimator(), ansatz, SLSQP()) +vqe.initial_point = np.zeros(ansatz.num_parameters) -algorithm = GroundStateEigensolver(converter, vqe) +algorithm = GroundStateEigensolver(mapper, vqe) cas.fcisolver = QiskitSolver(algorithm) @@ -66,3 +83,12 @@ More detailed documentation can be found at [Documentation](https://qiskit-community.github.io/qiskit-nature-pyscf/). For more detailed explanations we recommend to check out the documentation of [PySCF](https://pyscf.org/) and [Qiskit Nature](https://qiskit.org/documentation/nature/). + + +## Citation + +If you use this plugin, please cite the following references: + +- PySCF, as per [these instructions](https://github.com/pyscf/pyscf#citing-pyscf). +- Qiskit, as per the provided [BibTeX file](https://github.com/Qiskit/qiskit/blob/master/Qiskit.bib). +- Qiskit Nature, as per https://doi.org/10.5281/zenodo.7828767 diff --git a/docs/index.rst b/docs/index.rst index faa96a2..9aa737e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -9,6 +9,16 @@ Overview To get started we suggest looking at the README on Github ``_. +Citation +======== + +If you use this plugin, please cite the following references: + +- PySCF, as per `these instructions `_. +- Qiskit, as per the provided `BibTeX file `_. +- Qiskit Nature, as per https://doi.org/10.5281/zenodo.7828767 + + Next Steps ================================= diff --git a/qiskit_nature_pyscf/qiskit_solver.py b/qiskit_nature_pyscf/qiskit_solver.py index 044433e..a1d6605 100644 --- a/qiskit_nature_pyscf/qiskit_solver.py +++ b/qiskit_nature_pyscf/qiskit_solver.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2022. +# (C) Copyright IBM 2022, 2023. # # 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 @@ -49,11 +49,12 @@ class QiskitSolver: from pyscf import gto, scf, mcscf + from qiskit.algorithms.minimum_eigensolvers import VQE from qiskit.algorithms.optimizers import SLSQP from qiskit.primitives import Estimator - from qiskit_nature.second_q.algorithms import GroundStateEigensolver, VQEUCCFactory - from qiskit_nature.second_q.circuit.library import UCCSD - from qiskit_nature.second_q.mappers import ParityMapper, QubitConverter + from qiskit_nature.second_q.algorithms import GroundStateEigensolver + from qiskit_nature.second_q.circuit.library import HartreeFock, UCCSD + from qiskit_nature.second_q.mappers import ParityMapper from qiskit_nature_pyscf import QiskitSolver @@ -61,15 +62,29 @@ class QiskitSolver: h_f = scf.RHF(mol).run() - norb, nelec = 2, 2 + norb = 2 + nalpha, nbeta = 1, 1 + nelec = nalpha + nbeta cas = mcscf.CASCI(h_f, norb, nelec) - converter = QubitConverter(ParityMapper(), two_qubit_reduction=True) + mapper = ParityMapper(num_particles=(nalpha, nbeta)) + + ansatz = UCCSD( + norb, + (nalpha, nbeta), + mapper, + initial_state=HartreeFock( + norb, + (nalpha, nbeta), + mapper, + ), + ) - vqe = VQEUCCFactory(Estimator(), UCCSD(), SLSQP()) + vqe = VQE(Estimator(), ansatz, SLSQP()) + vqe.initial_point = np.zeros(ansatz.num_parameters) - algorithm = GroundStateEigensolver(converter, vqe) + algorithm = GroundStateEigensolver(mapper, vqe) cas.fcisolver = QiskitSolver(algorithm) diff --git a/requirements.txt b/requirements.txt index 5f1a8e5..7d2a5f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,9 @@ +<<<<<<< HEAD qiskit-nature>=0.5.* pyscf>=2.0.* setuptools>=40.1.0,<=65.5.1 +======= +qiskit-nature>=0.6 +pyscf>=2.0 +setuptools>=40.1.0 +>>>>>>> 4ad204f (Upgrade to Qiskit Nature 0.6.0) diff --git a/test/test_qiskit_solver.py b/test/test_qiskit_solver.py index 7ad321b..d3e16de 100644 --- a/test/test_qiskit_solver.py +++ b/test/test_qiskit_solver.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2022. +# (C) Copyright IBM 2022, 2023. # # 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 @@ -16,8 +16,9 @@ from pyscf import gto, scf, mcscf -from qiskit_nature.second_q.algorithms import GroundStateEigensolver, NumPyMinimumEigensolverFactory -from qiskit_nature.second_q.mappers import JordanWignerMapper, QubitConverter +from qiskit.algorithms.minimum_eigensolvers import NumPyMinimumEigensolver +from qiskit_nature.second_q.algorithms import GroundStateEigensolver +from qiskit_nature.second_q.mappers import JordanWignerMapper from qiskit_nature_pyscf.qiskit_solver import QiskitSolver @@ -37,8 +38,8 @@ def test_rhf_casci_h2(self): qcas = mcscf.CASCI(h_f, norb, nelec) ground_state_solver = GroundStateEigensolver( - QubitConverter(JordanWignerMapper()), - NumPyMinimumEigensolverFactory(), + JordanWignerMapper(), + NumPyMinimumEigensolver(), ) qcas.fcisolver = QiskitSolver(ground_state_solver) @@ -60,8 +61,8 @@ def test_uhf_ucasci_h2(self): qcas = mcscf.UCASCI(h_f, norb, nelec) ground_state_solver = GroundStateEigensolver( - QubitConverter(JordanWignerMapper()), - NumPyMinimumEigensolverFactory(), + JordanWignerMapper(), + NumPyMinimumEigensolver(), ) qcas.fcisolver = QiskitSolver(ground_state_solver) @@ -83,8 +84,8 @@ def test_rhf_casscf_h2(self): qcas = mcscf.CASSCF(h_f, norb, nelec) ground_state_solver = GroundStateEigensolver( - QubitConverter(JordanWignerMapper()), - NumPyMinimumEigensolverFactory(), + JordanWignerMapper(), + NumPyMinimumEigensolver(), ) qcas.fcisolver = QiskitSolver(ground_state_solver) @@ -106,8 +107,8 @@ def test_uhf_ucasscf_h2(self): qcas = mcscf.UCASSCF(h_f, norb, nelec) ground_state_solver = GroundStateEigensolver( - QubitConverter(JordanWignerMapper()), - NumPyMinimumEigensolverFactory(), + JordanWignerMapper(), + NumPyMinimumEigensolver(), ) qcas.fcisolver = QiskitSolver(ground_state_solver) From b29e154fe07fa6ba4947024d6d9b6b0d3aa25567 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 26 Apr 2023 15:42:41 -0400 Subject: [PATCH 2/6] Update the intersphinx mapping URL for Qiskit Nature (cherry picked from commit 2a307eb82895b38a5c01bf78d0712e9bda50b774) --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index faddaa4..80e6cfe 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -210,7 +210,7 @@ "python": ("https://docs.python.org/3", None), "numpy": ("https://numpy.org/doc/stable", None), "scipy": ("https://docs.scipy.org/doc/scipy", None), - "qiskit_nature": ("https://qiskit.org/documentation/nature", None), + "qiskit_nature": ("https://qiskit.org/ecosystem/nature", None), "qiskit": ("https://qiskit.org/documentation", None), } From 3fa63349a506e1d7876bd9b116bc8347e49ef996 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 26 Apr 2023 15:45:15 -0400 Subject: [PATCH 3/6] Add release note (cherry picked from commit 972475a967454f8b69b95a595adcb1d67dc289dd) --- ...mpatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 releasenotes/notes/compatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml diff --git a/releasenotes/notes/compatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml b/releasenotes/notes/compatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml new file mode 100644 index 0000000..245ac79 --- /dev/null +++ b/releasenotes/notes/compatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml @@ -0,0 +1,6 @@ +--- +upgrade: + - | + You can upgrade your code to use Qiskit Nature 0.6 without needing to change + anything regarding this plugin. The examples have been updated to reflect + the newer 0.6 API of Qiskit Nature. From 6398c60b3947e8fe915afb09e6616c886ad1474f Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 26 Apr 2023 15:54:54 -0400 Subject: [PATCH 4/6] Fix copyright (cherry picked from commit 8bbcb793359a36f999eb7aa18d77005b39d4a8ec) --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 80e6cfe..da64a4b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2022. +# (C) Copyright IBM 2022, 2023. # # 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 From e366873c4b3bd087c439f585e7118ab77983150a Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 26 Apr 2023 16:11:45 -0400 Subject: [PATCH 5/6] Update reno (cherry picked from commit cf575372fc261791478a894b15aa637a275479db) --- ...atibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/releasenotes/notes/compatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml b/releasenotes/notes/compatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml index 245ac79..c0af57e 100644 --- a/releasenotes/notes/compatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml +++ b/releasenotes/notes/compatibility-with-qiskit-nature-0.6-7f1189fe41833678.yaml @@ -1,6 +1,6 @@ --- -upgrade: +fixes: - | - You can upgrade your code to use Qiskit Nature 0.6 without needing to change - anything regarding this plugin. The examples have been updated to reflect - the newer 0.6 API of Qiskit Nature. + Ensures compatibility of this plugin with Qiskit Nature 0.6. + The examples are updated in order to avoid triggering deprecation warnings. + Using Qiskit Nature 0.5 is still supported. From 598d5a60c01c1dc7393a3f0f499272cce0fb6fe2 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 26 Apr 2023 17:10:34 -0400 Subject: [PATCH 6/6] Update requirements.txt --- requirements.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7d2a5f9..b0afc69 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,3 @@ -<<<<<<< HEAD -qiskit-nature>=0.5.* -pyscf>=2.0.* -setuptools>=40.1.0,<=65.5.1 -======= qiskit-nature>=0.6 pyscf>=2.0 setuptools>=40.1.0 ->>>>>>> 4ad204f (Upgrade to Qiskit Nature 0.6.0)