Skip to content

Fix indexing inside SplineX2X when outputing orbitals fewer than it holds#4871

Merged
prckent merged 14 commits into
QMCPACK:developfrom
camelto2:hybridrep_fix_indexing
Dec 15, 2023
Merged

Fix indexing inside SplineX2X when outputing orbitals fewer than it holds#4871
prckent merged 14 commits into
QMCPACK:developfrom
camelto2:hybridrep_fix_indexing

Conversation

@camelto2

@camelto2 camelto2 commented Dec 12, 2023

Copy link
Copy Markdown
Contributor

Please review the developer documentation
on the wiki of this project that contains help and requirements.

Proposed changes

Found a segfault when trying to use hybridrep in orbital optimization. The source of the problem is that when doing orbital optimization, the underlying orbital set includes unoccupied orbitals. However, if we are calling the evaluations from inside a DiracDeterminant, the ValueVector psi size is ways set to the number of occupied orbitals, not the full size of the SPOSet. The fix here allows for proper indexing into psi, and this is actually producing a successful hyrbid rep optimization.

The spline classes do not properly guard against accessing out of bounds for the ValueVector psi, and I expect this is more general problem for all SPOSets.

TO DO:

  • Fix SplineR2R
  • Fix SplineC2C
  • add useful unit tests
  • Fix SplineC2R
  • Fix SplineC2COMPTarget
  • Fix SplineC2ROMPTarget

What type(s) of changes does this code introduce?

Delete the items that do not apply

  • Bugfix

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

M1 mac

Checklist

Update the following with a yes where the items apply. If you're unsure about any of them, don't hesitate to ask. This is
simply a reminder of what we are going to look for before merging your code.

  • Yes. This PR is up to date with current the current state of 'develop'
  • Yes. Code added or changed in the PR has been clang-formatted
  • Yes. This PR adds tests to cover any new code, or to catch a bug that is being fixed
  • No. Documentation has been added (if appropriate)

@camelto2
camelto2 requested a review from ye-luo December 12, 2023 20:29
@camelto2

Copy link
Copy Markdown
Contributor Author

The current units tests that are failing, are actually failing as expected. This is due to other spline implementations needing the same fixes. I'll work on those next and get the test passing

@camelto2
camelto2 marked this pull request as ready for review December 14, 2023 15:25
@camelto2

Copy link
Copy Markdown
Contributor Author

As is, the unit tests are modified to allow for the (requested number of orbitals) < (the number of orbitals defined in the SPOSet). The current unit test in test_hybridrep only checks SplineC2C and SplineR2R. These modifications to the unit test fail with an out of bounds access without the changes to SplineC2C and SplineR2R. The various assign_x functions in the splines now guard against out of bounds access for the requested number of orbitals, and then the tests pass

The diamond2x1x1 test can be modified in the same way to test SplineC2R, but I'm still taking a look at that. For now, I think we could just merge this, and do subsequent PRs on SplineC2R and SplineC2ROMPTarget/SplineC2COMPTarget if those need it

// protect last
last = last > kPoints.size() ? kPoints.size() : last;
const size_t last_real = std::min(kPoints.size(), psi.size());
last = last > last_real ? last_real : last;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be called last_cplx as the last complex output orbital.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

{
// protect last
last = last > kPoints.size() ? kPoints.size() : last;
const size_t last_real = std::min(kPoints.size(), psi.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

last_cplx here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

const ST* restrict g2 = myG.data(2);

const size_t N = last_spo - first_spo;
const size_t last_real = last_spo > psi.size() ? psi.size() : last_spo;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

last_cplx here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

{
// protect last
last = last > kPoints.size() ? kPoints.size() : last;
const int last_real = std::min(kPoints.size(), psi.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

last_cplx here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

ye-luo
ye-luo previously approved these changes Dec 14, 2023
@ye-luo

ye-luo commented Dec 14, 2023

Copy link
Copy Markdown
Contributor

Test this please

@prckent
prckent enabled auto-merge December 14, 2023 23:54
@prckent

prckent commented Dec 15, 2023

Copy link
Copy Markdown
Contributor

Test this please

@camelto2

camelto2 commented Dec 15, 2023

Copy link
Copy Markdown
Contributor Author

Well the V100 Clang offload tests were failing, which makes me think the tests I modified actually end up going through SplineC2COMPTarget, so i need to include those fixes in this PR as well. So I went ahead and fixed SplineC2R and modified a test for that as well since it seems all the Spline classes need a fix

@camelto2

Copy link
Copy Markdown
Contributor Author

Ok, I think all tests should pass now

@camelto2
camelto2 requested a review from ye-luo December 15, 2023 19:22

const size_t N = last_spo - first_spo;
const size_t last_cplx = last_spo > psi.size() ? psi.size() : last_spo;
const size_t N = last_cplx - first_spo;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the fix for the previous CI failure.

@ye-luo

ye-luo commented Dec 15, 2023

Copy link
Copy Markdown
Contributor

Will approve and merge once the CI update is merged.

@ye-luo
ye-luo force-pushed the hybridrep_fix_indexing branch from b66b7cc to 78b6ee1 Compare December 15, 2023 20:37
@ye-luo ye-luo changed the title Fix indexing inside SplineX2X Fix indexing inside SplineX2X when outputing orbitals fewer than it holds Dec 15, 2023
@ye-luo

ye-luo commented Dec 15, 2023

Copy link
Copy Markdown
Contributor

Test this please

@prckent
prckent merged commit 112f424 into QMCPACK:develop Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants