-
Notifications
You must be signed in to change notification settings - Fork 2
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
Possible flag-based interface to reduce duplication #11
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #11 +/- ##
==========================================
+ Coverage 82.45% 88.13% +5.68%
==========================================
Files 22 25 +3
Lines 1533 1610 +77
==========================================
+ Hits 1264 1419 +155
+ Misses 269 191 -78 ☔ View full report in Codecov by Sentry. |
Some comments on integration:
|
… linear mesh, tighten test tolerances
Quick comment on the dispatches:
Otherwise, there is always the risk of overdoing it. I trust you on this, but I just wanted to point out alternatives to introducing too many types. Sometimes properties can also be elegantly distinguished by plain symbols. This has disadvantages (e.g. multiple dispatch does not work), but has advantages, too (e.g. seamless integration with I'll do a more careful review during the review (if I get raound). |
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.
Quick comments.
|
||
EvaluationSpace | ||
RealSpace | ||
FourierSpace | ||
``` | ||
|
||
## Functions | ||
|
||
```@docs | ||
load_psp_file |
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.
This feels a bit like a too overwhelming method zoo. People will generally not remember all this. Let's brainstorm if we can simplify by show functions on clever types or so.
@@ -1,42 +1,53 @@ | |||
# # Tutorial | |||
# |
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.
Nice docs, super valuable.
src/common/hankel_transform.jl
Outdated
@@ -14,9 +14,9 @@ where ``j_l(x)`` is the spherical Bessel function of the first kind at order ``l | |||
hankel_transform | |||
@inbounds function hankel_transform(f::AbstractVector, l::Int, r::AbstractVector, | |||
dr::Union{Real,AbstractVector}; i_start=firstindex(f), | |||
i_stop=lastindex(f)) | |||
i_stop=lastindex(f), integrator=simpson) |
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.
Simpson is a function. Breaks a bit with the usual pattern where algorithm selection is done by types. We should at least capitalise it (to be able to switch to a struct). Lets discuss.
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, I was also thinking about this and more generally about the integration interface yesterday when I was doing some testing on the integrators. You're right that these should be type flags as well. Could take some inspiration from NumericalIntegration.jl, though I'm not sure I'd want to have it as a dependency.
Regarding the kwarg thing: Inside pspio we probable want to deconstruct (via a dispatch) to positional args, but let's discuss if this mskes sense. |
Proposal
While working to integrate PseudoPotentialIO into DFTK, there were a few points where having a dispatch flag-based interface in PPIO would help to reduce code duplication, namely
Here, I define a set of
AbstractPsPQuantity
structs:which are used to select dispatches for a variety of functions:
This reduces code duplication to some extent in PPIO and should allow for additional quantities to be added without much effort.
Additional features and changes
qe_simpson
,cp90_simpson
,abinit_corrected_trapezoid
integratorsdotprod
integrator torectangle
identifier
field toPsPFile
s (defaults to filename when loaded from a file)checksum
andidentifier
optional fields inAbstractPsP
s; this information may not be available / correct if the psp is constructed by hand or modified, e.g. in the DFTK HGH sensitivity test / exampleBase.==
andBase.hash
dispatches fromAbstractPsP
now thatchecksum
is optionalPsPFile
constructors to have two common dispatches:io::IO
andpath::AbstractString
(which calls down toio::IO
and passes along the filename)TODOs
LocalPotentialCorrection
flagserf(r) Z / r
local potential correctionr
as an argument to all the integrators (cp90_simpson
needs it to avoidr=0
, future integrators might use it as well)dr
and use it rather than finite differencesr[i+1] - r[i]
or similar)