SpikeInterface / SpikeInterface/spikeinterface

SpikeInterface and Kilosort4 compatibility

Open
#3,901 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

sorters
Dominant language
Python
Stars
847
Forks
280
Avg merge
3d 9h
Merged PRs (30d)
29

Description

Hi,

Kilosort4 seems to change very quickly and I seem unable to find a combination of spikeinterface/kilosort4 versions with which I do not encounter problems (but the problems change depending on the version combination). It would be really nice to have within the docs the version of kilosort with which the version of spikeinterface has been tested with.

As for my current compatibility issue, I was trying with spikeinterface 0.102.2 and kilosort 4.0.32 (April 16th, but there's already 4 new pypi releases since then...). I have 2 problems:

  1. I had to change the code of spikeinterface because the API of cluster_spikes has changed
  2. The code attempts to allocate 150Gb of memory at the saving step (so close to working...)

The relevant code is below and the spikeinterface log is attached. As I see it, my options are the following:

  1. Use an older version of kilosort (that should at least solve probem 1)) and just hope that it also solves problem 2). But which version to use (I had already attempted another version pair previously with other problems) ?
  2. Just wait for a new version of spikeinterface and hope for the best
  3. Attempt to solve problem 2) by modifying the code myself, but this is not maintainable long term.
#MY MODIFICATION
clusters = cluster_spikes(**cluster_spikes_kwargs)
try:
    clu, Wall = clusters
except Exception:
    clu, Wall, _, _ = clusters #Kilosort now returns a 4 element tuple...
#End of my modification

if params["skip_kilosort_preprocessing"]:
    ops["preprocessing"] = dict(
        hp_filter=torch.as_tensor(np.zeros(1)), whiten_mat=torch.as_tensor(np.eye(recording.get_num_channels()))
    )

print("Before save sorting", st.shape, clu.shape, Wall.shape) #Just to see

#This fails (trying to allocate 150Gb) as we have 15*10^6 spikes and near 400 channels

_ = save_sorting(
    ops=ops,
    results_dir=results_dir,
    st=st,
    clu=clu,
    tF=tF,
    Wall=Wall,
    imin=bfile.imin,
    tic0=tic0,
    save_extra_vars=save_extra_vars,
    save_preprocessed_copy=save_preprocessed_copy,
)

####This happends in kilosort save to phy line 420 of io.py

pc_features, pc_feature_ind = make_pc_features(
        ops, spike_templates, spike_clusters, tF
        )

#### Which calls (indirectly) get_data_cpu of clustering_qr.py

dd = torch.zeros((nspikes, nchan, nfeatures)) #Which is too big for memory

spikeinterface_log.json

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached spikeinterface log and the Kilosort call sites shown in the report, especially cluster_spikes, save_sorting, kilosort io.py line 420, and clustering_qr.py's get_data_cpu. Check the supported SpikeInterface and Kilosort versions and document tested combinations. Done means the compatibility guidance is reproducible and the reported API and memory behavior is clearly characterized.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.