-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Slicing IO read_ routines #586
Conversation
Codecov Report
@@ Coverage Diff @@
## main #586 +/- ##
==========================================
- Coverage 87.30% 87.28% -0.02%
==========================================
Files 374 375 +1
Lines 47506 47564 +58
==========================================
+ Hits 41474 41518 +44
- Misses 6032 6046 +14
|
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 played a bit around with this and it looks really cool. Well done!
I don't see a reason to not use this everywhere, i.e. read_energy etc? Would there be objections to this? |
I agree, no objections. I already tested this out on Maybe raise a warning for a while to make users aware that |
One can do: @SileBinder(..., default_slice=-1)
def read_energy(...) which should ensure that it defaults to return the last one, say |
Where should we default to return the last? Everywhere, some of @pfebrer comments related to MD are valid. Note, that a local commit ensures that the default slice is written in the documentation of said routine, so it will automatically be added for the method. |
Wouldn't the default slice return the confusion of the arguments we have removed? I advocate for no defaults on this, then "legacy" code will be more likely to keep doing the same thing in the future. If in the future we decide that another default is better, it will be very difficult to debug changes in the defaults in already written code. I would just issue a warning for some time as @tfrederiksen was suggesting (perhaps keep the current API with a deprecation warning). Also in my case I would spend more time rechecking the documentation for the defaults of each sile than simply specifying what I want 😅 |
This comment was marked as resolved.
This comment was marked as resolved.
By the way I don't know if it would be a good idea to use slices for cases where there is more than one dimension. E.g. in It looks nice but it's a bit hard to know if it makes sense implementationwise because it would no longer be just a simple external iterator on the reading function. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This is a fine idea, I think it could be implemented easily as the subsequent tuple keys are simply applied to the returned arrays. Lets see... |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Would it be so bad to have a |
I am pretty sure that would make sense for all siles that uses the Ok, so default to only the next item, as it is now. The |
I think this is a good suggestion, making it explicit for the user what is looked up. In particular the warning could suggest users to adapt |
Yeah maybe 😅 I guess if |
If all this is for explicitness, wouldn't the current availability of |
I have thought about it, and I have now added this, what do you think? read_geometry.last(*args, **kwargs)
read_geometry.next(*args, **kwargs) to explicitly request the next item, and the last item. Remark that |
Sounds good! But what does |
same as |
Hmm it is very difficult to know what users will think about it. But it doesn't seem it could be harmful in the future to maintain these two properties (fingers crossed haha) so we could have them both. |
@tfrederiksen you might be interested in the latest commit which changes the Probably this should go in ASAP, and then the other siles will come as required. |
if len(blocks) > 0: | ||
return blocks[-1] | ||
return None | ||
return read_block(step_to) |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
if len(blocks) > 0: | ||
return blocks[-1] | ||
return None | ||
return read_block(step_to) |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
Could |
That would be hard for end users, then the users need to read which indices corresponds to which energies, that was why the property dict was used. |
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 think this looks great. After merge I will revisit #573.
Fixed documentation issues and enabled this. Storing sliced objects will also work. Currently nested slicing is not possible. enabled nested with of a sile and changed to SileBinder The sile_read_multiple has been deleted, now the way to do it is SileBinder. This is more versatile and allows better handling. It also patches the documentation. This changes the behaviour of all files using this. By default a read_* with the SileBinder will only read the next entry, however to read multiple one should use read_*[...] for slicing the data. The bound method will try and be smart about only reading the needed elements, there is a bit of overhead, but largely it should be fast. All tests are functional again. Signed-off-by: Nick Papior <[email protected]>
if the file reads raises something, then announce Signed-off-by: Nick Papior <[email protected]>
Signed-off-by: Nick Papior <[email protected]>
Signed-off-by: Nick Papior <[email protected]>
Signed-off-by: Nick Papior <[email protected]>
This makes the read-functionalities more useable to retain other parts of the information. All tests are functional again. Signed-off-by: Nick Papior <[email protected]>
Signed-off-by: Nick Papior <[email protected]>
Added lots of typehints in the code, primarily in the io code base. Changed the way the siesta.stdout siles handle data. They now rely on the SileSlicer and thus can be sliced upon calling. It makes the code a little simpler but also highligted some problems. In particular the problem arise when the return function needs to do different things depending on whether the file is done reading, or not. The defaults for stdoutSileSiesta has changed to read the next entry in the file. This is in contrast to the way it was. It will require users to adapt! the reason for this can be found in the discussion in #586. This streamlines the usage across the different parts of the IO handling. Signed-off-by: Nick Papior <[email protected]>
somewhat, more documentation would be great.
CHANGELOG