Skip to content

Commit

Permalink
instllation using uv
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelgarcia committed Oct 24, 2024
1 parent 4a1a45a commit f106681
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 28 deletions.
75 changes: 57 additions & 18 deletions installation_tips/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
## Installation tips

If you are not (yet) an expert in Python installations (conda vs pip, mananging environements, etc.),
here we propose a simple recipe to install `spikeinterface` and several sorters inside an anaconda
environment for windows/mac users.
If you are not (yet) an expert in Python installations, a main difficulty is choosing the installation procedure.
The main ideas you need to know before starting:
* python itself can be distributed and installed many many ways.
* python itself do not contain so many features for scientifique computing you need to install "packages".
Numpy, scipy, matplotlib, spikeinterface, ... are python packages that have a complicated dependency graph between then. "uv"
* installing package can be distributed and installed several ways (pip, conda, uv, mamba, ...)
* installing many packages at once is challenging (because of the depenency graph) so you need to do it in an "isolated environement"
to not destroy any previous installation. You need to see an "environement" as a sub installtion in dedicated folder.

Choosing the installator + a environement manager + a package installer is a nightmare for beginners.
The main options are:
* use "anaconda" that do everything. The most popular but bad idea because : ultra slow and agressive licensing (not free anymore)
* use python from the system or python.org + venv + pip : good idea for linux users.
* use "uv" : a new, fast and simple. We recommand this for beginners on evry os.

Here we propose a steps by step recipe for beginers based on "uv".
We used to propose here a solution based on anaconda. It is kept here for a while but we do not recommand it anymore.


This environment will install:
* spikeinterface full option
* spikeinterface-gui
* phy
* tridesclous
* kilosort4

Kilosort, Ironclust and HDSort are MATLAB based and need to be installed from source.

### Quick installation

Steps:
1. On macOS and Linux. Open a terminal and do
`$ curl -LsSf https://astral.sh/uv/install.sh | sh`
1. On windows. Open a powershell and do
`powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"`
2. exit session and log again.
3. Download with right click + save this file corresponding in "Documents" folder:
* [`requirements_stable.txt`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/requirements_stable.txt)
4. open terminal or powershell
5. `uv venv si_env --python 3.11`
6. `source `source si_env/bin/activate` (you should have `(si_env)` in your terminal)
7. `uv pip install -r Documents/requirements_stable.txt`

1. Download anaconda individual edition [here](https://www.anaconda.com/download)
2. Run the installer. Check the box “Add anaconda3 to my Path environment variable”. It makes life easier for beginners.
3. Download with right click + save the file corresponding to your OS, and put it in "Documents" folder
* [`full_spikeinterface_environment_windows.yml`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/full_spikeinterface_environment_windows.yml)
* [`full_spikeinterface_environment_mac.yml`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/full_spikeinterface_environment_mac.yml)
4. Then open the "Anaconda Command Prompt" (if Windows, search in your applications) or the Terminal (for Mac users)
5. If not in the "Documents" folder type `cd Documents`
6. Then run this depending on your OS:
* `conda env create --file full_spikeinterface_environment_windows.yml`
* `conda env create --file full_spikeinterface_environment_mac.yml`

More detail on [uv here](https://github.com/astral-sh/uv).

Done! Before running a spikeinterface script you will need to "select" this "environment" with `conda activate si_env`.
## Installing before release

Note for **linux** users : this conda recipe should work but we recommend strongly to use **pip + virtualenv**.
Some tools in the spikeinteface ecosystem are getting regular bug fixes (spikeinterface, spikeinterface-gui, probeinterface, python-neo, sortingview).
We are making releases 2 to 4 times a year. In between releases if you want to install from source you can use the `requirements_rolling.txt` file to create the environment. This will install the packages of the ecosystem from source.
This is a good way to test if patch fix your issue.


### Check the installation
Expand Down Expand Up @@ -62,6 +79,28 @@ This script tests the following:
* opening the spikeinterface-gui
* exporting to Phy
### Legacy installation using anaconda (not recomanded)
Steps:
1. Download anaconda individual edition [here](https://www.anaconda.com/download)
2. Run the installer. Check the box “Add anaconda3 to my Path environment variable”. It makes life easier for beginners.
3. Download with right click + save the file corresponding to your OS, and put it in "Documents" folder
* [`full_spikeinterface_environment_windows.yml`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/full_spikeinterface_environment_windows.yml)
* [`full_spikeinterface_environment_mac.yml`](https://raw.githubusercontent.com/SpikeInterface/spikeinterface/main/installation_tips/full_spikeinterface_environment_mac.yml)
4. Then open the "Anaconda Command Prompt" (if Windows, search in your applications) or the Terminal (for Mac users)
5. If not in the "Documents" folder type `cd Documents`
6. Then run this depending on your OS:
* `conda env create --file full_spikeinterface_environment_windows.yml`
* `conda env create --file full_spikeinterface_environment_mac.yml`
Done! Before running a spikeinterface script you will need to "select" this "environment" with `conda activate si_env`.
Note for **linux** users : this conda recipe should work but we recommend strongly to use **pip + virtualenv**.
## Installing before release
Expand Down
28 changes: 18 additions & 10 deletions installation_tips/check_your_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import shutil
import argparse


job_kwargs = dict(n_jobs=-1, progress_bar=True, chunk_duration="1s")

def check_import_si():
import spikeinterface as si

Expand All @@ -13,15 +16,20 @@ def check_import_si_full():

def _create_recording():
import spikeinterface.full as si
rec, sorting = si.toy_example(num_segments=1, duration=200, seed=1, num_channels=16, num_columns=2)
rec.save(folder='./toy_example_recording')
rec, sorting = si.generate_ground_truth_recording(
durations=[200.],
sampling_frequency=30_000.,
num_channels=16,
num_units=10,
seed=2205
)
rec.save(folder='./toy_example_recording', **job_kwargs)


def _run_one_sorter_and_analyzer(sorter_name):
job_kwargs = dict(n_jobs=-1, progress_bar=True, chunk_duration="1s")
import spikeinterface.full as si
recording = si.load_extractor('./toy_example_recording')
sorting = si.run_sorter(sorter_name, recording, output_folder=f'./sorter_with_{sorter_name}', verbose=False)
sorting = si.run_sorter(sorter_name, recording, folder=f'./sorter_with_{sorter_name}', verbose=False)

sorting_analyzer = si.create_sorting_analyzer(sorting, recording,
format="binary_folder", folder=f"./analyzer_with_{sorter_name}",
Expand All @@ -36,12 +44,12 @@ def _run_one_sorter_and_analyzer(sorter_name):
sorting_analyzer.compute("quality_metrics", metric_names=["snr", "firing_rate"])


def run_tridesclous():
_run_one_sorter_and_analyzer('tridesclous')

def run_tridesclous2():
_run_one_sorter_and_analyzer('tridesclous2')

def run_kilosort4():
_run_one_sorter_and_analyzer('kilosort4')



def open_sigui():
Expand Down Expand Up @@ -75,10 +83,10 @@ def _clean():
# clean
folders = [
"./toy_example_recording",
"./sorter_with_tridesclous",
"./analyzer_with_tridesclous",
"./sorter_with_tridesclous2",
"./analyzer_with_tridesclous2",
"./sorter_with_kilosort4",
"./analyzer_with_kilosort4",
"./phy_example"
]
for folder in folders:
Expand All @@ -100,8 +108,8 @@ def _clean():
steps = [
('Import spikeinterface', check_import_si),
('Import spikeinterface.full', check_import_si_full),
('Run tridesclous', run_tridesclous),
('Run tridesclous2', run_tridesclous2),
('Run kilosort4', run_kilosort4),
]

# backwards logic because default is True for end-user
Expand Down
16 changes: 16 additions & 0 deletions installation_tips/requirements_rolling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
numpy<2
jupyterlab
PySide6<6.8
numba
zarr
hdbscan
pyqtgraph
ipywidgets
ipympl
ephyviewer
https://github.com/NeuralEnsemble/python-neo/archive/master.zip
https://github.com/SpikeInterface/probeinterface/archive/main.zip
https://github.com/SpikeInterface/spikeinterface/archive/main.zip[full,widgets]
https://github.com/SpikeInterface/spikeinterface-gui/archive/main.zip
https://github.com/magland/sortingview/archive/main.zip
kilosort
13 changes: 13 additions & 0 deletions installation_tips/requirements_stable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
numpy<2
jupyterlab
PySide6<6.8
numba
zarr
hdbscan
pyqtgraph
ipywidgets
ipympl
ephyviewer
spikeinterface[full,widgets]
spikeinterface-gui
kilosort

0 comments on commit f106681

Please sign in to comment.