Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Qiskit Nature 0.6.0 (backport #24) #26

Merged
merged 6 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ansatz
args
autosummary
bool
Expand All @@ -18,6 +19,8 @@ kwargs
makefile
mcscf
mol
nalpha
nbeta
ndarray
nelec
norb
Expand Down
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,44 @@ 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

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)

Expand All @@ -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
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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),
}

Expand Down
10 changes: 10 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Overview
To get started we suggest looking at the README on Github `<https://github.com/qiskit-community/qiskit-nature-pyscf/blob/main/README.md>`_.


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


Next Steps
=================================

Expand Down
31 changes: 23 additions & 8 deletions qiskit_nature_pyscf/qiskit_solver.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -49,27 +49,42 @@ 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

mol = gto.M(atom="Li 0 0 0; H 0 0 1.51", basis="631g*")

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)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
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.
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
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
23 changes: 12 additions & 11 deletions test/test_qiskit_solver.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down