{"id":436,"date":"2014-07-11T11:20:34","date_gmt":"2014-07-11T11:20:34","guid":{"rendered":"http:\/\/ri.itservices.manchester.ac.uk\/icsf\/?page_id=436"},"modified":"2019-03-22T17:21:10","modified_gmt":"2019-03-22T17:21:10","slug":"ipython-notebook","status":"publish","type":"page","link":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/software\/applications\/ipython-notebook\/","title":{"rendered":"IPython Notebook"},"content":{"rendered":"<table class=\"warning\">\n<tr>\n<td>This app is no longer available.<br \/>You should use jupyter notebook instead.<\/td>\n<\/tr>\n<table>\n<h2>Overview<\/h2>\n<p><a href=\"http:\/\/ipython.org\/notebook.html\">IPython Notebook<\/a> is a web-based interactive computational environment where you can combine code execution, text, mathematics, plots and rich media into a single document. We execute python commands and view the results in a web browser. The python commands execute remotely on the iCSF (where more memory and compute-power exists).<\/p>\n<p>IPython version 1.1.0 is installed on the iCSF as part of the <a href=\"\/icsf\/software\/applications\/anaconda-python\">Anaconda Python 1.9.2<\/a> package. This runs Python 2.7.<\/p>\n<h2>Restrictions on use<\/h2>\n<p>There are no restrictions accessing this software. However you must have an account on the <code>nyx3<\/code> or <code>nyx4<\/code> virtual desktop server from which you then access the iCSF. Please see <a href=\"http:\/\/ri.itservices.manchester.ac.uk\/virtual-desktop-service-x2go\/\">X2GO virtual desktop<\/a> for details. To request an account on nyx3\/nyx4 please email <a href=\"&#x6d;&#97;i&#x6c;&#116;o&#x3a;&#105;t&#x73;&#x2d;&#114;&#x69;&#x2d;&#116;e&#x61;&#109;&#64;&#x6d;&#97;n&#x63;&#x68;&#101;&#x73;&#x74;&#101;r&#x2e;&#97;c&#x2e;&#117;k\">i&#116;&#x73;&#x2d;r&#105;&#45;&#x74;&#x65;a&#109;&#64;&#x6d;&#x61;n&#99;&#x68;&#x65;&#x73;t&#101;&#x72;&#x2e;a&#99;&#46;&#x75;&#x6b;<\/a>.<\/p>\n<h2>Set up procedure<\/h2>\n<p>The IPython Notebook software runs on one of the iCSF compute nodes. However, we do not manually log in to the iCSF and run the IPython Notebook software. Instead we run a script <em>on the nyx3\/nyx4<\/em> virtual desktop to manage the whole business of connecting to the iCSF and running the IPython software.<\/p>\n<p>Hence you must first log in to the nyx3 or nyx4 <a href=\"http:\/\/ri.itservices.manchester.ac.uk\/virtual-desktop-service\/x2go\/\">virtual desktop service<\/a> using the <em>x2goclient<\/em> software. See links for details.<\/p>\n<p>(The RI Team are developing a method to allow you to do this direct from your desktop but for now we must use the nyx3\/nyx4 virtual desktop).<\/p>\n<h2>Running the application<\/h2>\n<p>The following instructions assume you are logged in to the <em>nyx3<\/em> virtual desktop (we use nyx3 in this example but you can also use nyx4).<\/p>\n<h3>Launching the IPython Notebook on to the iCSF<\/h3>\n<p>Note: we use nyx3 in this example but you can also use nyx4.<\/p>\n<ol>\n<li>On nyx3, open a shell window (e.g., using menu: <em>Applications -> System Tools -> Terminal<\/em>)<\/li>\n<li>In the terminal, run:\n<pre>\r\nipython-notebook         # Add --highmem to use iCSF 256GB node<\/pre>\n<\/li>\n<li>Enter your iCSF password when prompted<\/li>\n<li>Make a note of the URL address given to you &#8211; e.g.: <code>http:\/\/localhost:7777<\/code> (the number at the end may differ).<\/li>\n<\/ol>\n<p>This will log you in to the iCSF (incline) and start the IPython Notebook server. Hence you will be asked for your iCSF password. Enter it when prompted.<\/p>\n<p>For example, the complete output is:<\/p>\n<pre>\r\n[mabcxyz1@nyx3 ~]$ ipython-notebook \r\n\r\n===================== Use the URL given here ====================\r\n\r\n 1. Enter your iCSF password when prompted below\r\n 2. On nyx3 please start iceweasel and browse to:\r\n\r\n           http:\/\/localhost:7777\r\n\r\nConnecting to the iCSF to start an iPython Notebook...\r\nmabcxyz1@incline's password: <strong>&lt;enter your iCSF password&gt;<\/strong>\r\n<\/pre>\n<p>You will have been automatically logged in to the iCSF (on to one of the backend nodes). Notice the URL advertised to you:<\/p>\n<pre>http:\/\/localhost:<strong>7777<\/strong><\/pre>\n<p>The <code>7777<\/code> port number may be different in your output. You should <strong>make a note<\/strong> of the URL, particularly the port number. We will access this URL in a web browser shortly.<\/p>\n<p>You will see some output from the IPython Notebook server and then the message:<\/p>\n<pre>\r\n======= ** IMPORTANT - YOU MUST DO THIS WHEN FINISHED WITH IPython ** =======\r\n\r\n Please use CTRL-C in this window to terminate iPython Notebook on incline01\r\n (PID 102924) ...\r\n<\/pre>\n<p>We will use this when shutting down the server at the end of our session (see below).<\/p>\n<h3>View the IPython Notebook in a Web Browser on nyx3<\/h3>\n<p>On the <em>nyx3<\/em> virtual desktop:<\/p>\n<ol>\n<li>Start Iceweasel (e.g., using menu: <em>Applications -> Internet -> Iceweasel<\/em>)<\/li>\n<li>Now enter the following address in the browser address bar at the top:\n<pre>http:\/\/localhost:7777<\/pre>\n<p>where <code>7777<\/code> is the number reported to you earlier when you ran <code>ipython-notebook<\/code in the command window. Your number may be different!<\/li>\n<\/ol>\n<p>You should now see the IPython Notebook <em>dashboard<\/em> in your web browser. This has connected to the iCSF backend node running the IPython Notebook:<\/p>\n<div class=\"hidden\">\n<li>Iceweasel should already have the settings needed to access the outside world via the University proxy (this is done for security). If you <em>cannot<\/em> access external websites, follow these instructions: <\/li>\n<ol>\n<li>In Iceweasel, select the <em>three hotdogs<\/em> menu on the right-hand side, then: <em>Preferences<\/em><\/li>\n<li>Select icon: <em>Advanced<\/em> (cog icon in top row)<\/li>\n<li>Select tab: <em>Network<\/em> (middle of the 5 tabs)<\/li>\n<li>Press button: <em>Settings&#8230;<\/em> (top right of panel)<\/li>\n<li>Select radio button: <em>Manual proxy configuration:<\/em> (4th option)<\/li>\n<li>Fill in the boxes <em>HTTP Proxy: <\/em> <code>webproxy.its.manchester.ac.uk<\/code> and <em>Port: <\/em> <code>3128<\/code><\/li>\n<li>Hit OK<\/li>\n<li>Close the Preferences panel<\/li>\n<\/ol>\n<\/div>\n<p><a href=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/empty-dashboard.png\"><img decoding=\"async\" src=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/empty-dashboard.png\" alt=\"IPython Notebook dashboard\" width=\"500\" class=\"alignnone size-full wp-image-442\" srcset=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/empty-dashboard.png 777w, https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/empty-dashboard-300x196.png 300w\" sizes=\"(max-width: 777px) 100vw, 777px\" \/><\/a><\/p>\n<p>Create a new notebook in which you will run Python commands:<\/p>\n<ol>\n<li>Press <em>New Notebook<\/em> (right-hand side)<\/li>\n<\/ol>\n<p>A new web browser tab will open giving you a notebook where you can type Python commands:<\/p>\n<p><a href=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/new-notebook.png\"><img decoding=\"async\" src=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/new-notebook.png\" alt=\"New IPython Notebook\" width=\"500\" class=\"alignnone size-full wp-image-441\" srcset=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/new-notebook.png 776w, https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/new-notebook-300x125.png 300w\" sizes=\"(max-width: 776px) 100vw, 776px\" \/><\/a><\/p>\n<ul>\n<li>After entering commands press the &#8216;play&#8217; icon to execute them<\/li>\n<li>OR press <em>Shift-Enter<\/em> to execute commands immediately<\/li>\n<\/ul>\n<p>Try the following commands:<\/p>\n<pre>\r\nfrom pylab import *\r\n%matplotlib inline\r\nx = linspace(0,5,10)\r\ny = x ** 2\r\nfigure()\r\nplot(x,y,'r')\r\nshow()\r\n  #\r\n  # Press SHIFT-Enter to run this cell or press the play icon in the bar above\r\n<\/pre>\n<p>You should see the following:<\/p>\n<p><a href=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/plot-notebook.png\"><img decoding=\"async\" src=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/plot-notebook.png\" alt=\"IPython Notebook Plot Example\" width=\"500\" class=\"alignnone size-full wp-image-440\" srcset=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/plot-notebook.png 812w, https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-content\/uploads\/plot-notebook-300x268.png 300w\" sizes=\"(max-width: 812px) 100vw, 812px\" \/><\/a><\/p>\n<p>Explore the menus in the Notebook to save notebooks, and <em>Close and Halt<\/em> the notebook when you are finished with it (a notebook could be executing a long-running python script &#8211; it is a <em>live<\/em> web-page, so you have to <em>halt<\/em> the notebook before it is closed. The menus do this in one command.)<\/p>\n<p>Close the web browser when you are finished with the Notebook dashboard then <strong>proceed<\/strong> to the next section to stop the server (this is important!)<\/p>\n<h3>Stopping the Remote Notebook Server<\/h3>\n<p>As mentioned above, when you have finished using the IPython Notebook on the iCSF you must close it down. Otherwise server processes may be left running on the iCSF backend nodes.<\/p>\n<p>Simply type <code>CTRL-C<\/code> in the shell window. It will report that it has shut down the server. You will be automatically logged out of the iCSF, leaving the shell window back at the <em>nyx3<\/em> prompt.<\/p>\n<pre>\r\n\r\n======= ** IMPORTANT - YOU MUST DO THIS WHEN FINISHED WITH IPython ** =======\r\n Please use CTRL-C in this window to terminate iPython Notebook on incline01\r\n (PID 102924) ...\r\n\r\n^C     <strong>&lt;-- here we pressed CTRL-C<\/strong>\r\n2014-07-11 12:45:06.483 [NotebookApp] CRITICAL | received signal 2, stopping\r\n2014-07-11 12:45:06.484 [NotebookApp] CRITICAL | received signal 2, stopping\r\n2014-07-14 12:10:41.508 [NotebookApp] Shutting down kernels\r\n\r\nTerminated iPython Notebook on incline01 (PID 102924)\r\n\r\nConnection to incline closed.\r\n\r\n[mabcxyz1@nyx3 ~]$\r\n<\/pre>\n<p>That&#8217;s it, we&#8217;re back on nyx3 and the IPython Notebook server we were running on the iCSF has finished.<\/p>\n<h2>Additional Usage Notes and Hints<\/h2>\n<p>We&#8217;ll update this section with additional information and hints on using IPython Notebooks in response to user feedback. Please feel free to send us useful information via <a href=\"m&#97;&#105;&#x6c;&#x74;&#x6f;:i&#116;&#115;&#x2d;&#x72;&#x69;-&#116;&#101;&#97;&#x6d;&#x40;&#x6d;a&#110;&#99;&#x68;&#x65;&#x73;te&#114;&#46;&#x61;&#x63;&#x2e;u&#107;\">&#105;&#x74;s&#45;&#x72;i&#x2d;&#x74;&#101;&#x61;m&#64;&#x6d;a&#110;&#x63;&#104;&#x65;s&#116;&#x65;r&#46;&#x61;&#99;&#x2e;&#x75;&#107;<\/a>.<\/p>\n<h3>Magic Commands<\/h3>\n<p>In the sample code above some of the commands typed in to our first IPython Notebook began with a <code>%<\/code> character. This must be typed as part of the command (it isn&#8217;t a prompt as you might find in a command-shell). For example, earlier we used:<\/p>\n<pre>\r\n%matplotlib inline\r\n<\/pre>\n<p>to load the Matplotlib package, giving it a flag to have plots\/figures displayed inline in the browser rather than popping up in a separate window.<\/p>\n<p>These commands are known as <a href=\"http:\/\/ipython.org\/ipython-doc\/dev\/interactive\/tutorial.html\">magic commands<\/a>. They provide additional functionality beyond that provided by Python. Commands that begin with a single <code>%<\/code> are called <em>line magics<\/em> and lines that begin with <code>%%<\/code> are call <em>cell magics<\/em>. Cell magics take all subsequent lines in a cell as input (line magics only use the arguments passed in on the same line).<\/p>\n<h3>Rmagic<\/h3>\n<p>IPython has an extension that contains magic functions for working with R via rpy2. This extension can be loaded using the %load_ext magic as follows:<\/p>\n<pre>\r\n%load_ext rpy2.ipython\r\n<\/pre>\n<p>Don&#8217;t forget to include the <code>%<\/code> symbol &#8211; it is part of the command! (Note that earlier versions of IPython used <code>rmagic<\/code> for the name of this <em>magic<\/em> instead of <code>rpy2.ipython<\/code>).<\/p>\n<p>You can now issue R commands in your IPython Notebook. Try the following:<\/p>\n<pre>\r\n# If not already done above...\r\n%load_ext rpy2.ipython\r\n\r\nimport numpy as np\r\nimport pylab\r\nX = np.array([0,1,2,3,4])\r\nY = np.array([3,5,4,6,7])\r\npylab.scatter(X, Y)\r\n%Rpush X Y\r\n# Press SHIFT-Enter to run this cell or press the play icon in the bar above\r\n<\/pre>\n<p>Nothing will appear yet (we&#8217;ve just set up some variables for the next set of commands). In the next cell, type<\/p>\n<pre>\r\n%%R -i X,Y -o XYcoef\r\nXYlm = lm(Y~X)\r\nXYcoef = coef(XYlm)\r\nprint(summary(XYlm))\r\npar(mfrow=c(2,2))\r\nplot(XYlm)\r\n# Press SHIFT-Enter to run this cell or press the play icon in the bar above\r\n<\/pre>\n<p>You should now see various statistics and four plots.<\/p>\n<p>Please see the <a href=\"http:\/\/ipython.org\/ipython-doc\/1\/config\/extensions\/rmagic.html#module-IPython.extensions.rmagic\">Rmagic documentation<\/a> for details of these commands.<\/p>\n<p>When you start the IPython Notebook server on the iCSF the R 3.1.0 modulefile will be automatically loaded so that you can use the Rmagic command (it requires access to an R installation).<\/p>\n<h2>Further info<\/h2>\n<ul>\n<li><a href=\"http:\/\/ipython.org\/notebook\">IPython Notebook website<\/a><\/li>\n<li><a href=\"http:\/\/nbviewer.ipython.org\/github\/jrjohansson\/scientific-python-lectures\/blob\/master\/Lecture-4-Matplotlib.ipynb\">Matplotlib plotting examples<\/a><\/li>\n<li><a href=\"http:\/\/ipython.org\/ipython-doc\/1\/config\/extensions\/rmagic.html#module-IPython.extensions.rmagic\">Rmagic documentation<\/a><\/li>\n<\/ul>\n<h2>Updates<\/h2>\n<p>None.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This app is no longer available.You should use jupyter notebook instead. Overview IPython Notebook is a web-based interactive computational environment where you can combine code execution, text, mathematics, plots and rich media into a single document. We execute python commands and view the results in a web browser. The python commands execute remotely on the iCSF (where more memory and compute-power exists). IPython version 1.1.0 is installed on the iCSF as part of the Anaconda.. <a href=\"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/software\/applications\/ipython-notebook\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":43,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-436","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/pages\/436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/comments?post=436"}],"version-history":[{"count":20,"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/pages\/436\/revisions"}],"predecessor-version":[{"id":908,"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/pages\/436\/revisions\/908"}],"up":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/pages\/43"}],"wp:attachment":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/icsf\/wp-json\/wp\/v2\/media?parent=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}