Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Goal: Detail how to update an R Conda environment so it can be used as a kernel within ARCC’s Jupyter service.


Table of Contents
stylenone

What is Jupyter and What is a Kernel?

Note
  • Jupyter is a large umbrella project that covers many different software offerings and tools, including the popular Jupyter Notebook and JupyterLab web-based notebook authoring and editing applications.

  • Kernels are programming language specific processes that run independently and interact with the Jupyter Applications and their user interfaces.

    • They can be considered as the computational engine for notebooks.

    • The kernel process is a standalone process that runs in the background and executes the code that you write in your notebooks. The kernel process is responsible for running the code and returning the results to the frontend.

  • ARCC provides the Jupyter with OnDemand workshop.


General Process

Info

The general process involves updating the Conda environment to include kernel related packages, and then configuring the kernel spec to allow it to be picked up by the Jupyter service.

Info
  1. Activate you R Conda Environment.

  2. Start R.

  3. Install the IRkernel package.

  4. Exit R.

  5. Deactivate your Conda environment.

  6. Copy the created kernelspec into your home ~/.local/share/jupyter/kernels/ folder.

  7. Update the kernel.json.


Install the IRkernel package

Info

Activate you R Conda Environment and start R.

Code Block
[]$ module load miniconda3/24.3.0
[]$ conda activate /project/<project-name>/software/conda-envs/r_4.3.3_env/
(/project/<project-name>/software/conda-envs/r_4.3.3_env) []$ R
> install.packages('IRkernel')
...
also installing the dependencies ‘fastmap’, ‘fansi’, ‘utf8’, ‘htmltools’, ‘pillar’, ‘base64enc’, ‘repr’, ‘evaluate’, ‘IRdisplay’, ‘pbdZMQ’, ‘crayon’, ‘jsonlite’, ‘uuid’, ‘digest’
...
* DONE (IRkernel)

Created kernelspec folder

Info

Installing the IRkernel package will create a kernel spec that we can use.

This can be found under the Conda environment location, under: lib/R/library/IRkernel/kernelspec/

Code Block
[]$ ls /project/<project-name>/software/conda-envs/r_4.3.3_env/lib/R/library/IRkernel/kernelspec/
kernel.js  kernel.json  logo-64x64.png  logo-svg.svg
Code Block
[salexan5@mblog2 ~]$ cat /project/<project-name>/software/conda-envs/r_4.3.3_env/lib/R/library/IRkernel/kernelspec/kernel.json
{"argv": ["R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
 "display_name":"R",
 "language":"R"
}

Configure Your Jupyter Environment

Note

If you haven’t used the Jupyter service, then you might not have, and thus will need to create the following folders:

.local/share/jupyter/kernels/

Info

Copy the created kernelspec into your home:

Code Block
[~]$ cd .local/share/jupyter/kernels/
[]$ mkdir r_4.3.3
[]$ cd r_4.3.3
[]$ cp /project/<project-name>/software/conda-envs/r_4.3.3_env/lib/R/library/IRkernel/kernelspec/* .
Info

Update the kernel.json file to:

  • point to the Conda environment’s version of R.

  • give this kernel a unique display name.

Code Block
[]$ cat kernel.json
{"argv": ["/project/<project-name>/software/conda-envs/r_4.3.3_env/bin/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
 "display_name":"R_4.3.3 (local)",
 "language":"R"
}

Start Jupyter

Info

From OnDemand start a Jupyter session.

Notice how the newly configured kernel is available.

image-20240731-140000.pngImage Removedimage-20240826-184721.pngImage Added

Within a Notebook

Within a cell try:

Code Block
.libPaths()
Code Block
# Cell Output:
'/cluster/medbow/project/<project-name>/software/conda-envs/r_4.3.3_env/lib/R/library'
Code Block
write.table(installed.packages()[,c(1,2,3:4)])
Code Block
# Cell Output:
"Package" "LibPath" "Version" "Priority"
"base" "base" "/cluster/medbow/project/<project-name>/software/conda-envs/r_4.3.3_env/lib/R/library" "4.3.3" "base"
...
"vctrs" "vctrs" "/cluster/medbow/project/<project-name>/software/conda-envs/r_4.3.3_env/lib/R/library" "0.6.5" NA
Info

Note the library path is that of the Conda environment: /project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library