{"id":962,"date":"2017-02-16T12:43:39","date_gmt":"2017-02-16T17:43:39","guid":{"rendered":"http:\/\/josephpcohen.com\/w\/?p=962"},"modified":"2023-07-23T21:38:53","modified_gmt":"2023-07-24T01:38:53","slug":"jupyter-notebook-and-hpc-systems","status":"publish","type":"post","link":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/","title":{"rendered":"Jupyter notebook and HPC systems"},"content":{"rendered":"<p>Jupyter notebook [<a href=\"https:\/\/jupyter.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">jupyter.org<\/a>] is an interactive shell in a web browser that can display output, graphics, and tables inline to make research and development faster, easier, and more reproducibility. It is primarily used for the Python language but is also used by the Julia community. This approach will let you use jupyter notebooks with the GPUs from a cluster.<\/p>\n<p><!--more--><\/p>\n<p>Here are the scripts I use to connect to a machine via slurm and have the ports configured so I call access the notebook via http:\/\/localhost:8889 where the code is executing on a GPU in a cluster.<\/p>\n<p><code>cluster.head.node<\/code> The DNS address of your clusters entry machine. This should be a machine where you can submit jobs. Also, this guide will use the port number<br \/>\n<code>8889<\/code>. You should replace this with a number between 1024\u201349151 so it does not conflict with other users.<\/p>\n<p>You can configure your laptop to forward ports automatically so you can just type &#8220;ssh cluster.head.node&#8221; To have this setup you need to modify your local ssh config as follows:<\/p>\n<pre>==~\/.ssh\/config========\r\nHost cluster.head.node\r\nUser username \r\nLocalForward 8889 127.0.0.1:8889\r\n====================\r\n<\/pre>\n<p>Then you need to launch a job on your clusters head node so the jupyter command will run on a compute node. This example uses slurm:<\/p>\n<pre>$sbatch --gres=gpu jupyter.sh\r\n<\/pre>\n<p>The &#8220;jupyter.sh&#8221; script will launch a reverse tunnel to connect back to cluster.head.node from whatever node you landed on. It also sets the JUPYTER_RUNTIME_DIR to deal with a permissions issue.<\/p>\n<pre>== jupyter.sh ==========\r\n#!\/bin\/sh\r\nssh -N -R 8889:localhost:8889 cluster.head.node &amp;\r\nexport JUPYTER_RUNTIME_DIR=\/tmp\/jupyterchangeme\r\njupyter notebook --port=8889 --no-browser\r\n====================<\/pre>\n<p>Everyone should have a <b>unique port and tmp folder<\/b> when using this config.<\/p>\n<h2>If reverse port forwarding is blocked<\/h2>\n<p>Sometimes nodes are not able to ssh into a head node (like due to an authentication issue). In that case you can start a screen\/tmux session on the head node and then ssh into the execution node with port forwarding. As long as the screen\/tmux session is still running you can disconnect and connect to the head node and the port will stay connected.<\/p>\n<p>Look up the node that is running the job using squeue -u $USER and then ssh into that hostname:<\/p>\n<pre>\r\nssh -L 8889:localhost:8889 nodehostname\r\n<\/pre>\n<h2>Setting a password<\/h2>\n<p>If the webpage doesn&#8217;t prompt you to mset a password then follow these instructions. <a href=\"https:\/\/jupyter-notebook.readthedocs.io\/en\/latest\/public_server.html\">More info here<\/a><\/p>\n<p>Generate the hash of your password like this in a python shell:<\/p>\n<pre>from notebook.auth import passwd\r\npasswd()\r\n<\/pre>\n<p>Then take that hash and set it as follows in this file: ~\/.jupyter\/jupyter_notebook_config.py<\/p>\n<pre>c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'<\/pre>\n<p>&nbsp;<\/p>\n<h1>Common fixes<\/h1>\n<p>Error when having a too recent version of ipython:<\/p>\n<pre class=\"p1\">$ jupyter-kernelspec list\r\n[ListKernelSpecs] WARNING | Native kernel (python2) is not available\r\n[ListKernelSpecs] WARNING | Native kernel (python2) is not available\r\nNo kernels available\r\n<\/pre>\n<p>Install an earlier version of ipython:<\/p>\n<pre class=\"p1\">$pip install --user --upgrade ipython==4.1.1\r\n<\/pre>\n<p>Also to fix some issue with NFS that will happen after you switch between machines set these config options<\/p>\n<p>In ~\/.jupyter\/jupyter_notebook_config.py<\/p>\n<pre>c.NotebookNotary.db_file = ':memory:'<\/pre>\n<p>In ~\/.ipython\/profile_default\/ipython_config.py<\/p>\n<pre>c.HistoryAccessor.enabled = False\r\nc.HistoryAccessor.hist_file = ':memory:'<\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Jupyter notebook [jupyter.org] is an interactive shell in a web browser that can display output, graphics, and tables inline to make research and development faster, <a class=\"mh-excerpt-more\" href=\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/\" title=\"Jupyter notebook and HPC systems\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":974,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Jupyter notebook and HPC systems - Joseph Paul Cohen PhD<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Jupyter notebook and HPC systems - Joseph Paul Cohen PhD\" \/>\n<meta property=\"og:description\" content=\"Jupyter notebook [jupyter.org] is an interactive shell in a web browser that can display output, graphics, and tables inline to make research and development faster, [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/\" \/>\n<meta property=\"og:site_name\" content=\"Joseph Paul Cohen PhD\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-16T17:43:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-24T01:38:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/josephpcohen.com\/w\/wp-content\/uploads\/jupyter-sq-text.png\" \/>\n\t<meta property=\"og:image:width\" content=\"440\" \/>\n\t<meta property=\"og:image:height\" content=\"440\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Joseph Paul Cohen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joseph Paul Cohen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/\"},\"author\":{\"name\":\"Joseph Paul Cohen\",\"@id\":\"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/e25d0d5746952220f35d182ca7aa8684\"},\"headline\":\"Jupyter notebook and HPC systems\",\"datePublished\":\"2017-02-16T17:43:39+00:00\",\"dateModified\":\"2023-07-24T01:38:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/\"},\"wordCount\":441,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/e25d0d5746952220f35d182ca7aa8684\"},\"articleSection\":[\"References\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/\",\"url\":\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/\",\"name\":\"Jupyter notebook and HPC systems - Joseph Paul Cohen PhD\",\"isPartOf\":{\"@id\":\"https:\/\/josephpcohen.com\/w\/#website\"},\"datePublished\":\"2017-02-16T17:43:39+00:00\",\"dateModified\":\"2023-07-24T01:38:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/josephpcohen.com\/w\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Jupyter notebook and HPC systems\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/josephpcohen.com\/w\/#website\",\"url\":\"https:\/\/josephpcohen.com\/w\/\",\"name\":\"Joseph Paul Cohen PhD\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/e25d0d5746952220f35d182ca7aa8684\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/josephpcohen.com\/w\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/e25d0d5746952220f35d182ca7aa8684\",\"name\":\"Joseph Paul Cohen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a810b57939e75247f570c9094e7bd16e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a810b57939e75247f570c9094e7bd16e?s=96&d=mm&r=g\",\"caption\":\"Joseph Paul Cohen\"},\"logo\":{\"@id\":\"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Jupyter notebook and HPC systems - Joseph Paul Cohen PhD","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/","og_locale":"en_US","og_type":"article","og_title":"Jupyter notebook and HPC systems - Joseph Paul Cohen PhD","og_description":"Jupyter notebook [jupyter.org] is an interactive shell in a web browser that can display output, graphics, and tables inline to make research and development faster, [...]","og_url":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/","og_site_name":"Joseph Paul Cohen PhD","article_published_time":"2017-02-16T17:43:39+00:00","article_modified_time":"2023-07-24T01:38:53+00:00","og_image":[{"width":440,"height":440,"url":"https:\/\/josephpcohen.com\/w\/wp-content\/uploads\/jupyter-sq-text.png","type":"image\/png"}],"author":"Joseph Paul Cohen","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joseph Paul Cohen","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/#article","isPartOf":{"@id":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/"},"author":{"name":"Joseph Paul Cohen","@id":"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/e25d0d5746952220f35d182ca7aa8684"},"headline":"Jupyter notebook and HPC systems","datePublished":"2017-02-16T17:43:39+00:00","dateModified":"2023-07-24T01:38:53+00:00","mainEntityOfPage":{"@id":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/"},"wordCount":441,"commentCount":0,"publisher":{"@id":"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/e25d0d5746952220f35d182ca7aa8684"},"articleSection":["References"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/","url":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/","name":"Jupyter notebook and HPC systems - Joseph Paul Cohen PhD","isPartOf":{"@id":"https:\/\/josephpcohen.com\/w\/#website"},"datePublished":"2017-02-16T17:43:39+00:00","dateModified":"2023-07-24T01:38:53+00:00","breadcrumb":{"@id":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/josephpcohen.com\/w\/jupyter-notebook-and-hpc-systems\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/josephpcohen.com\/w\/"},{"@type":"ListItem","position":2,"name":"Jupyter notebook and HPC systems"}]},{"@type":"WebSite","@id":"https:\/\/josephpcohen.com\/w\/#website","url":"https:\/\/josephpcohen.com\/w\/","name":"Joseph Paul Cohen PhD","description":"","publisher":{"@id":"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/e25d0d5746952220f35d182ca7aa8684"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/josephpcohen.com\/w\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/e25d0d5746952220f35d182ca7aa8684","name":"Joseph Paul Cohen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a810b57939e75247f570c9094e7bd16e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a810b57939e75247f570c9094e7bd16e?s=96&d=mm&r=g","caption":"Joseph Paul Cohen"},"logo":{"@id":"https:\/\/josephpcohen.com\/w\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/posts\/962"}],"collection":[{"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/comments?post=962"}],"version-history":[{"count":18,"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/posts\/962\/revisions"}],"predecessor-version":[{"id":1723,"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/posts\/962\/revisions\/1723"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/media\/974"}],"wp:attachment":[{"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/media?parent=962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/categories?post=962"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/josephpcohen.com\/w\/wp-json\/wp\/v2\/tags?post=962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}