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

Instability of results as exponent approaches 3. #73

Open
kvhuguenin opened this issue Oct 4, 2024 · 2 comments
Open

Instability of results as exponent approaches 3. #73

kvhuguenin opened this issue Oct 4, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@kvhuguenin
Copy link
Contributor

As discvoered by @E-Rum , the potentials obtained from the calculator seem to diverge as the exponent p-->3:

from torchpme.calculators import PMEPotential
import torch
for exp in [1.,2.,2.5,2.9,2.999,2.9999,2.999999,3.]:
    calculator = PMEPotential(
        exponent=exp,
        atomic_smearing=1.,
        mesh_spacing=0.05,
        interpolation_order=3,
        subtract_interior=True,
        full_neighbor_list=False,
    )
    potentials = calculator(
        positions=torch.rand(10, 3) * 10,
        charges=torch.rand(10,1) * 0.01,
        cell=torch.eye(3) * 10,
        neighbor_indices=torch.randint(0, 10, (15,2)),
        neighbor_distances=torch.rand(15),
    )
    print(min(abs(potentials)))

leading to Outputs:

tensor([0.0018])
tensor([0.0008])
tensor([0.0026])
tensor([0.0031])
tensor([0.3840])
tensor([2.7494])
tensor([210.4061])
tensor([nan])

Analytically, both the real and reciprocal space sums converge absolutely for any real number p>0, suggesting that this is due to a numerical instability. The obvious candidate in the current implementation is the incomplete gamma function gammaincc(a,x) = gammaincc((3-p)/2, x) whose first argument a needs to be positive for the torch (and also scipy) implementations. As a approaches zero, there could be numerical instabilities due to this.

@kvhuguenin kvhuguenin self-assigned this Oct 4, 2024
@PicoCentauri
Copy link
Contributor

Interesting. We can look into the torch code together next week if we can fix something there.

@ceriottm
Copy link
Contributor

ceriottm commented Oct 6, 2024

The ideal solution here would be to implement something different that also handles arbitrarily large (integer) exponents.

@PicoCentauri PicoCentauri added the bug Something isn't working label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants