Skip to content

Conversation

@h-mayorquin
Copy link
Collaborator

In the context of #1602 and NeuralEnsemble/python-neo#1265.

This does not go all the way to use native python buffers which is what we have done in those PR but it moves closer in that direction. I added a further test.

@h-mayorquin h-mayorquin added the core Changes to core module label Jun 23, 2023
@h-mayorquin h-mayorquin self-assigned this Jun 23, 2023
channel_indices: Union[List, None] = None,
) -> np.ndarray:
traces = self._timeseries[start_frame:end_frame]
data = np.memmap(self.datfile, self.dtype, mode="r", offset=self.file_offset, shape=self.shape)
Copy link
Member

Choose a reason for hiding this comment

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

Hi Ramon.
We should use the same trick as in neo. Open the file in init an d create the memmap on the fly.
open/close on network drive has a cost!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made the two of them but I wanted to make smaller PRs:

#1742

@DradeAW
Copy link
Contributor

DradeAW commented Jun 24, 2023

I don't understand why opening the memmap on get_traces is more efficient?

Opening and closing comes at a cost, but once opened it should only be a pointer to the file?
How is this more efficient?

@h-mayorquin
Copy link
Collaborator Author

h-mayorquin commented Jun 24, 2023

@DradeAW
Long story short, the memmaps are not released (and theres is no API to release them) and lead to a linear memory increase. This is one way that we find of avoiding this problem. Opening memmaps and files is not that expensive when compared to most operations except on the network case which is what Sam is talking about.

@DradeAW
Copy link
Contributor

DradeAW commented Jun 24, 2023

the memmaps are not released

Interesting, I always thought that calling memmap.close() inside __del__ took care of this issue. I'm gonna have to look into this for my own code!

Thank you :)

@h-mayorquin
Copy link
Collaborator Author

You can read here why there is no unified interface:

numpy/numpy#13510

@h-mayorquin
Copy link
Collaborator Author

I am thinking on writing a blogpost about it but June is a very busy time for contracts. Maybe next month.

@samuelgarcia samuelgarcia added this to the 0.98.0 milestone Jun 27, 2023
@samuelgarcia
Copy link
Member

I propose to close this and merge #1742 instead.

@h-mayorquin
Copy link
Collaborator Author

Fine by me, I added the close flag on the other PR.

@h-mayorquin h-mayorquin deleted the make_binary_recording_memmap_efficient branch June 27, 2023 09:41
@h-mayorquin h-mayorquin restored the make_binary_recording_memmap_efficient branch June 27, 2023 09:41
@h-mayorquin h-mayorquin deleted the make_binary_recording_memmap_efficient branch June 27, 2023 09:41
@alejoe91 alejoe91 removed this from the 0.98.0 milestone Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants