Setup Libraries#

These instructions install miniconda and the requisite libraries for the tutorial in a conda environment, which is an independent python installation.

Jupyter has the similar concept of kernels, which are independent execution environments. They don’t even have to be Python, kernels for other languages exist as well.

By loading a separate kernel for each project, we avoid the complication of different components/projects having weird interactions, ultimately helping reproducibility.

We first produce a new conda environment with the libraries we require, then we tell Jupyter about this new environment with the ipython executable

NOTE: This step may take a little while



# Download mambaforge install script
if [[ ! -f $HOME/ ]]; then
    wget -O $HOME/ || { echo "Failed to download the mambaforge installation script."; exit $?; }

# Install miniconda3
if [[ ! -d $HOME/mambaforge ]]; then
    chmod u+x $HOME/
    bash $HOME/ -b -f -u -p $HOME/mambaforge

echo "Sourcing the conda and mamba setup scripts..."
source $HOME/mambaforge/etc/profile.d/
source $HOME/mambaforge/etc/profile.d/

# # Not updating miniconda since that results in an issues with mamba 
# #
# echo "Updating the miniconda3 release..."
# conda update -y -n base -c defaults conda 2>&1 || { echo "Failed to properly update miniconda3."; exit $?; }

# Create conda environment
if [[ ! -d $HOME/mambaforge/envs/$KERNEL_NAME ]]; then
    echo "Creating the miniconda3 environment \"$KERNEL_NAME\"..."
    mamba env create -n $KERNEL_NAME -f environment.yml || { echo "Failed to properly setup the environment \"$KERNEL_NAME\" using mamba."; exit $?; }
echo "Activating the kernel \"$KERNEL_NAME\"..."
conda activate $KERNEL_NAME || { echo "Failed to activate the kernel \"$KERNEL_NAME\"."; exit $?; }

python -m ipykernel install --name $KERNEL_NAME --user
echo "Installed \"$KERNEL_NAME\"!"
Sourcing the conda and mamba setup scripts...
Activating the kernel "machine-learning-hats"...
Installed kernelspec machine-learning-hats in /home/cms.rkansal/.local/share/jupyter/kernels/machine-learning-hats
Installed "machine-learning-hats"!


If successful, you should see something similar to the following:

Installed "machine-learning-hats"!

The new kernel you just made will then show up in the various Jupyter notebooks after refreshing the page.