Jupyter Notebook for ISIS/Slang

From Remeis-Wiki
Jump to navigation Jump to search

If you want to start an ISIS session with a jupyter notebook this should be straight forward on the cluster. For this you need to load two modules via the module system

module load conda slang-jupyter

Once this is done you need to access the conda environment via

conda activate

Here you can start the jupyter server, but make sure that the shell where you start the server has all needed modules loaded (e.g., if you need localmodels, for example tbnew, make sure it is activated. If you never actively loaded a module to use ISIS, you are probably good).

Start the server

jupyter notebook

now you should be greeted with the usual page from the notebooks where you can open notebooks etc. The folder were you started the server is the root folder and you can not go above this level. If you want to start a ISIS notebook, just create a new notebook and select isis (there is also a slang kernel, that is not the same!). Having the notebook opened you should be able to run commands in the cells as usual. The notebook acts as one document, so functions and variables defined in one cell are accessible in another (provided the cell with the definitions was executed first). For details about the notebook interactions check the manual of jupyter itself.

Embedding images

Currently the kernel (that is the part of the software that translates your input to isis) has no built in feature to display images. If you issue a plot command and you are locally at the machine a normal pgplot will open just as it is with the isis shell. The simplest way to include an image in the notebook is to plot into a png file

variable pg = open_plot("my-cool-plot.png/png"); % this opens a plot to a png file, any plot command afterwards will draw to this file
xlabel("X-axis");
ylabel("Y-axis");
plot([0:4:#100], sin([0:4:#100]));
oplot([0,4], [0,1]);
close_plot(pg); % this is important, if you don't close the file, any additional plot command will create a new file with appended counter

The created png can be included in the notebook with a markdown cell

![Example Text](my-cool-plot.png)

where the text in square brackets is the description, this can be left empty (but the brackets are necessary).

This way you can also use xfig or tikz to create pdfs or png and embed them accordingly.

Remote Access

If you want to work on a notebook remotely then this is not directly possible for various reasons but mainly because this would allow everyone to execute arbitrary code on our cluster (and, in case this was not clear, we don't want that). There is, however, a way to forward the server via an ssh tunnel between your computer (let's say you use a laptop) and the cluster.

To do so, you first have to get the information about where the server is running

jupyter notebook list # make sure the conda environment is activated to have access to jupyter

This will show you a line similar to

http://localhost:8888/?token=2b9af3b8973be0b3270d0cf93941969db373bd70bfe195ea :: /home/stierhof

where the first part is the address where the server is accessible (locally) and the second is the root folder where it is running. Now to access the server on your laptop, create the tunnel with

ssh -NL 8888:localhost:8888 <user>@<computer>

This command will not return and seemingly do nothing! You need to keep the shell where you started the tunnel open, if you close it the tunnel will be closed too. In this example the number 8888 is the port number from the listed notebook above, if you are shown a different number you also have to change it in the ssh command (but 8888 is the default port). Once the ssh tunnel connects you local port with the port on the cluster you can paste the full address as shown by the jupyter notebook list command into a browser and access the server from there in the usual way.

Disclaimer

The software that enables isis to be used in a jupyter notebook is not very well tested yet. If you find any problems, or better yet, have solutions to problems or ideas for features, please let me know - Jakob Stierhof