Skip to content

Best Practices for Jupyter Notebooks

Here are some best practices that will help you be successful using Jupyter.

Use the Chrome browser

  • We've found that the Chrome browser is the best browser for Jupyter Notebooks.
  • Our Jupyter Notebooks may not work with the Safari browser.

Shut down your notebooks when you are done

  • Notebooks on the SuperCloud take up computing resources. When you leave Jupyter running, you are leaving resources occupied that could be used by someone else.
  • To shut down your notebook, click on the "Shutdown" button in the top right of every Jupyter page, or click the "Shutdown" button on the Jupyter launching page.
  • Make sure you save your notebooks and any important data before shutting down!

Save frequently

  • Save your notebook or text file by clicking File->Save or CMD+S/Control+S.
  • Save important data or results as files on the filesystem. Work save or write commands into your code wherever you produce an important result. In Python you can save in a text file, or use or np.savez().
  • When choosing the appropriate method for your application, note that both Numpy and HDF5 save the data in binary files which makes them computationally efficient. However, if you need to interface with scripts or code in a language other than Python, HDF5 is a standard across C/C++, FORTRAN, MATLAB and Python, providing flexibility and portability (please see information on HDF5 file locking here). If you need human readable data then csv format is your preferred option.

Export your notebook as a script

  • When you are done developing your code and need to run it without making too many edits, export your notebook as a script.
  • Save your notebook before exporting to get any recent changes.
  • In python, you can type !jupyter nbconvert --to script <notebook-name>.ipynb in a code block to export from within the notebook. Be sure to remove this line from your Python script before running it.
  • See the page on converting your notebook for more information.

Know when to use a batch job

  • Jupyter notebooks are great for development and running interactive analysis, but if you have long running code you may want to submit that code as a batch job instead.
  • If you find you are going through the notebook running all cells without editing, or your notebook takes so long to run that you are taking frequent coffee breaks, it may make more sense to convert your notebook into a runable script that you can run from the command line. Once you have a runable script, you can submit that script as a job on the system, and it can run without your input. As long as you are saving your results, you can collect those results in the same directory that you run the notebook in.
  • Batch jobs will run the code you submit and exit independent of user input.
  • Export your notebook as a script to use as a starting point for a batch job.
  • See this page for more information on running batch jobs.
  • You can use the Jupyter Terminal to submit batch jobs, or submit from the login node through a terminal on your desktop.