google-deepmind/ferminet

Question about pbc ewald part.

Closed this issue · 2 comments

Dear contributors,
Glad to see open-source code of electron gas system. When I go through pbc code, I get a problem about ewald summation and I cite it below.https://github.com/deepmind/ferminet/blob/main/ferminet/pbc/hamiltonian.py#L142

phase_prim_ae = phase_ae % 1

If I understand correctly this line is used to calculate the energy between elecrtrons and their images. And the summation should be done following minimal-imag conventions.

Let's assume we are working in a simple cubic and two electrons are seperated by 0.6 L where L is the length of this simple cubic in one dimension. So the minimal imag between these two electrons should be -0.4L, while the code above will give 0.6 L instead which may lead to some problems.

Although this problem can be easily masked if large enough truncated limit is used, it still needs to be corrected for potential problems.

I'm afraid the correct code should be

phase_prim_ae = (phase_ae + 0.5) % 1 - 0.5

Then the minimal imag between 0.6 L electron pairs will be -0.4L, which seems correct.

Hi Xiang, thanks for your interest in the release and for taking a careful look at the code!

You are absolutely correct that if we were applying a minimum image convention, that code would be wrong. However, these lines are only there because as walkers move far from the origin, they move outside the region of physical space where we are actually taking the Ewald sum. We only need to move the walkers 'close' (by some definition related to the truncation length) to the origin, and so an electron occasionally being one image over from the minimum image does not cause a problem.

To lay your mind at ease: I have calculated the potential of two electrons separated as you suggested by a distance of 0.6 units with/without your suggested edit (here I am using NumPy only, no JAX, and double precision):

without edit: -2.75527802498627
with edit: -2.7552780249862696

(simple cubic lattice, lattice constant 1 bohr, no atomic potential, include_heg_background=True)

I'm not sure this -needs- to be fixed, however, it cannot hurt and might save someone anxiety about the same problem in future. I would like to lay any readers' minds to rest thought that this does not cause the code to give 'wrong answers' as far as I can tell.

Dear Gcassella,

Thanks for the quick response. I agree that the difference is quite small and won't affect the correctness of present work. I just worry that this difference might lead to some problems at extremely special cases and that's why I raise the issue.