-
Notifications
You must be signed in to change notification settings - Fork 85
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
[WIP] Get DFTK fully generic in the floating point type #59
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, victory is near! Left a few comments.
@@ -22,7 +23,7 @@ function energy_ewald(lattice, recip_lattice, charges, positions; η=nothing) | |||
if η === nothing | |||
# Balance between reciprocal summation and real-space summation | |||
# with a slight bias towards reciprocal summation | |||
η = sqrt(sqrt(1.69 * norm(recip_lattice ./ 2π) / norm(lattice))) / 2 | |||
η = T(sqrt(sqrt(1.69 * norm(recip_lattice ./ 2π) / norm(lattice))) / 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you more generally make sure that there are no implicit conversions to float64? Should it be T(1.69) and T(2pi) everywhere there are constant literals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do still not have a better solution here ... if you find one let me know.
fedfef6
to
eef5cb7
Compare
@antoine-levitt I'm waiting for your final verdict and then this goes in 😄. |
src/core/occupation.jl
Outdated
|
||
n_electrons_integration = compute_n_elec(εF) | ||
if abs(n_electrons_integration - n_electrons) > sqrt(eps(real(T))) | ||
@warn("`find_occupation_gap_zero_temperature` has a mismatch in number " * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong copy-paste here in the error message. Shouldn't these be asserts? It really shouldn't happen...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well but it does for some floating point types ... albeit the error is really neglible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no, scratch that ... that's at the other instance, here it can be a proper assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really ? The other one should really be fine also... that's in float16 I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's for more accurate types like Double32 or Double64. I think the reason is because their density of representable floats is plainly different than for IEEE floats, such that eps(T)
might not always be the best metric, or put another way: The prefactor for an eps(T)
error bound might just be different, not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's what I meant by "diagnostic tool". So I did a quick grep for backslash, things that might get us into trouble is pretty much all of PspHgh, SphericalHarmonics, bzmesh, A_coeff(n) = (-1)^n / (factorial(n) * 4^n * sqrt(π))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see ... puh ... I can't be bothered to fix that all here. I made a separate issue for that, see #60.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm ... but some of that might not actually matter that much, because it's later assigned to arrays of the appropriate type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah but you lose precision, which matters if we want to push below Float64. Let's do that later, but keep the assert (which is pretty useful precisely because of this kind of things; in fact a better check would be to check against eps^2/3 or something)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I dropped the relevant commit.
@@ -7,7 +7,7 @@ include("testcases.jl") | |||
# TODO There is a lot of code duplication in this file ... once we have the ABINIT reference | |||
# stuff in place, this should be refactored. | |||
|
|||
function run_silicon_redHF(;Ecut=5, test_tol=1e-6, n_ignored=0, grid_size=15, scf_tol=1e-6) | |||
function run_silicon_redHF(T; Ecut=5, test_tol=1e-6, n_ignored=0, grid_size=15, scf_tol=1e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T=Float64
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then also at other places like in run_silicon_lda
and so on ...
so far we explicitly specify the type everywhere, which I think is actually what you want.
Left of couple of nitpicking comments, but otherwise good to go! |
eef5cb7
to
1e94e8a
Compare
1e94e8a
to
15ff911
Compare
15ff911
to
e6b1bd4
Compare
1906544
to
11dc169
Compare
As usual I'm thoroughly confused by the package system. I get
on this branch |
Ok ... I did some digging. Essentially all these problems boil down to the fact that I propose the following: I'll open an issue asking about registration of the package (see 11 in FourierTransforms.jl). I would understand if that's not done to General, because it really is a little immature. In that case we have four options:
I personally prefer to the third option. It surely puts some maintenance burden on us, however. What are your thoughts? |
As usual I'm for the simplest and dirtiest solution :-p copy the files. It's fine under MIT (with proper attribution of course), it's just a temporary workaround to try stuff and it's the most flexible solution (eg if we want to change things in the FFT code) |
11dc169
to
3d899a7
Compare
Hmm ... ok ... after some thoughts I agree with you. I closed the issue at FourierTransforms and added the files as a copy. |
3d899a7
to
d13cc8e
Compare
This PR will get DFTK agnostic to the floating point type used.