User Tools

Site Tools


tipsntricks:ipython_notebook

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tipsntricks:ipython_notebook [2021/03/11 14:51]
ccrosby [Security]
tipsntricks:ipython_notebook [2024/06/21 16:01] (current)
wikiadmin [Jupyter / Ipython Notebook]
Line 1: Line 1:
 ===== Jupyter / Ipython Notebook ===== ===== Jupyter / Ipython Notebook =====
  
-Jupyter is installed in most of the python modules. To make use of it you would do something like:+Jupyter is a commonly installed component in most Python modules, and it can be easily utilized by following a few simple steps. For instance:
 <code bash> <code bash>
 jupyter-notebook jupyter-notebook
 </code> </code>
  
-However using it effectively on the cluster is a bit more complicated...+Howeverusing it effectively on the cluster is a bit more complicated...
  
 After [[http://wiki.chpc.ac.za/quick:start#logging_in|Logging in]] to your account check for your preferred python version as follows: After [[http://wiki.chpc.ac.za/quick:start#logging_in|Logging in]] to your account check for your preferred python version as follows:
Line 14: Line 14:
 </code> </code>
  
-Now proceed to request for an interactive compute node where a configuration file and security measures will be establishedsingle core on an interactive node has proven sufficient for this exercisebut if you are going to open multiple notebooks, request an appropriate number of cores, let's say 4, as follows+You can now request an interactive compute node to establish a configuration file and implement security measures. For this exercise, a single core on an interactive node has been found to be sufficient. However, if you plan to open multiple notebooks, please request an appropriate number of cores, such as four, using the following command:
  
 <code bash> <code bash>
-qsub -I -P PROJ0101 -q serial -l select=1:ncpus=4:mpiprocs=4:nodetype=haswell_reg+qsub -I -P PROJ0101 -q serial -l select=1:ncpus=4:mpiprocs=4
 </code> </code>
  
 //**Note**://  //**Note**:// 
-  -//"PROJ0101" is an arbitrary project name, kindly use your research project'shortname e.g. //ERTH0859\\ +  -// Kindly replace "PROJ0101" with your research programme'short name e.g. //ERTH0859\\ 
-  -// Record the cnode ID because you will ssh into that particular compute node when setting up your password.//+  -// Make sure to record the cnode ID as you will need to ssh into that specific compute node when setting up your password..//
   -//Advanced interactive compute node settings are found here: [[http://wiki.chpc.ac.za/howto:tipsandtricks#using_an_interactive_pbs_session | Example interactive job request]].//   -//Advanced interactive compute node settings are found here: [[http://wiki.chpc.ac.za/howto:tipsandtricks#using_an_interactive_pbs_session | Example interactive job request]].//
  
Line 28: Line 28:
  
 <code bash> <code bash>
-qsub -I -P PROJ0101 -q bigmem -l select=1:ncpus=4:mpiprocs=4:nodetype=haswell_fat+qsub -I -P PROJ0101 -q bigmem -l select=1:ncpus=4:mpiprocs=4
 </code> </code>
  
Line 48: Line 48:
 **Note** **Note**
   -//This writes a default config file to: /home/USERNAME/.jupyter/jupyter_notebook_config.py//, where USERNAME is YOUR username.   -//This writes a default config file to: /home/USERNAME/.jupyter/jupyter_notebook_config.py//, where USERNAME is YOUR username.
-  -//The output file "jupyter_notebook_config.py" will be listed as a hidden file. Thusto list it do a $ ls -a //+  -//The output file "jupyter_notebook_config.py" will be listed as a hidden file. To display itexecute the command $ ls -a//
  
 Next you need to generate your password (remember it -- you'll need it when you connect later): Next you need to generate your password (remember it -- you'll need it when you connect later):
Line 64: Line 64:
 Your password hash will be different.  Obviously use the one in your terminal, not the one shown in this example. Your password hash will be different.  Obviously use the one in your terminal, not the one shown in this example.
  
-Use the following command to access the "jupyter_notebook_config.py" file: $ cd $HOME/.jupyter/ \\ 
-Now edit the ''jupyter_notebook_config.py'' file, specifically edit the ''c.NotebookApp.passwd'' line.  
  
 +Exit python and then use the following command to access the "jupyter_notebook_config.py" file:
 +<code bash>
 +  cd .jupyter/
 +</code>
  
 +Now edit the file ''jupyter_notebook_config.py'' with your favourite editor. 
 <code> <code>
 +vim jupyter_notebook_config.py 
 c.NotebookApp.password = 'sha1:f27008fdb0eb:4c2f305d5e230edca16c7059882ba3ba63bee03b' c.NotebookApp.password = 'sha1:f27008fdb0eb:4c2f305d5e230edca16c7059882ba3ba63bee03b'
 </code> </code>
Line 80: Line 84:
 **VERY IMPORTANT:**  Do not add the lines below to your .ssh/config file on the cluster, you //WILL// break any attempt at parallel processing! **VERY IMPORTANT:**  Do not add the lines below to your .ssh/config file on the cluster, you //WILL// break any attempt at parallel processing!
  
-Open a terminal on your local machine and create a ''.ssh/config'' file. +Open a terminal on your **local** workstation and create a ''.ssh/config'' file. 
    
 <code> <code>
Line 86: Line 90:
 </code> </code>
  
-If your desktop system runs Windows, a simple way to deal with this is to run a unix-like environment inside Windows.  You can either use[[http://cygwin.com|Cygwin]] Cygwin directly, or start a "Local Terminal" in [[https://mobaxterm.mobatek.net/|MobaXterm]].  From this terminal you can edit the local ''~/.ssh/config'' file as if you were working on a Linux computer. +If your desktop system runs Windows, a simple way to deal with this is to run a unix-like environment inside Windows.  You can either use[[http://cygwin.com|Cygwin]] Cygwin directly, or start a "Local Terminal" in [[https://mobaxterm.mobatek.net/|MobaXterm]].  From this terminal you can edit the local ''.ssh/config'' file as if you were working on a Linux computer. 
  
    
-Continue to edit the ''~/.ssh/config'' file on your local machine by adding in these lines:+Find,  
 +<code> 
 +ls -al 
 +</code> 
 +... and continue to edit the ''.ssh/config'' file on your local machine by adding in these lines:
 <code> <code>
 Host cnode* Host cnode*
Line 95: Line 103:
     User YOURUSERNAME     User YOURUSERNAME
     ProxyCommand ssh YOURUSERNAME@lengau.chpc.ac.za nc %h 22     ProxyCommand ssh YOURUSERNAME@lengau.chpc.ac.za nc %h 22
-    LocalForward 8838 localhost:8838+    LocalForward 8888 localhost:8888 
 +Host fat* 
 +    Hostname %h 
 +    User YOURUSERNAME 
 +    ProxyCommand ssh YOURUSERNAME@lengau.chpc.ac.za nc %h 22 
 +    LocalForward 8888 localhost:8888    
 </code> </code>
 +
 +
 +Remember to replace "YOURUSERNAME" with your own username on the cluster.
  
 At this point you may not know what the LocalForward and localhost port numbers are so, on the cluster in the interactive node you had opened earlier type:  At this point you may not know what the LocalForward and localhost port numbers are so, on the cluster in the interactive node you had opened earlier type: 
Line 102: Line 118:
 jupyter-notebook --no-browser jupyter-notebook --no-browser
 </code> </code>
-Edit given port number into LocalForward and localhost above+Edit the given port number into LocalForward and localhost above
  
 **Note** **Note**
Line 108: Line 124:
   -//Confirm the localForward and localhost port numbers provided for each different session.//   -//Confirm the localForward and localhost port numbers provided for each different session.//
  
-In your local terminal ''ssh'' directly to compute node +In your local terminal ''ssh'' directly to the compute node that you are using.  Let us assume that it is cnode1234: 
  
 <code> <code>
-ssh cnode*+ssh cnode1234
 </code> </code>
  
-You should be prompted for your password, twice. This is because the ''ssh'' logs in to Lengau first and then from Lengau it logs into the the compute node. +You should be prompted for your CLUSTER password, twice. This is because the ''ssh'' logs in to Lengau first and then from Lengau it logs into the the compute node.  On the first login, MobaXterm will offer to remember your password, and if you allow it to do so it will not be necessary to re-enter it.
  
 You are now ready to roll... You are now ready to roll...
  
-In your browser go to: http://localhost:8838 (note you can only do this to nodes where you currently have a job running). +In your browser go to: http://localhost:8888 (note you can only do this for nodes where you currently have a jupyter job running). Your port number may be different.  Use the number that you have been assigned.
  
 The jobscript will look something like: The jobscript will look something like:
 <file bash jupyter.qsub> <file bash jupyter.qsub>
 #!/bin/bash #!/bin/bash
-#PBS -P SHORTNAME+#PBS -P ERTH1234 
 #PBS -q serial #PBS -q serial
-#PBS -l select=1:ncpus=8:mpiprocs=1+#PBS -l select=1:ncpus=8:mpiprocs=8
 #PBS -l walltime=08:00:00 #PBS -l walltime=08:00:00
 #PBS -N Jupyter #PBS -N Jupyter
Line 133: Line 149:
 module add chpc/python/3.6.0_gcc-6.3.0 module add chpc/python/3.6.0_gcc-6.3.0
  
-JUPYTERPORT=8838  # you could change this too, if you wanted to.+JUPYTERPORT=8888  # you could change this too, if you wanted to.
  
 hostname > ~/jupyter.host hostname > ~/jupyter.host
Line 145: Line 161:
 </code> </code>
  
-Then, again on your local machine, you need to connect to the compute node, i.e. ''ssh cnode0101'' If you are working in Windows, do this from your Cygwin or MobaXterm terminal command line.  You will be prompted for your Lengau login password.+Then, again on your local machine, you need to connect to the allocated compute node, for example ''ssh cnode0101'' If you are working in Windows, do this from your Cygwin or MobaXterm terminal command line.  You will be prompted for your Lengau login password.
  
 ==== Running Jupyter on a GPU node ==== ==== Running Jupyter on a GPU node ====
/app/dokuwiki/data/attic/tipsntricks/ipython_notebook.1615467100.txt.gz · Last modified: 2021/12/09 16:42 (external edit)