From 5605d5dfe994e0ff0446e9a4f249e684a58d3e0b Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 27 Sep 2023 10:27:51 +0200 Subject: [PATCH] fix: ensure the `ElectronicDensity` is always unrestricted-spin The `ElectronicDensity` object returned in the `ElectronicStructureResult` from the `PySCFGroundStateSolver` is documented to always contain unrestricted-spin information. This was not the case so far and is addressed by this commit. --- qiskit_nature_pyscf/pyscf_ground_state_solver.py | 15 ++++----------- .../proper-qiskit-density-0582f26cc9a669d9.yaml | 10 ++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/proper-qiskit-density-0582f26cc9a669d9.yaml diff --git a/qiskit_nature_pyscf/pyscf_ground_state_solver.py b/qiskit_nature_pyscf/pyscf_ground_state_solver.py index 874000b..b1c1bd6 100644 --- a/qiskit_nature_pyscf/pyscf_ground_state_solver.py +++ b/qiskit_nature_pyscf/pyscf_ground_state_solver.py @@ -166,17 +166,10 @@ def solve( 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]) + 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]) diff --git a/releasenotes/notes/proper-qiskit-density-0582f26cc9a669d9.yaml b/releasenotes/notes/proper-qiskit-density-0582f26cc9a669d9.yaml new file mode 100644 index 0000000..07f20bd --- /dev/null +++ b/releasenotes/notes/proper-qiskit-density-0582f26cc9a669d9.yaml @@ -0,0 +1,10 @@ +--- +fixes: + - | + The :class:`~qiskit_nature.second_q.properties.ElectronicDensity` object that was returned as part of the + :class:`~qiskit_nature.second_q.problems.ElectronicStructureResult` from the :class:`.PySCFGroundStateSolver` + was faultily storing restricted-spin information within the alpha-spin register even though the object is + documented as storing unrestricted spin-data. This has been fixed and the + :class:`~qiskit_nature.second_q.properties.ElectronicDensity` object is now guaranteed to store + unrestricted-spin information. If a restricted-spin density is required it may be obtained from the + :meth:`~qiskit_nature.second_q.properties.ElectronicDensity.trace_spin` method.