Skip to content

Conversation

@TiborGY
Copy link
Contributor

@TiborGY TiborGY commented Aug 15, 2022

Description

sq_rsp(...) is an ancient diagonalizer function from Psi3 with many issues. While its innards could be improved, the function signature is horrid. It should be deprecated and replaced with something better.
Stemming from the awful interface, users of sq_rsp(...) never check if the diagonalization failed, because they cannot. This is now rectified by adding failure checks wherever the new DSYEV wrappers are called.
Checks against non-square matrices are also added where there is both a row and column count at the call site.

Some of the call sites would be dfocc territory, this PR does not include them to avoid conflicts with the dfocc overhaul.
This is another shard of the #2642 mega-PR that can be merged after PR #2678 and #2738 are in.

Todos

  • Implement two new wrapper functions around DSYEV to replace sq_rsp(...) with. The new wrappers have a much cleaner interface, and no longer require the allocation of an eigenvector array if the caller only needs eigenvalues. They also no longer swallow the return value of DSYEV, in fact their return value is marked as [[nodiscard]]. In short, checking for diagonalization failure went from impossible to mandatory.
    Please note that unlike sq_rsp(...), the new functions do not take a "tolarence" value, but this is actually a null change as that parameter has been set-but-unused in sq_rsp(...) since ~forever ago when sq_rsp(...) switched to calling DSYEV internally.
  • Replace sq_rsp(...) calls in mcscf (mcscf::SCF::energy and mcscf::MatrixBase::diagonalize) with new wrapper. Add checks for diagonalization failure and guard against non-square matrices.
  • Replace sq_rsp(...) calls in detci (detci/h0block.cc, detci/sem.cc and detci/sem_test.cc) with new wrapper. Add checks for diagonalization failure.
  • Replace sq_rsp(...) call in libmints/matrix.cc (Matrix::diagonalize) with new wrapper. Add checks for diagonalization failure. Add a sanity checks for non-square matrices and illegal values of "diagonalization order".
  • Replace sq_rsp(...) calls in ccenergy (ccenergy/d1diag.cc, ccenergy/d2diag.cc and ccenergy/new_d1diag.cc) with new wrapper. Add checks for diagonalization failure. This allows the removal of the eigenvector array, and the code that allocates/deallocates it.
  • Replace sq_rsp(...) calls in the libqt Davidson solver with new wrapper. Add checks for diagonalization failure.
  • Replace sq_rsp(...) call in the RHF and ROHF stability checks with new wrapper. Add checks for diagonalization failure.
  • Replace sq_rsp(...) calls in libsapt_solver/sapt2.cc with new wrapper. Add checks for diagonalization failure.

Questions

  • Is libciomr a good place for the new wrappers to live in? The one they are replacing is there, so it seemed like as good of a place as any.

Checklist

  • No new features
  • 503/503 ctests are passing

Status

  • Ready for review
  • Ready for merge

@TiborGY TiborGY changed the title Patch 10 Replace sq_rsp(...) with a new DSYEV wrapper Aug 15, 2022
@TiborGY TiborGY changed the title Replace sq_rsp(...) with a new DSYEV wrapper Replace sq_rsp(...) with a new DSYEV wrapper, part 1 Aug 15, 2022
@TiborGY TiborGY force-pushed the patch-10 branch 2 times, most recently from 6488186 to 1175db0 Compare October 6, 2022 01:02
@psi-rking
Copy link
Contributor

As an old-timer, I would say yes, libciomr is the place. At least as long as there is still a libciomr, that's where I would look. This is nice improvement!

ccdensity has a sq_rsp too. did you miss that one?

@TiborGY
Copy link
Contributor Author

TiborGY commented Oct 7, 2022

As an old-timer, I would say yes, libciomr is the place. At least as long as there is still a libciomr, that's where I would look. This is nice improvement!

ccdensity has a sq_rsp too. did you miss that one?

I ran a search and none of the remaining hits were from ccdensity.

@psi-rking
Copy link
Contributor

psi-rking commented Oct 7, 2022 via email

@TiborGY
Copy link
Contributor Author

TiborGY commented Oct 7, 2022

Indeed it has, by yours truly. See #2672 for the removal. I do not know when the AEL code became defunct, but I removed it because it was never called. The code is preserved in the psi4attic repo.

@TiborGY TiborGY marked this pull request as ready for review November 19, 2022 02:11
Copy link
Member

@loriab loriab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup and consolidation, thank you!

@TiborGY
Copy link
Contributor Author

TiborGY commented Nov 28, 2022

503/503 ctest tests are passing
ctestlog.txt
If that is judged to be sufficient coverage, this PR is ready for merge.

@loriab
Copy link
Member

loriab commented Nov 28, 2022

I've just run full ctests and pytests with this branch, and it's clean, so lgtm!

@loriab loriab added this to the Psi4 1.7 milestone Nov 28, 2022
@loriab loriab added the cleanup For issues where the goal is to make Psi4 a little cleaner. label Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup For issues where the goal is to make Psi4 a little cleaner.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants