Skip to content
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

Refactor grid randomization #4363

Merged
merged 25 commits into from
Jan 11, 2023
Merged

Conversation

markdewing
Copy link
Contributor

Fixes the issue raised in #4362. There will be a lot of CI failures. Not sure the best way to approach the fix and updating the deterministic tests. This is a start to at least introduce a possible fix.

Does some refactoring to put the inputs to the random rotation matrix into their own class. The generation of the rotation matrix is extracted from the randomize_grid function, to make it testable in isolation.

A single unit test is added to the rotation matrix - will need more in the future.

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

Delete the items that do not apply

  • Bugfix
  • Refactoring (no functional changes, no api changes)

Does this introduce a breaking change?

  • Yes

What systems has this change been tested on?

desktop

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
  • N/A. Documentation has been added (if appropriate)

Extract the storage and generation of the random rotation matrix to make
it easier to test.

Fix the issue in QMCPACK#4362 where the distribution of the rotations does not
cover the entire sphere.
class RandomRotationState
{
public:
using RealType = QMCTraits::RealType;
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete Type from name, the capitalization already indicates this is a type.

RandomRotationState() : rng_vals_({0.0, 0.0, 0.0}) {}
RandomRotationState(RandomGenerator& rng) : rng_vals_({rng(), rng(), rng()}) {}

TensorType getRandomRotationMatrix() const
Copy link
Contributor

@PDoakORNL PDoakORNL Dec 13, 2022

Choose a reason for hiding this comment

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

I think this should just be a function that takes a RNG and returns a random rotation matrix.

@@ -866,13 +865,9 @@ void NonLocalECPComponent::evaluateOneBodyOpMatrixdRContribution(ParticleSet& W,
}

///Randomly rotate sgrid_m
void NonLocalECPComponent::randomize_grid(RandomGenerator& myRNG)
void NonLocalECPComponent::randomize_grid(const RandomRotationState& rs)
Copy link
Contributor

@camelto2 camelto2 Dec 13, 2022

Choose a reason for hiding this comment

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

Note that there is also NonLocalECPComponent::randomize_grid(std::vector& sphere, RandomGenerator& myRNG). From what I can tell, this is only used by the legacy NonLocalECPotential_CUDA.cpp. For consistency, should that randomize_grid call be changed as well since the legacy code hasn't been removed yet?

That probably breaks more tests and since we are eventually dropping the legacy, maybe it isn't worth changing. But it seems to me things should be done consistently for whatever is actively in the code base.

Copy link
Contributor

@prckent prckent Dec 14, 2022

Choose a reason for hiding this comment

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

Indeed, we will want to fix this everywhere.

The code used by the legacy CUDA code paths will also need to be updated.

There will have to be some discussion around updating the tests. This will be a significant effort even for the smallest possible update and likely need parallelizing over multiple people.

@prckent
Copy link
Contributor

prckent commented Jan 4, 2023

I experimented with an ugly bash-awk-sed combination to update the test values for all CPU build variants as well as for the legacy CUDA variants. It looks like nearly all of the updates can be automated this way. Estimators such as the density will have to be updated by hand. Should I pursue this or is anyone else close to a clean solution?

@prckent
Copy link
Contributor

prckent commented Jan 5, 2023

Test this please

@prckent
Copy link
Contributor

prckent commented Jan 6, 2023

I have a fully updated set of reference values in #4383 that passes CI. They could be merged independently of this refactor or pulled into this PR.

The conflict in this PR also needs fixing.

What are the preferred next steps? Who has bandwidth?

src/Numerics/RandomRotationMatrix.h Outdated Show resolved Hide resolved
src/Numerics/RandomRotationMatrix.h Outdated Show resolved Hide resolved
@markdewing
Copy link
Contributor Author

I think #4383 should be merged independently.

Add some documentation to generateRotationMatrix
Keep the parts that don't depend on the RNG in Numerics,
change those names to RotationMatrix3D, and put the parts that depend
on the RNG in QMCHamiltonians.
@markdewing
Copy link
Contributor Author

Test this please

src/QMCHamiltonians/NonLocalECPComponent.h Outdated Show resolved Hide resolved
PPset[ipp]->randomize_grid(*myRNG);
{
TensorType rmat = generateRandomRotationMatrix(*myRNG);
PPset[ipp]->randomize_grid(rmat);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you fuse them into one line and keep the code concise?

src/Numerics/RotationMatrix3D.h Outdated Show resolved Hide resolved
The order of function argument evaluations is undefined in the standard.

This leads to a difference in evaluation order between debug and
release builds, which causes the order of rng1, rng2, and rng3 to be swapped.
In debug builds, the arguments get placed on the stack in the reverse
order listed.  In release builds, the code is likely inlined, and the
arguments effectively get evaluated in the forward order listed.
From random_grid to rotateQuadratureGrid
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.

Is it time to remove the WIP tag?

src/QMCHamiltonians/NonLocalECPotential.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/NonLocalECPotential.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/NonLocalECPotential.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/NonLocalECPotential.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/NonLocalECPotential.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/NonLocalECPotential.deriv.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/SOECPotential.cpp Outdated Show resolved Hide resolved
tests/solids/bccMo_2x1x1_SOREP/CMakeLists.txt Show resolved Hide resolved
@markdewing markdewing changed the title [WIP] Fix grid randomization issue and refactor Refactor grid randomization Jan 8, 2023
@markdewing
Copy link
Contributor Author

Test this please

ye-luo
ye-luo previously approved these changes Jan 9, 2023
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.

LGTM. Still need non-ANL approval.

@markdewing
Copy link
Contributor Author

Test this please

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.

The python code needs a description at the top saying what it is, what it was used for, where the output went, when it would need to be rerun etc.

Good to see the nearly 100% patch coverage

Also update the script to match a fix for the complex build.
@prckent
Copy link
Contributor

prckent commented Jan 11, 2023

Test this pleas

@prckent prckent enabled auto-merge January 11, 2023 17:36
@prckent
Copy link
Contributor

prckent commented Jan 11, 2023

Test this please

@prckent prckent merged commit e49d5ce into QMCPACK:develop Jan 11, 2023
@markdewing markdewing deleted the random_rotation branch January 11, 2023 21:50
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.

5 participants