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

Fix division by zero at geoopt #1170

Merged
merged 2 commits into from
Feb 10, 2025

Conversation

foxtran
Copy link
Contributor

@foxtran foxtran commented Feb 1, 2025

Fixes #500

@@ -850,7 +850,7 @@ subroutine relax(env,iter,mol,anc,restart,maxcycle,maxdispl,ethr,gthr, &
write(env%unit,'(5x,"change ",e18.7,1x,"Eh")') echng
write(env%unit,'(3x,"gradient norm :",f14.7,1x,"Eh/α")',advance='no') gnorm
write(env%unit,'(3x,"predicted",e18.7)',advance='no') depred
write(env%unit,'(1x,"("f7.2"%)")') (depred-echng)/echng*100
write(env%unit,'(1x,"("f7.2"%)")') (depred-echng)/(echng+1e-34_wp)*100
Copy link
Contributor

Choose a reason for hiding this comment

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

How did you determine this fixed #500? At least in the example they attached, the gradient norm is also NaN.

I would probably say to just not even write the percentage difference if the actual echng is effectively 0, rather than write an enormous value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found since I am using the same technique as for other issues. :-)

@@ -613,7 +613,11 @@ Subroutine dphidrPBC(mode,nat,xyz,i,j,k,l,vTrR,vTrB,vTrC,phi,&
dphidrj=0
dphidrk=0
dphidrl=0
onenner=1.0d0/(nan*nbn)
if (abs(nan*nbn).gt.eps) then
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth clarifying what the purpose of this check is. It seems like we would only reach this condition if for some reason the magnitude of one or both of these surface normals was very small. The earlier check already determines if the normals are nearly parallel.

Is there a specific example you have found that the code change here fixes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The earlier check already determines if the normals are nearly parallel.

You can be here if nan or nbn equal zero and then you divide by zero :)

Is there a specific example you have found that the code change here fixes?

Yep, you can detect this with input provided in #500.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised the example from #500 goes through this function. I assumed from the name it only applied for PBC structures, but the example from the issue is molecular.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

¯_(ツ)_/¯

@foxtran foxtran force-pushed the fix/div_by_zero_at_geoopt branch from e49ab56 to dbafc6e Compare February 10, 2025 21:02
@foxtran foxtran force-pushed the fix/div_by_zero_at_geoopt branch from dbafc6e to ecabb30 Compare February 10, 2025 21:03
@foxtran
Copy link
Contributor Author

foxtran commented Feb 10, 2025

@Albkat, can we merge it?

Copy link
Member

@Albkat Albkat left a comment

Choose a reason for hiding this comment

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

LGTM

@Albkat Albkat merged commit 40c757e into grimme-lab:main Feb 10, 2025
17 checks passed
@foxtran foxtran deleted the fix/div_by_zero_at_geoopt branch February 10, 2025 21:24
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.

GFN-FF optimization fails with NaN gradient norm
3 participants