Setup¶
Python is a popular language for scientific computing, and a frequent choice for machine learning as well.
This workshop will use a Python environment containing JupyterLab and the necessary dependencies as the primary interface for all practical sessions. You are encouraged to follow the local installation option. Google Colab will be available as a fallback option if needed.
Please set up your Python environment at least a day in advance of the workshop. If you encounter problems with the installation procedure, attend the pre-workshop setup session for assistance, so that you are ready to go as soon as the workshop begins.
Local installation¶
Important
You have different options:
Use pip and virtual environments: If you have
gitin your terminal and are comfortable using virtual environments and have a working Python interpreter (at least version 3.10 or above), orUse Miniforge / pixi and conda environments: Recommended for Windows users, and users who don’t have tools like a Python interpreter,
gitin their devices.
Once you have done either, proceed to getting the notebooks. Finally download the datasets
Using pip¶
Open a terminal (Mac/Linux) or Command Prompt (Windows) and run the following commands.
Create a virtual environment called
workshop:
python3 -m venv workshop
Activate the newly created virtual environment:
source workshop/bin/activate
workshop\Scripts\activate
Remember that you need to activate your environment every time you restart your terminal!
Install the required packages:
Once you have activated your environment, you can install all the required packages for this workshop using the following command:
pip install -r https://raw.githubusercontent.com/sweden-ai-factory/gen-ai-for-life-science/refs/heads/main/requirements.txt
Using Miniforge¶
In this page, we give indications about how to install Miniforge and use conda/mamba.
The first step is to install Miniforge, which is a modified version of Miniconda using by default the community driven conda-forge channel.
Download the installer using curl or wget or your favorite program. For eg:
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
or
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
Execute the installer and initialize conda:
bash Miniforge3-$(uname)-$(uname -m).sh -b
$HOME/miniforge3/bin/conda init --all
On Windows, download the Windows installer and follow the instructions given in https://github.com/conda-forge/miniforge.
Open an Anaconda Prompt and run conda init --all.
When it’s done, open a new terminal (click on ctrl-alt-t) and check that the
line in the new terminal starts with (base). The indication (base) means
that you use the base “environment”.
However, working in the base environment is not a good practice and it is
better to disable the auto activation with:
conda config --set auto_activate_base false
Tip
If you have a GPU, you might want to comment pytorch and uncomment pytorch-gpu in the
environment.yaml file.
Create an environment called
workshop:
conda env create --yes -f environment.yaml
Activate the environment:
conda activate workshop
Using pixi¶
Install Pixi by following the installation instructions.
Download https://raw.githubusercontent.com/sweden-ai-factory/gen-ai-for-life-science/refs/heads/main/pixi.toml, and use one the below commands
pixi shell # If you don't have a GPU
pixi shell -e gpu # If you have a GPU
Use either pixi shell to enter the environment,
or prefix commands with pixi run.
Getting the Notebooks¶
Once you have git installed, enter the following command into your terminal:
git clone https://github.com/sweden-ai-factory/gen-ai-for-life-science
The repository will be cloned to a directory named gen-ai-for-life-science
which will also contain the notebooks. If you want to get the latest copy,
you update this repository by using
cd gen-ai-for-life-science
git pull
Launch JupyterLab¶
From within your virtual environment (using activate script) or conda
environment (using conda activate workshop / pixi shell) navigate to the
notebooks directory and launch JupyterLab
cd gen-ai-for-life-science/notebooks
jupyter-lab
which should also open JupyterLab.
Fallback option: Google colab¶
Alternatively you can use Google colab.
If you open a Jupyter notebook here, most of the required packages are already pre-installed. Data will be downloaded/streamed automatically. Make sure that under Runtime > Change runtime type, your “Hardware accelerator” is set to T4 GPU or equivalent (you may need to do this for each notebook).
Downloading the required datasets¶
Download the datasets for this workshop here.
Unzip these file and place them in your repository.
Checking Your Environment¶
Once in, you can verify your setup by running:
import torch
print("CUDA available:", torch.cuda.is_available())
print("GPU device:", torch.cuda.get_device_name(0) if torch.cuda.is_available() else "None")
print("PyTorch version:", torch.__version__)
Downloading the required datasets¶
Download the datasets for this workshop here.
Unzip these file and place them in your repository.