Skip to content

Fix bug in TrialWaveFunction mw_evalGrad for spinor wave functions#4911

Merged
ye-luo merged 3 commits intoQMCPACK:developfrom
camelto2:twf_fix_evalGrad
Feb 1, 2024
Merged

Fix bug in TrialWaveFunction mw_evalGrad for spinor wave functions#4911
ye-luo merged 3 commits intoQMCPACK:developfrom
camelto2:twf_fix_evalGrad

Conversation

@camelto2
Copy link
Contributor

@camelto2 camelto2 commented Jan 31, 2024

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

Proposed changes

This PR fixes a bug I found when doing some testing of the spinor code using the batched drivers. Essentially, I saw errors in the energy and kinetic energy relative to legacy only if there is a jastrow present and only if drift was on. Ended up tracking it down to the fact that WaveFunctionComponents that do not use the spins do not touch the spin gradient component, which they shouldn't. However, the problem was that in the TWF::mw_evalGrad function, it was passing in the previous wave function components TWFGrad type. Since the Jastrow mw_evalGrad wasn't setting the spin component to zero, then the grads += grads_z ends up accumulating the first slater determinants value over and over again. So for 3 WF components, the spin gradient was 3x too large.

Fixed by simply moving the TWFGrad initialization into the loop.
set zero before calling the single walker fallback.

Closes #4910

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)

rcclay
rcclay previously approved these changes Jan 31, 2024
prckent
prckent previously approved these changes Jan 31, 2024
Copy link
Contributor

@prckent prckent left a comment

Choose a reason for hiding this comment

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

LGTM

@prckent
Copy link
Contributor

prckent commented Jan 31, 2024

Test this please

TWFGrads<CT> grads_z(num_wf);
ScopedTimer localtimer(wf_leader.WFC_timers_[VGL_TIMER + TIMER_SKIP * i]);
const auto wfc_list(extractWFCRefList(wf_list, i));
wavefunction_components[i]->mw_evalGrad(wfc_list, p_list, iat, grads_z);
Copy link
Contributor

@ye-luo ye-luo Jan 31, 2024

Choose a reason for hiding this comment

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

Need a bit change. WFC::mw_evalGrad is not expected to depends on previous value of grads_z. This is different from single walker API. At

grad_now[iw] = wfc_list[iw].evalGradWithSpin(p_list[iw], iat, spingrad_now[iw]);

Set spingrad_now[iw] to zero before calling evalGradWithSpin. grad_now[iw] has been directly overwritten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted TrialWaveFunction back and changed in WaveFunctionComponent.cpp

Copy link
Contributor

@ye-luo ye-luo left a comment

Choose a reason for hiding this comment

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

See my comment above.

@camelto2 camelto2 dismissed stale reviews from prckent and rcclay via 5e702ed January 31, 2024 23:34
@ye-luo
Copy link
Contributor

ye-luo commented Jan 31, 2024

Test this please

@ye-luo ye-luo enabled auto-merge January 31, 2024 23:37
@ye-luo ye-luo merged commit f0269b7 into QMCPACK:develop Feb 1, 2024
@camelto2 camelto2 deleted the twf_fix_evalGrad branch February 1, 2024 00:51
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.

Incorrect total energy and energy components for batched VMC with drift and spinors

4 participants