-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
units
as parameter in read_*
#726
Conversation
When you brought up the MHz question, I was also thinking about this. I can't really figure out if this is a good idea or not. There are soo many places where values have units. And I am worried it might end up being confusing, and error-prone. |
I think the use case is quite clear for the HFI. Here some people will want to work with "MHz" as this is a more natural energy scale without having to worry about making conversion errors if we force it to "eV" at the interface. |
It also makes it explicit for the user what the units are (both in the source file as well as after import in sisl). |
OK, I see your point that it may not be relevant to implement this everywhere. But at least for |
Yeah, probably we should do it. But... :) If we are going to do this, we need to figure out how to do it for multiple return values, say it also returned some coordinate (length), how should we deal with that? |
Do you have an example of that? I guess we can stick to sisl defaults if it is about reading |
A simple example would be to read the Hamiltonian, it uses the coordinates and an energy. |
But reading this one gets a sisl object |
Eventually, one could have multiple parameters: |
Yes, but I would consider We could imagine a decorator enabling the @units_handling # not the best word
def read_hyperfine_interaction(...)
sile.read_hyperfine_interaction(units=("MHz", "Ang")) then internally the units = {"energy": "MHz", "length": "Ang"} or similar? |
We could also always add the quantity to the parameter? |
Wrong button, sorry! |
you mean that users should do |
I mean that this PR should be changed to |
I am not in favor of having |
OK, then what about accepting both str and dict as inputs for |
Yes, this was my idea, here I don't think we need anymore (other than changing it to |
My idea of the decorator was to convert the |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #726 +/- ##
==========================================
+ Coverage 86.86% 86.87% +0.01%
==========================================
Files 399 399
Lines 50948 50998 +50
==========================================
+ Hits 44257 44306 +49
- Misses 6691 6692 +1 ☔ View full report in Codecov by Sentry. |
Should we also allow calls without the keyword, i.e., |
good question, no, I think it would be wise to forcefully ask the user to write |
I've given the decorator a try. What do you think? |
I'm facing some problems that I think is related to the other decorators. Wouldn't it be simpler with just a function like this? def read_hyperfine_coupling(units="eV"):
units = sisl.unit.unit2dict(units) Then it is perhaps also easier to see what is going on, as compared to @units2dict
def read_hyperfine_coupling(units="eV"):
assert isinstance(units, dict) |
fine for me, I'll probably rename |
The decorator requires an inspection pass. So lets just keep it as is. :) EDIT: I mean, as you suggest :) |
60aad08
to
a1d3321
Compare
unit
as parameter in read_*
units
as parameter in read_*
Should we merge this now, and take it from there? |
OK, maybe the docstrings just need an update with |
Yeah, later we should change this to use typing constructs. :) |
But I think this is fine |
fd29bf5
to
6dd18de
Compare
OK, I think it is ready now. |
Merged! Thanks a lot @tfrederiksen |
Although sisl works with
eV
as the default energy unit, users may just use sisl as an interface and keep original units (or some other choice).Here a suggestion for ORCA. I could extend to the other interfaces too.