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

[WIP] Get DFTK fully generic in the floating point type #59

Merged
merged 16 commits into from
Nov 18, 2019

Conversation

mfherbst
Copy link
Member

@mfherbst mfherbst commented Nov 14, 2019

This PR will get DFTK agnostic to the floating point type used.

  • Get DoubleFloats to work
  • Tests
  • Merge magnesium examples

@mfherbst mfherbst added the feature New feature or request label Nov 14, 2019
Copy link
Member

@antoine-levitt antoine-levitt left a 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.

examples/magnesium_supercell.jl Outdated Show resolved Hide resolved
examples/magnesium_supercell.jl Outdated Show resolved Hide resolved
src/core/PlaneWaveBasis.jl Outdated Show resolved Hide resolved
src/core/PlaneWaveBasis.jl Outdated Show resolved Hide resolved
src/core/PlaneWaveBasis.jl Outdated Show resolved Hide resolved
src/core/energy_ewald.jl Outdated Show resolved Hide resolved
@@ -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)
Copy link
Member

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?

Copy link
Member Author

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.

src/core/generic_fftn.jl Outdated Show resolved Hide resolved
src/core/lobpcg_hyper_impl.jl Show resolved Hide resolved
src/core/self_consistent_field.jl Show resolved Hide resolved
@mfherbst
Copy link
Member Author

@antoine-levitt I'm waiting for your final verdict and then this goes in 😄.


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 " *
Copy link
Member

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...

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@antoine-levitt antoine-levitt Nov 16, 2019

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(π))

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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)

Copy link
Member Author

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)
Copy link
Member

Choose a reason for hiding this comment

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

T=Float64?

Copy link
Member Author

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.

@antoine-levitt
Copy link
Member

Left of couple of nitpicking comments, but otherwise good to go!

@antoine-levitt
Copy link
Member

As usual I'm thoroughly confused by the package system. I get

(v1.3) pkg> resolve
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package FourierTransforms [65ccaadd]:
 FourierTransforms [65ccaadd] log:
 ├─FourierTransforms [65ccaadd] has no known versions!
 └─restricted to versions * by DFTK [acf6eb54] — no versions left
   └─DFTK [acf6eb54] log:
     ├─possible versions are: 0.0.1 or uninstalled
     └─DFTK [acf6eb54] is fixed to version 0.0.1

on this branch

@mfherbst
Copy link
Member Author

mfherbst commented Nov 17, 2019

Ok ... I did some digging. Essentially all these problems boil down to the fact that FourierTransforms is unregistered and there seems to be no clean way to depend on unregistered packages from registered packages (as ours is now).

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:

  • Do not allow for the generic stuff at all
  • Copy the files to DFTK
  • Register a fork in MolSim under a temporary name such that it is clear its a workaround
  • Register the package in MolSim as is. Requires some coordination with the authors to avoid registering different states under the same version or different versions for the same package state.

I personally prefer to the third option. It surely puts some maintenance burden on us, however.

What are your thoughts?

@antoine-levitt
Copy link
Member

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)

@mfherbst
Copy link
Member Author

Hmm ... ok ... after some thoughts I agree with you. I closed the issue at FourierTransforms and added the files as a copy.

@mfherbst mfherbst merged commit 8dab726 into master Nov 18, 2019
@mfherbst mfherbst deleted the fully-generic branch November 18, 2019 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants