From 82cd8a13bbfd24bf6dd5fb26878c724f7d2450ba Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Mon, 5 Jun 2023 10:07:58 +0200 Subject: [PATCH 1/7] feat: add the PySCFGroundStateSolver --- .pylintdict | 3 + qiskit_nature_pyscf/__init__.py | 5 +- .../pyscf_ground_state_solver.py | 201 ++++++++++++++++++ ...-ground-state-solver-6a7866e29ca659f6.yaml | 31 +++ test/test_pyscf_ground_state_solver.py | 65 ++++++ 5 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 qiskit_nature_pyscf/pyscf_ground_state_solver.py create mode 100644 releasenotes/notes/feat-pyscf-ground-state-solver-6a7866e29ca659f6.yaml create mode 100644 test/test_pyscf_ground_state_solver.py diff --git a/.pylintdict b/.pylintdict index ee37094..55e56cb 100644 --- a/.pylintdict +++ b/.pylintdict @@ -7,6 +7,7 @@ ci currentmodule dicts ecore +eigensolver fci fcisolver filename @@ -17,6 +18,7 @@ hamiltonian https kwargs makefile +methodtype mcscf mol nalpha @@ -32,6 +34,7 @@ py pyscf qiskit qiskit's +qubit readme reinstall rhf diff --git a/qiskit_nature_pyscf/__init__.py b/qiskit_nature_pyscf/__init__.py index de38ffa..5eb8544 100644 --- a/qiskit_nature_pyscf/__init__.py +++ b/qiskit_nature_pyscf/__init__.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 @@ -21,12 +21,15 @@ :nosignatures: QiskitSolver + PySCFGroundStateSolver """ from .qiskit_solver import QiskitSolver +from .pyscf_ground_state_solver import PySCFGroundStateSolver from .version import __version__ __all__ = [ "QiskitSolver", + "PySCFGroundStateSolver", "__version__", ] diff --git a/qiskit_nature_pyscf/pyscf_ground_state_solver.py b/qiskit_nature_pyscf/pyscf_ground_state_solver.py new file mode 100644 index 0000000..66f875d --- /dev/null +++ b/qiskit_nature_pyscf/pyscf_ground_state_solver.py @@ -0,0 +1,201 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 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 +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""A PySCF-based GroundStateSolver for Qiskit Nature.""" + +from __future__ import annotations + +import logging + +import numpy as np +from pyscf import fci +from qiskit.quantum_info import SparsePauliOp +from qiskit_nature.second_q.algorithms import GroundStateSolver +from qiskit_nature.second_q.operators import SparseLabelOp +from qiskit_nature.second_q.operators.tensor_ordering import IndexType, to_chemist_ordering +from qiskit_nature.second_q.problems import ( + BaseProblem, + ElectronicStructureProblem, + ElectronicStructureResult, +) +from qiskit_nature.second_q.properties import ElectronicDensity + +LOGGER = logging.getLogger(__name__) + + +class PySCFGroundStateSolver(GroundStateSolver): + """A PySCF-based GroundStateSolver for Qiskit Nature. + + This class provides a ``GroundStateSolver`` for Qiskit Nature, leveraging the ``fci`` module of + PySCF. This is utility does not enable any Quantum algorithms to be used (since it replaces them + in the Qiskit workflow) but instead provides a useful utility for debugging classical + computational workflows based on Qiskit Nature. + More importantly, it provides a more efficient implementation of what Qiskit otherwise achieves + using a ``NumPyMinimumEigensolver`` in combination with a ``filter_criterion``. For non-singlet + spin ground states the setup using Qiskit components is a lot more involved, whereas this class + provides an easy-to-use alternative. + + Here is an example use cas: + + .. code-block:: python + + from pyscf import fci + + from qiskit_nature.second_q.drivers import MethodType, PySCFDriver + from qiskit_nature.second_q.transformers import ActiveSpaceTransformer + + from qiskit_nature_pyscf import PySCFGroundStateSolver + + driver = PySCFDriver( + atom="O 0.0 0.0 0.0; O 0.0 0.0 1.5", + basis="sto3g", + spin=2, + method=MethodType.UHF, + ) + problem = driver.run() + + transformer = ActiveSpaceTransformer(4, 4) + + problem = transformer.transform(problem) + + solver = PySCFGroundStateSolver(fci.direct_uhf.FCI()) + + result = solver.solve(problem) + print(result) + + For more details please to the documentation of [PySCF](https://pyscf.org/) and + [Qiskit Nature](https://qiskit.org/documentation/nature/). + """ + + def __init__(self, solver: fci.direct_spin1.FCISolver) -> None: + """ + Args: + solver: a FCI solver provided by PySCF. + """ + super().__init__(None) + self._solver = solver + + def solve( + self, + problem: BaseProblem, + aux_operators: dict[str, SparseLabelOp | SparsePauliOp] | None = None, + ) -> ElectronicStructureResult: + """Finds the ground-state of the provided problem. + + This method is written to match the ``GroundStateSolver`` API of Qiskit Nature but it does + not support the evaluation of ``aux_operators`` and will ignore them. + It is also only capable of solving an ``ElectronicStructureProblem`` and will raise an error + if another problem object is provided. + + Args: + problem: the problem instance to be solved. + aux_operators: **ignored**. + + Raises: + RuntimeError: if a problem other than an ``ElectronicStructureProblem`` is provided. + + Returns: + The interpreted result object in Qiskit Nature format. + """ + if aux_operators is not None: + LOGGER.warning("Ignored.") + + if not isinstance(problem, ElectronicStructureProblem): + raise RuntimeError("Unsupported problem type.") + + e_ints = problem.hamiltonian.electronic_integrals + + restricted_spin = e_ints.beta_alpha.is_empty() + + one_body: np.ndarray + two_body: np.ndarray + + if restricted_spin: + one_body = np.asarray(problem.hamiltonian.electronic_integrals.alpha["+-"]) + two_body = np.asarray( + to_chemist_ordering( + problem.hamiltonian.electronic_integrals.alpha["++--"], + index_order=IndexType.PHYSICIST, + ) + ) + else: + one_body = np.asarray( + [ + problem.hamiltonian.electronic_integrals.alpha["+-"], + problem.hamiltonian.electronic_integrals.beta["+-"], + ] + ) + two_body = np.asarray( + [ + to_chemist_ordering( + problem.hamiltonian.electronic_integrals.alpha["++--"], + index_order=IndexType.PHYSICIST, + ), + to_chemist_ordering( + problem.hamiltonian.electronic_integrals.alpha_beta["++--"], + index_order=IndexType.PHYSICIST, + ), + to_chemist_ordering( + problem.hamiltonian.electronic_integrals.beta["++--"], + index_order=IndexType.PHYSICIST, + ), + ] + ) + + energy, ci_vec = self.solver.kernel( + h1e=one_body, + eri=two_body, + norb=problem.num_spatial_orbitals, + nelec=problem.num_particles, + ) + + _, multiplicity = fci.spin_square( + ci_vec, norb=problem.num_spatial_orbitals, nelec=problem.num_particles + ) + + density: ElectronicDensity + if restricted_spin: + raw_density = self.solver.make_rdm1( + ci_vec, norb=problem.num_spatial_orbitals, nelec=problem.num_particles + ) + density = ElectronicDensity.from_raw_integrals(raw_density) + else: + raw_density = self.solver.make_rdm1s( + ci_vec, norb=problem.num_spatial_orbitals, nelec=problem.num_particles + ) + density = ElectronicDensity.from_raw_integrals(raw_density[0], h1_b=raw_density[1]) + + result = ElectronicStructureResult() + result.computed_energies = np.asarray([energy]) + result.hartree_fock_energy = problem.reference_energy + result.extracted_transformer_energies = dict(problem.hamiltonian.constants.items()) + result.nuclear_repulsion_energy = result.extracted_transformer_energies.pop( + "nuclear_repulsion_energy", None + ) + result.num_particles = [sum(problem.num_particles)] + result.magnetization = [0.5 * (problem.num_alpha - problem.num_beta)] + result.total_angular_momentum = [0.25 * (multiplicity**2 - 1)] + result.electronic_density = density + + return result + + get_qubit_operators = None + """This class does not deal with qubit operators.""" + + def supports_aux_operators(self) -> bool: + """Returns whether the eigensolver supports auxiliary operators.""" + return False + + @property + def solver(self): + """Returns the solver.""" + return self._solver diff --git a/releasenotes/notes/feat-pyscf-ground-state-solver-6a7866e29ca659f6.yaml b/releasenotes/notes/feat-pyscf-ground-state-solver-6a7866e29ca659f6.yaml new file mode 100644 index 0000000..c84a1d9 --- /dev/null +++ b/releasenotes/notes/feat-pyscf-ground-state-solver-6a7866e29ca659f6.yaml @@ -0,0 +1,31 @@ +--- +features: + - | + Adds the :class:`.PySCFGroundStateSolver` to provide simpler means for testing and debugging + classical computational workflows in Qiskit Nature. Below is an example of how to use it: + + .. code-block:: python + + from pyscf import fci + + from qiskit_nature.second_q.drivers import MethodType, PySCFDriver + from qiskit_nature.second_q.transformers import ActiveSpaceTransformer + + from qiskit_nature_pyscf import PySCFGroundStateSolver + + driver = PySCFDriver( + atom="O 0.0 0.0 0.0; O 0.0 0.0 1.5", + basis="sto3g", + spin=2, + method=MethodType.UHF, + ) + problem = driver.run() + + transformer = ActiveSpaceTransformer(4, 4) + + problem = transformer.transform(problem) + + solver = PySCFGroundStateSolver(fci.direct_uhf.FCI()) + + result = solver.solve(problem) + print(result) diff --git a/test/test_pyscf_ground_state_solver.py b/test/test_pyscf_ground_state_solver.py new file mode 100644 index 0000000..a459146 --- /dev/null +++ b/test/test_pyscf_ground_state_solver.py @@ -0,0 +1,65 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 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 +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +"""Tests for the PySCFGroundStateSolver.""" + +from test import QiskitNaturePySCFTestCase + +from pyscf import mcscf, fci +from qiskit_nature.second_q.drivers import MethodType, PySCFDriver +from qiskit_nature.second_q.transformers import ActiveSpaceTransformer + +from qiskit_nature_pyscf import PySCFGroundStateSolver + + +class TestPySCFGroundStateSolver(QiskitNaturePySCFTestCase): + """Tests for the PySCFGroundStateSolver.""" + + def test_direct_spin1_fci(self): + """Test with the ``fci.direct_spin1.FCISolver``.""" + driver = PySCFDriver( + atom="H 0.0 0.0 0.0; H 0.0 0.0 1.5", + basis="sto3g", + ) + problem = driver.run() + + solver = PySCFGroundStateSolver(fci.direct_spin1.FCI()) + + result = solver.solve(problem) + + casci = mcscf.CASCI(driver._calc, 2, 2) + casci.run() + + self.assertAlmostEqual(casci.e_tot, result.total_energies[0]) + + def test_direct_uhf_fci(self): + """Test with the ``fci.direct_uhf.FCISolver``.""" + driver = PySCFDriver( + atom="O 0.0 0.0 0.0; O 0.0 0.0 1.5", + basis="sto3g", + spin=2, + method=MethodType.UHF, + ) + problem = driver.run() + + transformer = ActiveSpaceTransformer(4, 4) + + problem = transformer.transform(problem) + + solver = PySCFGroundStateSolver(fci.direct_uhf.FCI()) + + result = solver.solve(problem) + + casci = mcscf.UCASCI(driver._calc, 4, 4) + casci.run() + + self.assertAlmostEqual(casci.e_tot, result.total_energies[0]) From 29f2ce46491e90e11e74c347b93500ce412b65e1 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Mon, 5 Jun 2023 14:06:48 +0200 Subject: [PATCH 2/7] Set spin squared directly --- qiskit_nature_pyscf/pyscf_ground_state_solver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_nature_pyscf/pyscf_ground_state_solver.py b/qiskit_nature_pyscf/pyscf_ground_state_solver.py index 66f875d..998375b 100644 --- a/qiskit_nature_pyscf/pyscf_ground_state_solver.py +++ b/qiskit_nature_pyscf/pyscf_ground_state_solver.py @@ -158,7 +158,7 @@ def solve( nelec=problem.num_particles, ) - _, multiplicity = fci.spin_square( + spin_square, _ = fci.spin_square( ci_vec, norb=problem.num_spatial_orbitals, nelec=problem.num_particles ) @@ -183,7 +183,7 @@ def solve( ) result.num_particles = [sum(problem.num_particles)] result.magnetization = [0.5 * (problem.num_alpha - problem.num_beta)] - result.total_angular_momentum = [0.25 * (multiplicity**2 - 1)] + result.total_angular_momentum = [spin_square] result.electronic_density = density return result From ca2ef0b380d63afd6067fe6694b7e840d5f693b3 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 7 Jun 2023 14:38:36 +0200 Subject: [PATCH 3/7] fix: do not hard-code physicist integral order --- qiskit_nature_pyscf/pyscf_ground_state_solver.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/qiskit_nature_pyscf/pyscf_ground_state_solver.py b/qiskit_nature_pyscf/pyscf_ground_state_solver.py index 998375b..ebd52ba 100644 --- a/qiskit_nature_pyscf/pyscf_ground_state_solver.py +++ b/qiskit_nature_pyscf/pyscf_ground_state_solver.py @@ -21,7 +21,11 @@ from qiskit.quantum_info import SparsePauliOp from qiskit_nature.second_q.algorithms import GroundStateSolver from qiskit_nature.second_q.operators import SparseLabelOp -from qiskit_nature.second_q.operators.tensor_ordering import IndexType, to_chemist_ordering +from qiskit_nature.second_q.operators.tensor_ordering import ( + IndexType, + find_index_order, + to_chemist_ordering, +) from qiskit_nature.second_q.problems import ( BaseProblem, ElectronicStructureProblem, @@ -124,7 +128,6 @@ def solve( two_body = np.asarray( to_chemist_ordering( problem.hamiltonian.electronic_integrals.alpha["++--"], - index_order=IndexType.PHYSICIST, ) ) else: @@ -134,19 +137,20 @@ def solve( problem.hamiltonian.electronic_integrals.beta["+-"], ] ) + index_order = find_index_order(problem.hamiltonian.electronic_integrals.alpha["++--"]) two_body = np.asarray( [ to_chemist_ordering( problem.hamiltonian.electronic_integrals.alpha["++--"], - index_order=IndexType.PHYSICIST, + index_order=index_order, ), to_chemist_ordering( problem.hamiltonian.electronic_integrals.alpha_beta["++--"], - index_order=IndexType.PHYSICIST, + index_order=index_order, ), to_chemist_ordering( problem.hamiltonian.electronic_integrals.beta["++--"], - index_order=IndexType.PHYSICIST, + index_order=index_order, ), ] ) From fe95e0c0c2c1a4c1ca360d06c9f7a85ee2a18364 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 7 Jun 2023 14:56:18 +0200 Subject: [PATCH 4/7] fix: lint --- qiskit_nature_pyscf/pyscf_ground_state_solver.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/qiskit_nature_pyscf/pyscf_ground_state_solver.py b/qiskit_nature_pyscf/pyscf_ground_state_solver.py index ebd52ba..a2b29a2 100644 --- a/qiskit_nature_pyscf/pyscf_ground_state_solver.py +++ b/qiskit_nature_pyscf/pyscf_ground_state_solver.py @@ -21,11 +21,7 @@ from qiskit.quantum_info import SparsePauliOp from qiskit_nature.second_q.algorithms import GroundStateSolver from qiskit_nature.second_q.operators import SparseLabelOp -from qiskit_nature.second_q.operators.tensor_ordering import ( - IndexType, - find_index_order, - to_chemist_ordering, -) +from qiskit_nature.second_q.operators.tensor_ordering import find_index_order, to_chemist_ordering from qiskit_nature.second_q.problems import ( BaseProblem, ElectronicStructureProblem, From a35beb279978ddfba0dd98ad1cb6e42449ecf501 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Thu, 8 Jun 2023 18:57:39 +0200 Subject: [PATCH 5/7] Apply changes based on review --- .../pyscf_ground_state_solver.py | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/qiskit_nature_pyscf/pyscf_ground_state_solver.py b/qiskit_nature_pyscf/pyscf_ground_state_solver.py index a2b29a2..0814e03 100644 --- a/qiskit_nature_pyscf/pyscf_ground_state_solver.py +++ b/qiskit_nature_pyscf/pyscf_ground_state_solver.py @@ -18,6 +18,7 @@ import numpy as np from pyscf import fci +from qiskit.opflow import PauliSumOp from qiskit.quantum_info import SparsePauliOp from qiskit_nature.second_q.algorithms import GroundStateSolver from qiskit_nature.second_q.operators import SparseLabelOp @@ -35,14 +36,14 @@ class PySCFGroundStateSolver(GroundStateSolver): """A PySCF-based GroundStateSolver for Qiskit Nature. - This class provides a ``GroundStateSolver`` for Qiskit Nature, leveraging the ``fci`` module of - PySCF. This is utility does not enable any Quantum algorithms to be used (since it replaces them - in the Qiskit workflow) but instead provides a useful utility for debugging classical - computational workflows based on Qiskit Nature. + This class provides a :class:`~qiskit_nature.second_q.algorithms.GroundStateSolver` for Qiskit + Nature, leveraging the ``fci`` module of PySCF. This is utility does not enable any Quantum + algorithms to be used (since it replaces them in the Qiskit workflow) but instead provides a + useful utility for debugging classical computational workflows based on Qiskit Nature. More importantly, it provides a more efficient implementation of what Qiskit otherwise achieves - using a ``NumPyMinimumEigensolver`` in combination with a ``filter_criterion``. For non-singlet - spin ground states the setup using Qiskit components is a lot more involved, whereas this class - provides an easy-to-use alternative. + using a :class:`~qiskit.algorithms.minimum_eigensolvers.NumPyMinimumEigensolver` in combination + with a ``filter_criterion``. For non-singlet spin ground states the setup using Qiskit + components is a lot more involved, whereas this class provides an easy-to-use alternative. Here is an example use cas: @@ -73,7 +74,7 @@ class PySCFGroundStateSolver(GroundStateSolver): print(result) For more details please to the documentation of [PySCF](https://pyscf.org/) and - [Qiskit Nature](https://qiskit.org/documentation/nature/). + [Qiskit Nature](https://qiskit.org/ecosystem/nature/). """ def __init__(self, solver: fci.direct_spin1.FCISolver) -> None: @@ -91,9 +92,11 @@ def solve( ) -> ElectronicStructureResult: """Finds the ground-state of the provided problem. - This method is written to match the ``GroundStateSolver`` API of Qiskit Nature but it does - not support the evaluation of ``aux_operators`` and will ignore them. - It is also only capable of solving an ``ElectronicStructureProblem`` and will raise an error + This method is written to match the + :class:`~qiskit_nature.second_q.algorithms.GroundStateSolver` API of Qiskit Nature but it + does not support the evaluation of ``aux_operators`` and will ignore them. + It is also only capable of solving an + :class:`~qiskit_nature.second_q.problems.ElectronicStructureProblem` and will raise an error if another problem object is provided. Args: @@ -101,16 +104,22 @@ def solve( aux_operators: **ignored**. Raises: - RuntimeError: if a problem other than an ``ElectronicStructureProblem`` is provided. + TypeError: if a problem other than an + :class:`~qiskit_nature.second_q.problems.ElectronicStructureProblem` is provided. Returns: The interpreted result object in Qiskit Nature format. """ if aux_operators is not None: - LOGGER.warning("Ignored.") + LOGGER.warning( + "This solver does not support auxiliary operators. They will be ignored." + ) if not isinstance(problem, ElectronicStructureProblem): - raise RuntimeError("Unsupported problem type.") + raise TypeError( + "This solver only supports an ElectronicStructureProblem but you provided a " + f"problem of type '{type(problem)}'." + ) e_ints = problem.hamiltonian.electronic_integrals @@ -188,14 +197,23 @@ def solve( return result - get_qubit_operators = None - """This class does not deal with qubit operators.""" + def get_qubit_operators( + self, + problem: BaseProblem, + aux_operators: dict[str, SparseLabelOp | SparsePauliOp | PauliSumOp] | None = None, + ) -> tuple[SparsePauliOp | PauliSumOp, dict[str, SparsePauliOp | PauliSumOp] | None]: + """This solver does not deal with qubit operators and this method raises a RuntimeError.""" + raise RuntimeError( + "This solver is a purely classical one and as such solves an ElectronicStructureProblem" + " on the second-quantization level. Thus, it has no concept of qubit operators and does" + " not support this method." + ) def supports_aux_operators(self) -> bool: """Returns whether the eigensolver supports auxiliary operators.""" return False @property - def solver(self): + def solver(self) -> fci.direct_spin1.FCISolver: """Returns the solver.""" return self._solver From 24ee9fc2307da8b41eaf859aa450f285a24428a4 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Fri, 9 Jun 2023 09:07:48 +0200 Subject: [PATCH 6/7] fix: remove PauliSumOp from type hint --- qiskit_nature_pyscf/pyscf_ground_state_solver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/qiskit_nature_pyscf/pyscf_ground_state_solver.py b/qiskit_nature_pyscf/pyscf_ground_state_solver.py index 0814e03..a1a3062 100644 --- a/qiskit_nature_pyscf/pyscf_ground_state_solver.py +++ b/qiskit_nature_pyscf/pyscf_ground_state_solver.py @@ -18,7 +18,6 @@ import numpy as np from pyscf import fci -from qiskit.opflow import PauliSumOp from qiskit.quantum_info import SparsePauliOp from qiskit_nature.second_q.algorithms import GroundStateSolver from qiskit_nature.second_q.operators import SparseLabelOp @@ -200,8 +199,8 @@ def solve( def get_qubit_operators( self, problem: BaseProblem, - aux_operators: dict[str, SparseLabelOp | SparsePauliOp | PauliSumOp] | None = None, - ) -> tuple[SparsePauliOp | PauliSumOp, dict[str, SparsePauliOp | PauliSumOp] | None]: + aux_operators: dict[str, SparseLabelOp | SparsePauliOp] | None = None, + ) -> tuple[SparsePauliOp, dict[str, SparsePauliOp] | None]: """This solver does not deal with qubit operators and this method raises a RuntimeError.""" raise RuntimeError( "This solver is a purely classical one and as such solves an ElectronicStructureProblem" From 2c6254b612666b99924f55a724648503ed7ec6b1 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Fri, 9 Jun 2023 11:47:02 +0200 Subject: [PATCH 7/7] fix: remove computation of spin squared expectation value This is currently not guaranteed to give the correct result. I know a way of fixing this when having the MO coefficients available but we do not have them here. Will investigate this in the future. For now, we simply do not compute the spin related values. --- qiskit_nature_pyscf/pyscf_ground_state_solver.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/qiskit_nature_pyscf/pyscf_ground_state_solver.py b/qiskit_nature_pyscf/pyscf_ground_state_solver.py index a1a3062..3b4fcf8 100644 --- a/qiskit_nature_pyscf/pyscf_ground_state_solver.py +++ b/qiskit_nature_pyscf/pyscf_ground_state_solver.py @@ -166,10 +166,6 @@ def solve( nelec=problem.num_particles, ) - spin_square, _ = fci.spin_square( - ci_vec, norb=problem.num_spatial_orbitals, nelec=problem.num_particles - ) - density: ElectronicDensity if restricted_spin: raw_density = self.solver.make_rdm1( @@ -190,8 +186,8 @@ def solve( "nuclear_repulsion_energy", None ) result.num_particles = [sum(problem.num_particles)] - result.magnetization = [0.5 * (problem.num_alpha - problem.num_beta)] - result.total_angular_momentum = [spin_square] + result.magnetization = [float("NaN")] + result.total_angular_momentum = [float("NaN")] result.electronic_density = density return result