Notebooks, Python, PyROOT

Notebooks can be a very nice tool to work interactively and share your interactive work with others. You can run the notebook server yourself to work with them.

Notebooks are a front-end interface and can work with many different backends, usually called “kernels”:

  • Python 3

  • C++ (through ROOT Cling)

  • R

  • Julia

Create a Virtual Environment

A Python virtual environment is a sort of sandbox for running python software with specific versions. It can be used to keep your work together in one place and allows you to install additional Python packages, for example using conda and pip.

We’ll set one up using the

$> ssh -o "ProxyJump"
conda create --prefix /data/your_project/your_username/my_venv

Activate the Virtual Environment

$> conda activate /data/your_project/your_username/my_venv

Install JupyterLab

(my_venv) $> conda install -c conda-forge jupyterlab

Start the Notebook

The notebook application will start in you home directory by default, so for convenience copy the example notebook there:

$> cp /project/datagrid/username/notebook_example.ipynb ~/

Then start the notebook server:

(my_venv) $> jupyter lab --no-browser
[I 11:37:09.555 LabApp] Writing notebook server cookie secret to /run/user/8902/jupyter/notebook_cookie_secret
[I 11:37:16.802 LabApp] JupyterLab extension loaded from /path/to/venvs/jpylab_venv/lib/python3.6/site-packages/jupyterlab
[I 11:37:16.802 LabApp] JupyterLab application directory is /path/to/venvs/jpylab_venv/share/jupyter/lab
[W 11:37:16.803 LabApp] JupyterLab server extension not enabled, manually loading...
[I 11:37:16.806 LabApp] JupyterLab extension loaded from /path/to/venvs/jpylab_venv/lib/python3.6/site-packages/jupyterlab
[I 11:37:16.806 LabApp] JupyterLab application directory is /path/to/venvs/jpylab_venv/share/jupyter/lab
[I 11:37:16.806 LabApp] Serving notebooks from local directory: /path/to/venvs
[I 11:37:16.806 LabApp] The Jupyter Notebook is running at:
[I 11:37:16.807 LabApp] http://localhost:8888/?token=4368047ef5b6622ba249efd0135a24cba7e4909c28e94b49
[I 11:37:16.807 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 11:37:16.807 LabApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:

Look at the port in the final line, in this case 8888; the token also matters

SSH Port Forwarding

On the machine where you want to run the browser, i.e. your laptop:

$> ssh -o "ProxyJump" -L <port>:localhost:<port>

For more details on how to use ssh, see the ssh guide.

Work with the Notebook

Open a browser on your local machine to the link in the final line and you should see something like this: notebook

Then use the left pane to navigate to where you copied the example notebook and open it by double clicking on it. It should then look like this: notebook

Few Handy Things

  • use Shift + ENTER to execute a cell

  • notebooks can be version controlled

  • notebooks can be shared with other people