<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://hpc.mediawiki.hull.ac.uk/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ccscj</id>
	<title>HPC - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://hpc.mediawiki.hull.ac.uk/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ccscj"/>
	<link rel="alternate" type="text/html" href="https://hpc.mediawiki.hull.ac.uk/Special:Contributions/Ccscj"/>
	<updated>2026-08-25T08:38:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.16</generator>
	<entry>
		<id>https://hpc.mediawiki.hull.ac.uk/index.php?title=General/Jupyternotebook&amp;diff=39493</id>
		<title>General/Jupyternotebook</title>
		<link rel="alternate" type="text/html" href="https://hpc.mediawiki.hull.ac.uk/index.php?title=General/Jupyternotebook&amp;diff=39493"/>
		<updated>2020-02-07T07:47:48Z</updated>

		<summary type="html">&lt;p&gt;Ccscj: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
The Jupyter Notebook is an interactive computing environment that enables users to author notebook documents that include: - Live code - Interactive widgets - Plots - Narrative text - Equations - Images - Video.&lt;br /&gt;
&lt;br /&gt;
Jupyter notebooks are ideally suited for &amp;#039;&amp;#039;educational purposes only&amp;#039;&amp;#039;, however they have limitations across a network particularly with the graphical interface. The university does provide a [[Jupyterhub|jupyterhub service]].&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Important&amp;#039;&amp;#039;&amp;#039; : If you wish to carry out serious python development consider changing to an [[General/Interactive|interactive session]] and using a [[Applications/Miniconda|virtual environment]] within your account and using the editors [[Training/Linux_-_vi_editor|vi]] or [[Training/Linux_-_Nano_editor|nano]]. &lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Alternatively&amp;#039;&amp;#039;&amp;#039;, if you wish to edit files on your local machine there are many IDEs which provide a means for transferring python file across to Viper seamlessly, examples of these are [https://www.jetbrains.com/pycharm/ PyCharm] and [https://code.visualstudio.com/ Visual Studio Code]. (&amp;#039;&amp;#039;All suitable for Linux, MacOS and Windows&amp;#039;&amp;#039;).&lt;br /&gt;
&lt;br /&gt;
==Setting up==&lt;br /&gt;
&lt;br /&gt;
===Interactive mode (GPU)===&lt;br /&gt;
&lt;br /&gt;
Below is the console output of using jupyter notebook in an interactive session&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;&amp;quot;&amp;gt;&lt;br /&gt;
[pysdlb@login01 ~]$ interactive -pgpu&lt;br /&gt;
salloc: Granted job allocation 2216487&lt;br /&gt;
Job ID 2216487 connecting to gpu03, please wait...&lt;br /&gt;
Last login: Tue Jan 14 12:01:33 2020 from login01&lt;br /&gt;
[pysdlb@gpu03 ~]$ module load python/anaconda/4.6/miniconda/3.7&lt;br /&gt;
[pysdlb@gpu03 ~]$ conda create -n jupyter&lt;br /&gt;
&lt;br /&gt;
Collecting package metadata (current_repodata.json): done&lt;br /&gt;
Solving environment: done&lt;br /&gt;
&lt;br /&gt;
## Package Plan ##&lt;br /&gt;
&lt;br /&gt;
  environment location: /home/pysdlb/.conda/envs/jupyter&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Proceed ([y]/n)? y&lt;br /&gt;
&lt;br /&gt;
Preparing transaction: done&lt;br /&gt;
Verifying transaction: done&lt;br /&gt;
Executing transaction: done&lt;br /&gt;
#&lt;br /&gt;
# To activate this environment, use&lt;br /&gt;
#&lt;br /&gt;
#     $ conda activate jupyter&lt;br /&gt;
#&lt;br /&gt;
# To deactivate an active environment, use&lt;br /&gt;
#&lt;br /&gt;
#     $ conda deactivate&lt;br /&gt;
&lt;br /&gt;
[pysdlb@gpu03 ~]$ conda activate jupyter&lt;br /&gt;
(jupyter) [pysdlb@gpu03 ~]$ conda install -c anaconda jupyter&lt;br /&gt;
Collecting package metadata (current_repodata.json): done&lt;br /&gt;
Solving environment: done&lt;br /&gt;
......&lt;br /&gt;
Preparing transaction: done&lt;br /&gt;
Verifying transaction: done&lt;br /&gt;
Executing transaction: done&lt;br /&gt;
(jupyter) [pysdlb@gpu03 ~]$ conda install -c fastai fastai&lt;br /&gt;
Collecting package metadata (current_repodata.json): done&lt;br /&gt;
Solving environment: -&lt;br /&gt;
.....&lt;br /&gt;
Preparing transaction: done&lt;br /&gt;
Verifying transaction: done&lt;br /&gt;
Executing transaction: done&lt;br /&gt;
(jupyter) [pysdlb@gpu03 ~]$ conda install -c conda-forge nibabel&lt;br /&gt;
Collecting package metadata (current_repodata.json): done&lt;br /&gt;
Solving environment: done&lt;br /&gt;
.....&lt;br /&gt;
Preparing transaction: done&lt;br /&gt;
Verifying transaction: done&lt;br /&gt;
Executing transaction: done&lt;br /&gt;
(jupyter) [pysdlb@gpu03 ~]$ jupyter notebook&lt;br /&gt;
[I 13:33:59.573 NotebookApp] The port 8888 is already in use, trying another port.&lt;br /&gt;
[I 13:33:59.715 NotebookApp] Serving notebooks from local directory: /home/pysdlb&lt;br /&gt;
[I 13:33:59.715 NotebookApp] The Jupyter Notebook is running at:&lt;br /&gt;
[I 13:33:59.715 NotebookApp] http://localhost:8889/?token=50b345a31008ba2913678140c6aa4f85d0217bce6b1f83e5&lt;br /&gt;
[I 13:33:59.715 NotebookApp]  or http://127.0.0.1:8889/?token=50b345a31008ba2913678140c6aa4f85d0217bce6b1f83e5&lt;br /&gt;
[I 13:33:59.715 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).&lt;br /&gt;
[C 13:34:01.967 NotebookApp]&lt;br /&gt;
&lt;br /&gt;
    To access the notebook, open this file in a browser:&lt;br /&gt;
        file:///home/pysdlb/.local/share/jupyter/runtime/nbserver-10504-open.html&lt;br /&gt;
    Or copy and paste one of these URLs:&lt;br /&gt;
        http://localhost:8889/?token=50b345a31008ba2913678140c6aa4f85d0217bce6b1f83e5&lt;br /&gt;
     or http://127.0.0.1:8889/?token=50b345a31008ba2913678140c6aa4f85d0217bce6b1f83e5&lt;br /&gt;
START /usr/bin/firefox &amp;quot;/home/pysdlb/.local/share/jupyter/runtime/nbserver-10504-open.html&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Prepare SLURM batch script for jupyter notebook backend&lt;br /&gt;
&lt;br /&gt;
===CPU based===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#SBATCH -p compute&lt;br /&gt;
#SBATCH --ntasks=1&lt;br /&gt;
#SBATCH -t 04:00:00             # max runtime is 4 hours&lt;br /&gt;
#SBATCH -J ipy_server    # name&lt;br /&gt;
#SBATCH -o QQQ.out&lt;br /&gt;
&lt;br /&gt;
let ipnport=($UID-6025)%65274&lt;br /&gt;
echo ipnport=$ipnport&lt;br /&gt;
&lt;br /&gt;
ipnip=$(hostname -i)&lt;br /&gt;
echo ipnip=$ipnip&lt;br /&gt;
&lt;br /&gt;
module purge&lt;br /&gt;
module load python/anaconda/4.6/miniconda/3.7&lt;br /&gt;
&lt;br /&gt;
# Use virtual environment for python customization (change &amp;lt;user&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
source activate /home/user/.conda/envs/jupyter&lt;br /&gt;
&lt;br /&gt;
export I_MPI_DEBUG=5&lt;br /&gt;
export I_MPI_FABRICS=shm:tmi&lt;br /&gt;
export I_MPI_FALLBACK=no&lt;br /&gt;
&lt;br /&gt;
unset XDG_RUNTIME_DIR&lt;br /&gt;
jupyter notebook --ip=$ipnip --port=$ipnport --no-browser&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This generates an output file with the URL required to connect to the jupyter notebook backend&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ipnport=1487&lt;br /&gt;
ipnip=10.254.5.93&lt;br /&gt;
[I 09:53:13.302 NotebookApp] Serving notebooks from local directory: /home/pysdlb&lt;br /&gt;
[I 09:53:13.302 NotebookApp] 0 active kernels&lt;br /&gt;
[I 09:53:13.303 NotebookApp] The Jupyter Notebook is running at:&lt;br /&gt;
[I 09:53:13.303 NotebookApp] http://10.254.5.93:1487/?token=b71e38e053bd44e62ba340aff5a5b9b68c74cd0d0883d582&lt;br /&gt;
[I 09:53:13.303 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).&lt;br /&gt;
[C 09:53:13.345 NotebookApp]&lt;br /&gt;
&lt;br /&gt;
    Copy/paste this URL into your browser when you connect for the first time,&lt;br /&gt;
    to login with a token:&lt;br /&gt;
        http://10.254.5.93:1487/?token=b71e38e053bd44e62ba340aff5a5b9b68c74cd0d0883d582&lt;br /&gt;
[I 09:55:58.597 NotebookApp] 302 GET /?token=b71e38e053bd44e62ba340aff5a5b9b68c74cd0d0883d582 (10.254.5.247) 3.56ms&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Going to a browser on visualisation nodes or at time of writing login02.hpc.hull.ac.uk&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;&amp;quot;&amp;gt;&lt;br /&gt;
 $ firefox  http://10.254.5.93:1487/?token=b71e38e053bd44e62ba340aff5a5b9b68c74cd0d0883d582&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* It should be possible to combine these two steps into one script&lt;br /&gt;
&lt;br /&gt;
===GPU Configuration===&lt;br /&gt;
&lt;br /&gt;
* the SLURM batch script would slightly different&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#SBATCH --ntasks=1&lt;br /&gt;
#SBATCH -t 04:00:00             # max runtime is 4 hours&lt;br /&gt;
#SBATCH -J ipy_server    # name&lt;br /&gt;
#SBATCH -o QQQ.out&lt;br /&gt;
#SBATCH --gres=gpu          # use the GPU resource not the CPU&lt;br /&gt;
#SBATCH -p gpu              # Slurm partition, where you want the job to be queued &lt;br /&gt;
&lt;br /&gt;
let ipnport=($UID-6025)%65274&lt;br /&gt;
echo ipnport=$ipnport&lt;br /&gt;
&lt;br /&gt;
ipnip=$(hostname -i)&lt;br /&gt;
echo ipnip=$ipnip&lt;br /&gt;
&lt;br /&gt;
module purge&lt;br /&gt;
module load python/anaconda/4.6/miniconda/3.7&lt;br /&gt;
&lt;br /&gt;
# Use virtual environment for python customization (change &amp;lt;user&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
source activate /home/user/.conda/envs/jupyter&lt;br /&gt;
&lt;br /&gt;
export I_MPI_DEBUG=5&lt;br /&gt;
export I_MPI_FABRICS=shm:tmi&lt;br /&gt;
export I_MPI_FALLBACK=no&lt;br /&gt;
&lt;br /&gt;
unset XDG_RUNTIME_DIR&lt;br /&gt;
jupyter notebook --ip=$ipnip --port=$ipnport --no-browser&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Get Python to detect GPU Correctly (within Tensorflow here)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===SSH Tunneling for Jupyter===&lt;br /&gt;
It is possible to run Jupyter on a compute node and connect to the notebook from your desktop browser. In order to do this you need to &amp;#039;tunnel&amp;#039; a connection from your desktop/laptop over SSH to the node that Jupyter is running on.&lt;br /&gt;
&lt;br /&gt;
====SSH Tunneling with MobaXterm====&lt;br /&gt;
In MobaXterm tunnels are set up independently to an SSH connection. To set up a tunnel, open the Tunneling menu by either going to &amp;#039;&amp;#039;Tools &amp;gt; MobaSSHTunnel (port forwarding)&amp;#039;&amp;#039; from the top menu or &amp;#039;&amp;#039;Tunneling&amp;#039;&amp;#039; from the button bar. In the new MobaSSHTunnel window you can start an existing tunnel or add new tunnels, click &amp;#039;&amp;#039;New SSH Tunnnel&amp;#039;&amp;#039;. In the next window you want to set/select:&lt;br /&gt;
* &amp;#039;&amp;#039;Local port forwarding&amp;#039;&amp;#039;&lt;br /&gt;
* Under &amp;quot;Local clients&amp;quot; enter the port that you will point your local web browser to in &amp;quot;&amp;lt;Forwarded port&amp;gt;&amp;quot; for example 5050 (it doesn&amp;#039;t have to be the same as the port your Jupyter notebook is running on on Viper, but it is easier if it is)&lt;br /&gt;
* In &amp;quot;SSH server&amp;quot; enter &amp;quot;viper.hull.ac.uk&amp;quot; for SSH server and your username for &amp;quot;SSH login&amp;quot;&lt;br /&gt;
* In &amp;quot;Remote server&amp;quot;, under &amp;quot;&amp;lt;Remote server&amp;gt;&amp;quot; put the name of the compute node the Jupyter notebook is running on for example c048 (identify from squeue) and under &amp;quot;&amp;lt;Remote port&amp;gt;&amp;quot; enter the port your notebook is using, e.g. 5050 (either set manually or via your Jupyter config file).&lt;br /&gt;
* Save&lt;br /&gt;
[[File:Sshtunnel.PNG]]&lt;br /&gt;
&lt;br /&gt;
Once the tunnel is started you can point your local web browser to localhost:5050&lt;br /&gt;
[[File:Jupytertunnel.PNG]]&lt;br /&gt;
&lt;br /&gt;
====SSH Tunneling on Linux and Mac====&lt;br /&gt;
To setup a port forwarding tunnel on Linux or Mac, simply run the following SSH command (replacing 5050 with your chosen port and c048 with your compute node name):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;&amp;quot;&amp;gt;&lt;br /&gt;
ssh viper.hull.ac.uk -L 5050:c048:5050&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Again, you can then just point your browser to localhost:5050 to connect&lt;br /&gt;
&lt;br /&gt;
==Using jupyter configuration file==&lt;br /&gt;
&lt;br /&gt;
Jupyter notebook can be run using a configuration file to ease the number of command line option needed.&lt;br /&gt;
&lt;br /&gt;
Defaults for these options can also be set by creating a file named jupyter_notebook_config.py in your Jupyter folder. The Jupyter folder is in your home directory, ~/.jupyter.&lt;br /&gt;
&lt;br /&gt;
To create a jupyter_notebook_config.py file, with all the defaults commented out, you can use the following command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;background-color: #000000; color: white; border: 2px solid black; font-family: monospace, sans-serif;&amp;quot;&amp;gt;&lt;br /&gt;
$ jupyter notebook --generate-config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then for example add/modify the following lines to allow connection from any host, set a default port (5050 in this example), tell Jupyter not to try to open a browser, and set a default password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c.NotebookApp.ip = &amp;#039;*&amp;#039;&lt;br /&gt;
c.NotebookApp.port = 5050&lt;br /&gt;
c.NotebookApp.open_browser = False&lt;br /&gt;
c.NotebookApp.password = u&amp;#039;sha1:a1d634eb9a3c:fa1e22d81b2b456be67d3b59810c335b33c223134&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get your password you can use the following in python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
In [1]: from notebook.auth import passwd&lt;br /&gt;
In [2]: passwd()&lt;br /&gt;
Enter password:&lt;br /&gt;
Verify password:&lt;br /&gt;
Out[2]: &amp;#039;sha1:a1d634eb9a3c:fa1e22d81b2b456be67d3b59810c335b33c223134&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
&lt;br /&gt;
* [https://jupyterhub.hull.ac.uk University&amp;#039;s JupyterHub service]&lt;br /&gt;
* [https://www.anaconda.com/download/ Anaconda python]&lt;br /&gt;
* [https://jupyter-notebook.readthedocs.io/en/stable/index.html Jupyter notebook]&lt;br /&gt;
* [https://nbviewer.jupyter.org/ Jupyter viewer]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Other Links==&lt;br /&gt;
&lt;br /&gt;
* [[Main_Page|Main page]] &lt;br /&gt;
&lt;br /&gt;
* [[#top|Top of page]]&lt;/div&gt;</summary>
		<author><name>Ccscj</name></author>
		
	</entry>
</feed>