Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
5.2 KiB

  1. It is not uncommon for me to get exuberantly excited over a open source
  2. project that I stumble upon, however, Jupyter Lab has taken the
  3. cake this month. The Jypyter project is an open-source community
  4. that extended IPython notebook project to the web browser and added
  5. support for multiple languages.
  6. # Why Notebooks?
  7. As a researcher and educator I love notebooks because they enable
  8. you to easily share your code with others. Notebooks are much more
  9. interactive than simply sharing source code because you can
  10. mix text(markdown), code, and outputs from code execution. For classes and
  11. when working, this makes it very easy to generate quick reports.
  12. You can simply write a document that auto generates the graphs and figures
  13. you want to talk about in your document.
  14. Last week I worked on a computer vision assignment that required me to
  15. use Open CV to manipulate images using filters, convolutions, etc.
  16. The entirety of the assignment required me to produce roughly 30 images.
  17. A majority of the class wrote python scripts and threw each image they
  18. generated into a massive word document and typed up their
  19. analysis and submitted their assignment as a PDF along side a bunch of
  20. python scripts. There is nothing wrong with doing that; however, what
  21. happens if at the end of the assignment you realized that you were
  22. generating Gaussian filters incorrectly? If you wrote everything in
  23. a Jupyter notebook you would just have to fix the dubious code and
  24. re-run the notebook and it would produce your report in its entirety.
  25. But, if you had your scripts as separate files you would have to fix your
  26. code and then go through and generate a dozen new images that required
  27. Gaussian filters and place them in your document.
  28. The ability to accurately reproduce your report is pinnacle to making
  29. research more verifiable and reproducible. This is something that the
  30. R and open-science communities heavily focus on. Directly mixing your
  31. code and analysis with your report is very useful. Also, consider if the
  32. data that you are working with changes half way through writing your
  33. research report. With a notebook, you would just have to re-run the
  34. notebook where if you had the report as a separate word or Latex file,
  35. you now run the risk of misreporting your results.
  36. # Jupyter Notebook
  37. # Jupyter Lab
  38. # Running and Installing
  39. # Running for remote use
  40. Imagine that you are running an old computer and you simply want your
  41. code to run on a remote computer that has a beefie GPU for ML.
  42. With Jupyter Lab or Notebook you can do that, but, it takes a little
  43. trickery. The easiest solution that I found involves using a reverse
  44. SSH proxy.
  45. ![network diagram](media/jupyter/network.jpeg)
  46. The first thing that you want to do is set up a password so that you
  47. can connect to the jupyter lab instance using a password rather than using
  48. a authentication key which gets hidden in the terminal.
  49. ```bash
  50. jupyter notebook password
  51. ```
  52. ** note ** the password that you set is configured in the same config used by both jupyter lab and jupyter notebook.
  53. The next thing you should do is run the jupyter lab instance on the port that you want it to listen to.
  54. ```bash
  55. jupyter lab --no-browser --port=6000
  56. ```
  57. The "--no-browser" will prevent jupyter from opening in your default web browser.
  58. The next step is to do a local SSH port forward on your machine
  59. so you can access the jupyter instance on the remote server.
  60. The benefit of doing this is that you can get behind firewalls and that
  61. all your traffic is encrypted.
  62. ![local port forwarding](media/jupyter/localForward.png)
  63. The image above comes from my presentation on "[Everything SSH](https://jrtechs.net/open-source/teaching-ssh-through-a-ctf)".
  64. The essence of the command bellow is that you will forward all
  65. connections on your machines to port 6000 to a remote's servers connection to localhost:6000.
  66. ```bash
  67. ssh -L 6000:localhost:6000 user@some-remote-host.rit.edu
  68. ```
  69. After you run that command you can access the jupyter lab instance
  70. by opening your favorite web client and going to localhost:6000.
  71. Typing that command every time is tedious so I recommend that you
  72. allias it in your shells config file.
  73. ```bash
  74. alias jj="ssh -L 6000:localhost:6000 user@some-remote-host.rit.edu"
  75. ```
  76. Now all you have to type in your command prompt is jj to connect to
  77. your remote jupyter server. Neat.
  78. But, what if your roommate trips and your server gets restarted? Well,
  79. you can write a systemd script to automatically start your jupyter
  80. server when the computer boots. This is what my system d script looks like.
  81. ```bash
  82. # location /lib/systemd/system
  83. #
  84. # After file creation run: systemctl daemon-reload
  85. # enable service on start up: systemctl enable jupyter-lab
  86. # start the service: systemctl start jupyter-lab
  87. [Unit]
  88. Description=Script to start jupyter lab
  89. Documentation=https://jrtechs.net
  90. After=network.target
  91. [Service]
  92. Type=simple
  93. User=jeff
  94. WorkingDirectory=/home/jeff/Documents/school/csci-431/
  95. ExecStart=/usr/local/bin/jupyter lab --no-browser --port=6969
  96. Restart=on-failure
  97. [Install]
  98. WantedBy=multi-user.target
  99. ```
  100. You want to set the working directory to be the location where your jupyter notebooks are stored.
  101. You also want to make sure that you specify the absolute path to the jupyter binary in the execstart parameter. You can find that using the which command:
  102. ```bash
  103. which jupyter
  104. ```