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

Resurrect Ewald2D #3852

Merged
merged 67 commits into from
May 12, 2022
Merged

Resurrect Ewald2D #3852

merged 67 commits into from
May 12, 2022

Conversation

Paul-St-Young
Copy link
Contributor

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

Proposed changes

Resurrect true 2D Ewald sum without using OHMMS_DIM.

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

  • New feature

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

Workstation

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'
  • No. 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)

@Paul-St-Young Paul-St-Young self-assigned this Feb 17, 2022
@prckent
Copy link
Contributor

prckent commented Feb 17, 2022

Paul -

Thanks for looking at this. It would be good to have a proper 2D evaluation... if this is a proper implementation. How thoroughly have you checked this code and its outputs? I think it is safe to say that shortcuts were made in the historical Coulomb code, so before we can advertise 2D Coulomb as working and add examples etc. I think we need to be very thorough with testing, convergence checks, validation etc.

@Paul-St-Young
Copy link
Contributor Author

@prckent I looked at Madelung energy of square and triangular lattices using the unit cell and select supercells.
The potential energy of the perfect crystal checks out to 8 digits.
I also see reasonable numbers in VMC and DMC runs (which will require a few more PRs to enable).

That said, I'm not comfortable with this becoming a production-level feature right now.
I do want to get to that point in the near future (after more integration tests).

For now, this feature can be enable only via an undocumented flag <parameter name="ndim"> 2 </parameter> in <simulationcell>. Otherwise, the usual 3D code path is taken, so current users should be unaffected.

@prckent
Copy link
Contributor

prckent commented Feb 17, 2022

I looked at Madelung energy of square and triangular lattices using the unit cell and select supercells. The potential energy of the perfect crystal checks out to 8 digits. That is a relief to hear. Can you add some of these to test2D? It is good to capture these checks and establish tests that anyone fiddling with the code in future will have to keep working. An anisotropic case would be good as well.

@Paul-St-Young
Copy link
Contributor Author

I'll need to figure out how to add these to the unit test.
Attached are the inputs and outputs in case I lose them ...

tb11f2_vmad.zip

@Paul-St-Young
Copy link
Contributor Author

@prckent I added all my checks to the unit test.
This PR is ready for review.

I'm not sure why the CI cannot build the code.
I am unable to reproduce the CI failures using Clang 11, GCC 11.2.0, or GCC 10.3.0.

src/Particle/Lattice/LRBreakupParameters.h Show resolved Hide resolved
src/Particle/LongRange/EwaldHandler2D.cpp Show resolved Hide resolved
src/Particle/LongRange/EwaldHandler2D.cpp Outdated Show resolved Hide resolved
src/Particle/LongRange/EwaldHandler2D.h Show resolved Hide resolved
src/Particle/LongRange/EwaldHandler2D.h Outdated Show resolved Hide resolved
src/Particle/LongRange/KContainer.cpp Outdated Show resolved Hide resolved
src/Particle/LongRange/KContainer.h Outdated Show resolved Hide resolved
src/Particle/ParticleIO/LatticeIO.cpp Outdated Show resolved Hide resolved
@jtkrogel
Copy link
Contributor

I would like to discuss a little about the use of ndim in the input. As I understand, the physical systems we can simulate right now are fully 3D, while Ewald2D is meant to apply to systems that have two periodic dimensions. Is this correct?

If so, I don't think we should use ndim in the <simulationcell/> input. Rather, the use of Ewald2D should be triggered by the boundary conditions, i.e. bconds==ppp => Ewald3D while bconds==ppn/pnp/npp =>Ewald2D, and bconds==pnn/npn/nnp => abort.

As a follow-on, does the current code support ppn/pnp/npp or just ppn?

@prckent
Copy link
Contributor

prckent commented Feb 18, 2022

Rather, the use of Ewald2D should be triggered by the boundary conditions, i.e. bconds==ppp => Ewald3D while bconds==ppn/pnp/npp =>Ewald2D, and bconds==pnn/npn/nnp => abort. Agree. Note that there is no need to expose an option here - if someone wants to reproduce a 3D ion-ion energy they can use ppp. And we should definitely abort if someone tries pnn. This would be consistent with the general plan of having sensible default options for users and avoid/reduce the number of input parameters. Note that some ion-ion Coulomb checks based on the input wavefunctions might need bypassing for 2D, e.g. QE inputs. I think PySCF has proper low dimensional Coulomb handling now.

@Paul-St-Young
Copy link
Contributor Author

@jtkrogel Yes, Ewald2D is meant for a system that's periodic only in 2 directions.
I hard-coded for ppn, so this code is not correct for pnp and npp conditions.

I don't think we can have ppn directly trigger Ewald2D, because one could be simulating a quasi-2D slab.
In that case, the EwaldHandlerQuasi2D should be used instead.

@jtkrogel
Copy link
Contributor

Could you explain more? I don't understand the distinction (2D/quasi-2D) if all systems in question exist in a 3D space.

@Paul-St-Young
Copy link
Contributor Author

By true 2D, I mean that all particles stay exactly on the same plane.
By quasi 2D, I mean that particles are much more confined in one of the spatial direction than the others, but can still move around a little bit along that direction. This out-of-plane movement is completely forbidden in the true 2D case.

@Paul-St-Young
Copy link
Contributor Author

Do you have data to show 3D expanding converge to quasi2D value?

No, I do not have a 3D input with expanding z direction.

@Paul-St-Young
Copy link
Contributor Author

On second thought, 3D ppn with large z will not match the quasi 2D value because they have different neutralizing backgrounds.
The 3D positive background charge density for an N-electron simulation cell is +e*N/V, i.e. \sum_i +e/V uniformly spread out over the entire cell volume V, whereas the quasi 2D background charge density is \sum_i +e/A * \delta(z-z_i), i.e. one plane of 2D positive charge at the z height of each electron. A is the 2D cell area.

Copy link
Contributor

@PDoakORNL PDoakORNL left a comment

Choose a reason for hiding this comment

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

It looks like my previous review was addressed where possible for this PR except for this.

src/QMCHamiltonians/CoulombPBCAA.cpp Outdated Show resolved Hide resolved
// make sure we can ignore the short-range Madelung sum
mRealType Rws = Ps.getLattice().WignerSeitzRadius;
mRealType rvsr_at_image = Rws*AA->evaluate(Rws, 1.0/Rws);
if (rvsr_at_image > 1e-6)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want behavior to be preserved it should be tested, sometimes you need to be as clever in test code as you are in the actual implementation. You should be able to devise a synthetic case where this is true.

From the standpoint of the exception, putting the failing value in the app_log and it not actually being the alpha value means digging back into the implementation of the handlers for anyone that runs into this. Use a string stream or some other method and get the bad value into the exception's what string. You might need to indicate what the relationship between the short range part of the ewald being > 1e-6 at the WSR and apha being too small. Is this message valid for other choices of LRHANDLER? That is what the terribly name AA is right?

@ye-luo
Copy link
Contributor

ye-luo commented May 3, 2022

Could you also document the new option value in the manual?

@Paul-St-Young
Copy link
Contributor Author

@PDoakORNL I clarified the exception message and added a test with CHECK_THROWS.
Turns out I just had to set a very small LR_dim_cutoff to get a violation of my condition.
The short range part being < 1e-6 at the WSR should apply to any LRHandler.
Although the message about alpha is specific to the Ewald handler.

@Paul-St-Young
Copy link
Contributor Author

@ye-luo I added documentation for LR_handler in the manual.

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.

Only minor things left.

Not directly related to this PR. I noticed quasi2D doesn't seem to be connected in PBCAB.

src/Particle/LongRange/KContainer.cpp Outdated Show resolved Hide resolved
src/QMCHamiltonians/tests/test_ewald_quasi2d.cpp Outdated Show resolved Hide resolved
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

@ye-luo
Copy link
Contributor

ye-luo commented May 12, 2022

Test this please

@ye-luo
Copy link
Contributor

ye-luo commented May 12, 2022

@PDoakORNL OK to merge?

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.

It think that this meets easily meet the merge criteria now, and it can clearly be refined further as/if needed. Thanks for enduring the review Paul. I think that the code is better for it.

@prckent prckent dismissed PDoakORNL’s stale review May 12, 2022 19:04

Keep things moving. Can be revisited in future if not considered sufficiently addressed.

@prckent prckent merged commit 8cd61d7 into QMCPACK:develop May 12, 2022
@PDoakORNL
Copy link
Contributor

@Paul-St-Young satsified my important concerns.

@ye-luo ye-luo mentioned this pull request Jun 8, 2022
@Paul-St-Young Paul-St-Young deleted the ndim2 branch July 5, 2022 20:32
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.

6 participants