JupyterNotebook: Difference between revisions
No edit summary |
|||
Line 21: | Line 21: | ||
|prompt=(jupyter_py3)[name@server $] | |prompt=(jupyter_py3)[name@server $] | ||
|pip install jupyter}} | |pip install jupyter}} | ||
In your virtual environment, create a wrapper script that can launch Jupyter notebook | |||
{{Command | |||
|prompt=(jupyter_py3)[name@server $] | |||
|echo '#!/bin/bash\nunset XDG_RUNTIME_DIR\njupyter notebook --ip=$(hostname) --no-browser' > $VIRTUAL_ENV/bin/notebook.sh | |||
}} | |||
= Connecting to a manually spawned Jupyter Notebook = | = Connecting to a manually spawned Jupyter Notebook = |
Revision as of 20:59, 29 September 2017
This is not a complete article: This is a draft, a work in progress that is intended to be published into an article, which may or may not be ready for inclusion in the main wiki. It should not necessarily be considered factual or authoritative.
Introduction
Jupyter notebook comes in one Python model on Graham. You can get it working on the login node (not recommended), and the compute nodes (highly recommended). Note that Login nodes impose various user- and process-based limits, so notebooks running there may be killed if they consume significant cpu-time or memory. You will have to submit a job requesting the # of CPU (or even GPU), amount of memory and runtime. Here, we give the instructions to submit a Jupyter job.
Installing Jupyter Notebook
These instructions install Jupyter into your home directory. To install Jupyter we will use the pip
command and install it into a Python virtual environments. The below instructions install for Python 3.5.2. The below instructions install for Python 3.5.2 but you can also install for Python 3.5.Y or 2.7.X by loading a different Python module.
Load the Python module:
[name@server ~]$ module load python/3.5.2
Create a new python virtual environment:
[name@server ~]$ virtualenv jupyter_py3
Activate your newly created python virtual environment:
[name@server ~]$ source jupyter_py3/bin/activate
Install Jupyter into your newly created virtual environment:
(jupyter_py3)[name@server $] pip install jupyter
In your virtual environment, create a wrapper script that can launch Jupyter notebook
(jupyter_py3)[name@server $] {{{1}}}
Connecting to a manually spawned Jupyter Notebook
Create a Tunnel
To access the notebook running on a compute node from your web browser, you will need to create a tunnel between the cluster and your computer since the compute nodes are not directly accessible from the Internet. To create that tunnel, we recommend the usage of the Python package sshuttle.
On your computer, open a new terminal window, and run the following sshuttle command to create the tunnel
[name@my_computer $] sshuttle --dns -Nr userid@machine_name
Activate the Environment
On the cluster, activate the virtual environment in which you have installed Jupyter.
[name@server ~]$ source jupyter_py3/bin/activate
Submit the job
Create a bash script that launches Jupyter notebook server.
#!/bin/bash
unset XDG_RUNTIME_DIR
jupyter notebook --ip=$(hostname) --no-browser
Make it executable
[name@server ~]$ chmod u+x jupyter.sh
Example on Graham
Once you submit the job, and this job has started, you can check the instructions in the log file jupyter-log-*.txt. For example, let's say that you submit a job with a JOBID 131620, then you will have a file jupyter-log-131620.txt which will have something like the following
Copy/Paste this in your local terminal to ssh tunnel with remote ----------------------------------------------------------------- sshuttle -r jnandez@graham.computecanada.ca -v 10.29.76.27/24 ----------------------------------------------------------------- Then open a browser on your local machine to the following address ------------------------------------------------------------------ http://10.29.76.27:9799 (prefix w/ https:// if using password) ------------------------------------------------------------------ [I 13:58:14.393 NotebookApp] Serving notebooks from local directory: /home/jnandez/jupyter_notebook_HPC [I 13:58:14.394 NotebookApp] 0 active kernels [I 13:58:14.394 NotebookApp] The Jupyter Notebook is running at: http://10.29.76.27:9799/
Opening in a web browser
Open your local browser and type,
http://10.29.76.27:9799
Example on Cedar
Once you submit the job, and this job has started, you can check the instructions in the log file jupyter-log-*.txt. For example, let's say that you submit a job with a JOBID 1418055, then you will have a file jupyter-log-1418055.txt which will have something like the following
Copy/Paste this in your local terminal to ssh tunnel with remote ----------------------------------------------------------------- sshuttle -r jnandez@cedar.computecanada.ca -v 172.16.136.103/24 ----------------------------------------------------------------- Then open a browser on your local machine to the following address ------------------------------------------------------------------ http://172.16.136.103:8975 (prefix w/ https:// if using password) ------------------------------------------------------------------ [I 09:31:44.233 NotebookApp] Serving notebooks from local directory: /home/jnandez/jupyter_notebook_HPC [I 09:31:44.233 NotebookApp] 0 active kernels [I 09:31:44.233 NotebookApp] The Jupyter Notebook is running at: http://172.16.136.103:8975/ [I 09:31:44.233 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Opening in a web browser
Open your local browser and type,
http://172.16.136.103:8975