-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1rdm with spinor support #4807
1rdm with spinor support #4807
Conversation
This implementation just adds a bunch of if statements on whetehr to include spin gradients or not. Ideally, I would like to clean this up a lot and template it on MCCoords, but this should be adequate for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New code requires test support
Many PR's are coming in with none, you should be writing tests as you develop not as an afterthought later.
#4789 will have a test added prior to merge following the discussion on that PR. For this one, I am firmly requesting a merge of functionality first, followed by an agreed upon and fulfilled PR including the test(s) by Cody. The functionality here is part of an active CMS research project and it is important that this functionality makes it into develop and remains current there so that other bugs we are encountering (blocks to research) can be clearly identified in develop and fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A big part of keeping code current is being able to tell whether changes made to the code break it or not. This requires tests. All that really needs to be done here is to look at the current testing and figure out how to add cases for pset_targets that are spinors. This probably requires adding a mock particle set factory function to Particle/tests/MinimalParticlePool.h, which makes me wonder how much serious testing any of the spinor code has had.
@@ -276,12 +300,16 @@ class OneBodyDensityMatrices : public OperatorEstBase | |||
|
|||
// basis set updates | |||
void updateBasis(const Position& r, ParticleSet& pset_target); | |||
// basis set updates with spin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ///
or /** ... */
otherwise method documentation won't be produced by doxygen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed these
@@ -354,6 +361,82 @@ inline void OneBodyDensityMatrices::generateDensitySamples(bool save, | |||
rhocur_ = rho; | |||
} | |||
|
|||
inline void OneBodyDensityMatrices::generateDensitySamplesWithSpin(bool save, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generateDensitySamples has a unit test this can as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -234,11 +241,19 @@ class OneBodyDensityMatrices : public OperatorEstBase | |||
* * | |||
*/ | |||
void generateDensitySamples(bool save, int steps, RandomBase<FullPrecReal>& rng, ParticleSet& pset_target); | |||
|
|||
//same as above, but with spin variables included |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'///'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
The spinor code has had plenty of testing. We didn't use minimal particle pool. Most of the tests build particle sets by hand, similar to how many tests in the code have been written in the past |
This is probably high enough level to make switch over to the mock pools worth it. Which I think I agreed to help with in the past. And probably didn't which helped us get here. One requirement would be a very small wavefunction file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The discussion here rightly points out that we need a written up policy that we can point to and apply uniformly.
There has been a lot of discussion in various parts of Slack about this.
The requirement I am going to recommend here and that we apply in the future is simply that there is at least testing of some flavor in this PR, i.e. >=1 test, that executes a significant (>50%) fraction of lines in the code. Test coverage should not decrease as a result of the PR. Many of the reasons for this have been discussed already, but importantly it would allow someone other than the original code author to make a change somewhat safely. The change might be something a simple as formatting or updating error handling. This level of testing also helps guard against memory leaks and corruption creeping in. The test could be a deterministic integration test or (preferred) a set of unit tests. As already discussed, setting up unit tests can be a pain for complex objects. It is the responsibility of the implementer to go through that pain however and not create subsequent pain for others -- we have plenty of historical lessons is this area, hence the vigorous discussion. The rest of us will be trying to minimize the pain to create unit tests by docs/tutorials/hackathons/better design. This should get easier with time since we are going to be deleting lots of legacy and refactoring further, which will disentangle more code. => So for the time being this PR needs a test added. Based on the discussion of working QMC runs, a deterministic test is straightforward and will not take much time. Subsequent PRs will need to add docs, examples etc., but I don't think this was ever in question.
I would like to make it clear that I absolutely understand the need for testing, and that I never intended to make a PR without a test. I only made a PR without a test because I was requested to do so. For most of my development tasks, I do start my code development with a unit test before doing any of the implementation. Sometimes, depending on what I'm doing, it is easier to just get something working and worry about a test later before trying to merge if I'm just trying to see how or if something would work. It may not be the best practice, but in this case that is what I did. I added the functionality quickly so that Jaron could start to play around with it without it being made a permanent feature in the code. I haven't had time to work on making the tests due to other constraints, so I was planning to just keep my branch up to date with develop and merge eventually whenever I actually got around to writing a test. However, I was asked to go ahead and make a PR now, so I did. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also address the CI failure?
//spin related variables | ||
Real spcur_; | ||
Real dspcur_; | ||
bool is_spinor_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be made const.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Yes, I requested the PR. Code development ideals and research needs are at odds, creating a tug-of-war over which of our own feet to shoot. Hopefully with some future discussion we can sufficiently reduce the productivity drains on both sides of this issue, but I expect it will take some effort and creativity. |
(Going through open PRs and checking what is needed to get them merged) |
I'm having trouble reproducing some of the failures I'm seeing in some of the test. One of them is bus error, another a segfault. I haven't been able to reproduce those locally so I'm not sure how to go about debugging it |
Have you tried to decode the error found by the asan complex build? This shows that there is a memory related error in the estimator unit test. |
I think I have the fix for that now. I wasn't able to get that failure to trigger on my machines, but I think I tracked it down anyway. There are still tests failing from "maybe unitinitialized" which I've been trying to fix. My simple fixes aren't getting rid of the warning, and it seems to be happening due to the -O2, -O3 optimization flags. When I build with -O1, I do not trigger that warning, so i'm still trying to sort that out |
should all be fixed now |
Pinging this again, I think this is now ready to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Ping @prckent @PDoakORNL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving in the right direction.
More generally, presumably you have also thought about the random sampling implemented here:
I do wonder if the random sampling is an unnecessary complication. Do we have data to justify? The dimensionality of the integral is not that large so random sampling won't auotmatically have a large benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving in the right direction.
More generally, presumably you have also thought about the random sampling implemented here:
I do wonder if the random sampling is an unnecessary complication. Do we have data to justify? The dimensionality of the integral is not that large so random sampling won't automatically have a large benefit.
Test this please |
@@ -145,6 +147,11 @@ class OneBodyDensityMatrices : public OperatorEstBase | |||
/// current density | |||
Real rhocur_ = 0.0; | |||
|
|||
///spin related variables | |||
Real spcur_; | |||
Real dspcur_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI. The above two uninitialized variables caused failure https://github.com/QMCPACK/qmcpack/actions/runs/8022503383/job/21922019273?pr=4928
Fixed by 1aa5148
Unfortunately compilers didn't warn us in this case.
Please review the developer documentation
on the wiki of this project that contains help and requirements.
Proposed changes
This PR adds the spinor support into the 1rdm. If spinor=true in the particleset, it will generate spin moves similar to how the spatial moves are generated.
What type(s) of changes does this code introduce?
Delete the items that do not apply
Does this introduce a breaking change?
What systems has this change been tested on?
macOS
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.