Skip to main content

GravitySpawner: A spawner for Jupyterhub to let user select and input options at the same time

Project description

gravityspawner for Jupyterhub

This package is for Gravity of DOA, SJTU

We attend to select PBS/Slurm job queue first, then input arguments like hours, memory, CPU cores to spawn a Jupyter server.

We need to combine templates and wrapspawner to achieve this goal:

├── jupyterhub
│   └── templates               # jinja template       ├── page.html           # change the navigation bar, add some button       ├── spawn.html          # user can select and input arguments such as hour, cpu, memory. use JavaScript to hide the input form.       └── spawn_pending.html  # waiting for spawning server, add some message
└── src
    ├── gravityspawner
        ├── gravityspawner.py   # get extra arguments from jinja template, then pass them to batchspawner [thanks wrapspawner.ProfilesSpawner]. set resource limits as well.

Installation

Install via pip:

pip install gravityspawner

Or, another better way to use pip:

python -m pip install gravityspawner

Usage

  1. Add lines in jupyterhub_config.py:

       c.JupyterHub.spawner_class = 'gravityspawner.GravitySpawner'
    
  2. If we use batchspawner.TorqueSpawner, then add these lines in jupyterhub_config.py:

    c.GravitySpawner.profiles = [
       ('[ LOGIN 01 ] 8 cores 8 GB running forever (unless idle for more than 3 days)', 'local', 'jupyterhub.   spawner.LocalProcessSpawner', {'ip':'0.0.0.0'} ),
       ('[ SMALL ] Max: [ 72 cores + 400 GB ]', 'small', 'batchspawner.TorqueSpawner',
          dict(min_max_hour=(1,12),min_max_cpu=(8,72),min_max_memory=(10,360))),
       ('[ GPU ] Max: [ 72 cores + 400 GB + NVIDIA Tesla V100 32GB ]', 'gpu', 'batchspawner.TorqueSpawner',
          dict(min_max_hour=(1,12),min_max_cpu=(8,72),min_max_memory=(10,360))),
       ('[ FAT ] Max: [ 192 cores + 6000 GB ]', 'fat', 'batchspawner.TorqueSpawner',
          dict(min_max_hour=(1,12),min_max_cpu=(8,192),min_max_memory=(400,6000))),
    ]
    

    profiles here represent display, key, Spawner, options. We can set limits of resource here, such as hour, memory, CPU cores. If you need more options or change options, you also need to edit the jupyterhub/templates/spawn.html (front-end)

The final piece of configuration of jupyterhub_config.py like this:

import batchspawner
import gravityspawner

# our jinja template, change front-end style and add extra options
c.JupyterHub.template_paths = ['/opt/jupyterhub/templates']

# specify the spawner we use
c.JupyterHub.spawner_class = 'gravityspawner.GravitySpawner'

# PBS script to start Jupyter on computing nodes!
c.TorqueSpawner.batch_script = '''#!/bin/bash
#PBS -N jupyterhub
#PBS -q {queue}
#PBS -l walltime={runtime}:00:00
#PBS -l nodes=1:ppn={nprocs}
#PBS -l mem={memory}gb
####PBS -v {keepvars}
#PBS -V
#PBS -j oe
#PBS -o /home/$USER/.jupyter/jupyterhub.log
conda deactivate 1>/dev/null 2>&1
conda deactivate 1>/dev/null 2>&1
module load anaconda/conda-4.12.0 cuda/cuda-11.3
source /opt/conda/conda-4.12.0/bin/activate
conda activate /opt/jupyterhub/envs/hub02
{cmd}
'''

# Defaul options of Spawner. local + small + gpu + fat
c.GravitySpawner.profiles = [
   ('[ LOGIN 02 ] 8 cores 8 GB running forever (unless idle for more than 3 days)', 'local', 'jupyterhub.spawner.LocalProcessSpawner', {'ip':'0.0.0.0'} ),
   ('[ SMALL ] Max: [ 72 cores + 400 GB ]', 'small', 'batchspawner.TorqueSpawner',
      dict(min_max_hour=(1,12),min_max_cpu=(8,72),min_max_memory=(10,360))),
   ('[ GPU ] Max: [ 72 cores + 400 GB + NVIDIA Tesla V100 32GB ]', 'gpu', 'batchspawner.TorqueSpawner',
      dict(min_max_hour=(1,12),min_max_cpu=(8,72),min_max_memory=(10,360))),
   ('[ FAT ] Max: [ 192 cores + 6000 GB ]', 'fat', 'batchspawner.TorqueSpawner',
      dict(min_max_hour=(1,12),min_max_cpu=(8,192),min_max_memory=(400,6000))),
]

Example

This is a typical dropdown menu letting the user choose between local Login node and Torque/PBS queues selection menu

After using jupyterhub/templates, we can input args according to our selection, e.g.🌰

  1. select login node, which is 'local' in code: select login node
  2. select Torque/PBS gpu queue, which is 'gpu' in code: select PBS gpu queue

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gravityspawner-0.0.2.tar.gz (114.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gravityspawner-0.0.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file gravityspawner-0.0.2.tar.gz.

File metadata

  • Download URL: gravityspawner-0.0.2.tar.gz
  • Upload date:
  • Size: 114.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for gravityspawner-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b85c0470ac45552831ad80a9dc49cb36381ef578f1fedc1c58a575b128f97109
MD5 befcc1d1e2f688da157acc69dc487574
BLAKE2b-256 4bf0ab6817bca392ee5c1cc8caa070569205e1bb33f418ba09b7eb6116a9e787

See more details on using hashes here.

File details

Details for the file gravityspawner-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: gravityspawner-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for gravityspawner-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf6e113e2d0b6584f8a6a5c29c3f60352a88411cfe4a4e8f3270606bd45aa800
MD5 3bf0273d76350d911f1140732d6c21f9
BLAKE2b-256 e1459c0cb1d83cc15083e1ae87132038f6f4edec0a241e1fc80ecb37413605c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page