Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running jupyter notebooks on farm #51

Open
ctb opened this issue Oct 19, 2022 · 5 comments
Open

running jupyter notebooks on farm #51

ctb opened this issue Oct 19, 2022 · 5 comments

Comments

@ctb
Copy link
Member

ctb commented Oct 19, 2022

Start Jupyter Notebook on farm

Titus Brown, [email protected]

June 19, 2023

To edit: hackmd-github-sync-badge / latest on github

(Adapted from Nick Ulle's tutorial!)

Instructions

First, create a mamba environment with jupyter notebook installed:

module load mamba
mamba create -y -n jup notebook nb_conda_kernels

Activate it:

mamba activate jup

Set a password:

jupyter notebook password

Create a script run-jupyter-on-node.sh containing:

#! /bin/bash -eu

# initialize conda
conda_base=$(conda info --base)
. ${conda_base}/etc/profile.d/conda.sh

# activate relevant environment - CUSTOMIZE ME
conda activate jup

### pick a port
read LOWERPORT UPPERPORT < /proc/sys/net/ipv4/ip_local_port_range

port="$(shuf -i $LOWERPORT-$UPPERPORT -n 1)"
while :; do
  netstat -taln | egrep ":$port.*LISTEN" || break
  port="$(shuf -i $LOWERPORT-$UPPERPORT -n 1)"
done

### print out stuff
cat <<EOF

You need to use SSH tunneling to port forward from your desktop to Jupyter Lab.

Run the following command in a new terminal on your machine:

ssh -L${port}:${HOSTNAME}:${port} [email protected] -N

Then point your browser to http://localhost:${port}

EOF

### run me!
jupyter notebook --no-browser --ip=${HOSTNAME} --port=${port}

and then run with srun:

srun -p high2 --time=3:00:00 --nodes=1 \
            --cpus-per-task 1 --mem 5GB \
            --pty bash ./run-jupyter-on-node.sh
@ctb
Copy link
Member Author

ctb commented Oct 19, 2022

ref #44 rstudio server

@ctb
Copy link
Member Author

ctb commented Feb 4, 2023

A more automated solution based on #44 rstudio-server.

hackmd: https://hackmd.io/9Uk2wAOiQs6hnnaV_39DtQ?view

Two or three things to note and/or change:

  • there's no guard against running this on the head node, which we might want to change!
  • I chose to instruct people to set a single password with jupyter notebook password rather than generating a new one each time with xkcdpass
  • we might want to redirect jupyter notebook output somewhere. right now it goes to stdout which is distracting.

hackmd copy/pasted below:

Start Jupyter Notebook from head node on farm

The below uses the mambaforge installation of conda.

First, create a mamba environment containing jupyter notebook:

mamba create -y -n jup notebook nb_conda_kernels

Activate it:

mamba activate jup

Set a password:

jupyter notebook password

Create a script run-jupyter-on-node.sh containing:

#! /bin/bash -eu

# initialize conda
conda_base=$(conda info --base)
. ${conda_base}/etc/profile.d/conda.sh

# activate relevant environment - CUSTOMIZE ME
conda activate jup

### pick a port
read LOWERPORT UPPERPORT < /proc/sys/net/ipv4/ip_local_port_range

port="$(shuf -i $LOWERPORT-$UPPERPORT -n 1)"
while :; do
  netstat -taln | egrep ":$port.*LISTEN" || break
  port="$(shuf -i $LOWERPORT-$UPPERPORT -n 1)"
done

### print out stuff
cat <<EOF

You need to use SSH tunneling to port forward from your desktop to Jupyter Lab.

Run the following command in a new terminal on your machine:

ssh -L${port}:${HOSTNAME}:${port} [email protected] -N

Then point your browser to http://localhost:${port}

EOF

### run me!
jupyter notebook --no-browser --ip=${HOSTNAME} --port=${port}

and then run with srun:

srun -p high2 --time=3:00:00 --nodes=1 \
            --cpus-per-task 1 --mem 5GB \
            --pty bash ./run-jupyter-on-node.sh

@ccbaumler
Copy link
Contributor

This has worked for me on the first try. However, the original comment's link is broken.

@ctb
Copy link
Member Author

ctb commented Mar 24, 2023

@ctb ctb changed the title nick's notes on running jupyter on remote computers running jupyter notebooks on farm Jun 19, 2023
@ctb
Copy link
Member Author

ctb commented Jun 19, 2023

updated for june 19, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants