Commit 04daff05 authored by Carsten Eie Frigaard's avatar Carsten Eie Frigaard
Browse files

update

parent 6a6c8718
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## ITMAL: Long running cells in JupyterHub ## SWMAL: Long running cells in JupyterHub
(and how to capture output from 'em after closing Your browser or Your VPN connection) ..and how to capture output from 'em after closing Your browser or Your VPN connection.
REVISIONS| | REVISIONS| |
---------| | ---------| |
2018-0407| CEF, initial. 2018-04-07| CEF, initial.
2022-03-24| CEF, update for SWMAL F22.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%%capture output %%capture output
import time import time
t=20 t=20
done=False # done=False #
print("Jupyter Hub test..") print("Jupyter Hub test..")
print(f" long running cell, sleep for {t} seconds..") print(f" long running cell, sleep for {t} seconds..")
print(f" beg: {time.ctime()}") print(f" beg: {time.ctime()}")
time.sleep(t) time.sleep(t)
print(f" end: {time.ctime()}") print(f" end: {time.ctime()}")
done=True done=True
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#print(f"done={done}") #print(f"done={done}")
if done: if done:
output.show() # displays captured output output.show() # displays captured output
else: else:
print("cell above still seem to be running, wait some more..") print("cell above still seem to be running, wait some more..")
``` ```
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# ITMAL Notebook # ITMAL Notebook
## Quickstart demo.. ## Quickstart demo..
Running on the GPU-cluster (gpucluster.st.lab.au.dk). Running on the GPU-cluster (gpucluster.st.lab.au.dk).
See details in See details in
* https://brightspace.au.dk/d2l/le/lessons/27524/topics/296678 * https://brightspace.au.dk/d2l/le/lessons/27524/topics/296678
REVISIONS| | REVISIONS| |
---------| | ---------| |
2018-????| CEF, initial. 2018-????| CEF, initial.
2021-0407| CEF, updated, added header text and long-running section. 2021-0407| CEF, updated, added header text and long-running section.
2021-1026| CEF, minor lesson number update added more intro text. 2021-1026| CEF, minor lesson number update added more intro text.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Get ITMAL GIT repository ### Get ITMAL GIT repository
Clone [GITMAL] via the shell command '!'.. Clone [GITMAL] via the shell command '!'..
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
! test -d ~/itmal || (echo "Cloning GITMAL.." && git clone https://cfrigaard@bitbucket.org/cfrigaard/itmal) ! test -d ~/itmal || (echo "Cloning GITMAL.." && git clone https://cfrigaard@bitbucket.org/cfrigaard/itmal)
! cd ~/itmal && git pull ! cd ~/itmal && git pull
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Test Python Paths ### Test Python Paths
This cell just test if the startup-sequence has been run.. This cell just test if the startup-sequence has been run..
(startup-sequence placed in `~/.ipython/profile_default/startup /00_init.py`, that is a softlink to `/home/shared/00_init.py`.) (startup-sequence placed in `~/.ipython/profile_default/startup /00_init.py`, that is a softlink to `/home/shared/00_init.py`.)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import sys import sys
p=sys.path p=sys.path
print(f"Your current path=") print(f"Your current path=")
itmal_found_in_path=False itmal_found_in_path=False
for i in p: for i in p:
print(f" {i}") print(f" {i}")
n=i.find("/itmal") n=i.find("/itmal")
if n>0: if n>0:
itmal_found_in_path=True itmal_found_in_path=True
assert itmal_found_in_path, "ups, 'itmal' dir not present in system path...you are in trouble!" assert itmal_found_in_path, "ups, 'itmal' dir not present in system path...you are in trouble!"
print("OK") print("OK")
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Test ITMAL library ### Test ITMAL library
Now, import some functions form 'libitmal'.. Now, import some functions form 'libitmal'..
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from libitmal import versions as ver from libitmal import versions as ver
ver.Versions() ver.Versions()
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
If it went well, you should see version like If it went well, you should see version like
```Python version: 3.8.3. ```Python version: 3.8.3.
Scikit-learn version: 0.23.1. Scikit-learn version: 0.23.1.
Keras version: 2.4.3 Keras version: 2.4.3
Tensorflow version: 2.2.0 Tensorflow version: 2.2.0
Tensorflow.keras version: 2.3.0-tf``` Tensorflow.keras version: 2.3.0-tf```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Long-running cells in JupyterHub ### Long-running cells in JupyterHub
...and how to capture output from 'em after closing Your browser or Your VPN connection. ...and how to capture output from 'em after closing Your browser or Your VPN connection.
### Step 1 ### Step 1
First use the `%%capture` magic command in a long-running cell---the cell below also sets the 'done' flag to false. First use the `%%capture` magic command in a long-running cell---the cell below also sets the 'done' flag to false.
### Step 2 ### Step 2
Run the cell, and close you browser. Run the cell, and close you browser.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
%%capture output %%capture output
import time import time
t=20 t=20
done=False # done=False #
print("Jupyter Hub test..") print("Jupyter Hub test..")
print(f" long running cell, sleep for {t} seconds..") print(f" long running cell, sleep for {t} seconds..")
print(f" beg: {time.ctime()}") print(f" beg: {time.ctime()}")
time.sleep(t) time.sleep(t)
print(f" end: {time.ctime()}") print(f" end: {time.ctime()}")
done=True done=True
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
### Step 3 ### Step 3
Finally come back to the node you launched the long-running cell on and see if the `done` flag is marked as `True`, then the captured output can be printed, see this in the second cell Finally come back to the node you launched the long-running cell on and see if the `done` flag is marked as `True`, then the captured output can be printed, see this in the second cell
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#print(f"done={done}") #print(f"done={done}")
if done: if done:
output.show() # displays captured output output.show() # displays captured output
else: else:
print("cell above still seem to be running, wait some more..") print("cell above still seem to be running, wait some more..")
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
You can connect to running jupyter Notebooks via You can connect to running jupyter Notebooks via
<img src="https://itundervisning.ase.au.dk/GITMAL/L08/Figs/Screenshot_juptyterhub_running_cells.png" <img src="https://itundervisning.ase.au.dk/GITMAL/L07/Figs/Screenshot_juptyterhub_running_cells.png"
alt="WARNING: you need to be logged into Blackboard to view images" style="height:500px"> alt="WARNING: could not get image from server." style="height:500px">
Beware that the star "[*]" wont show up as expected, when reconnection: the cell might be running even if no star "[ ]" is showing! Beware that the star "[*]" wont show up as expected, when reconnection: the cell might be running even if no star "[ ]" is showing!
<img src="https://itundervisning.ase.au.dk/GITMAL/L08/Figs/Screenshot_juptyterhub_running_cells_missing_star.png" <img src="https://itundervisning.ase.au.dk/GITMAL/L07/Figs/Screenshot_juptyterhub_running_cells_missing_star.png"
alt="WARNING: you need to be logged into Blackboard to view images" style="height:500px"> alt="WARNING: could not get image from server." style="height:500px">
......
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment