{"id":20489269,"url":"https://github.com/gravity-sjtu/gravityspawner","last_synced_at":"2025-12-14T12:41:51.540Z","repository":{"id":37208747,"uuid":"502695404","full_name":"gravity-sjtu/gravityspawner","owner":"gravity-sjtu","description":"A spawner for JupyterHub to let user adjust resources","archived":false,"fork":false,"pushed_at":"2022-07-06T10:42:47.000Z","size":115,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T21:08:56.229Z","etag":null,"topics":["jupyter","jupyterhub","jupyterhub-spawner","pbs","slurm","spawner","torque"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/gravityspawner/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gravity-sjtu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-12T18:22:53.000Z","updated_at":"2022-07-19T16:06:38.000Z","dependencies_parsed_at":"2022-09-09T08:02:47.440Z","dependency_job_id":null,"html_url":"https://github.com/gravity-sjtu/gravityspawner","commit_stats":null,"previous_names":["lalalabox/gravityspawner"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-sjtu%2Fgravityspawner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-sjtu%2Fgravityspawner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-sjtu%2Fgravityspawner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravity-sjtu%2Fgravityspawner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gravity-sjtu","download_url":"https://codeload.github.com/gravity-sjtu/gravityspawner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246453944,"owners_count":20780046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jupyter","jupyterhub","jupyterhub-spawner","pbs","slurm","spawner","torque"],"created_at":"2024-11-15T17:12:03.644Z","updated_at":"2025-12-14T12:41:51.458Z","avatar_url":"https://github.com/gravity-sjtu.png","language":"Python","readme":"# gravityspawner for Jupyterhub\n\nThis package is for [**Gravity of DOA, SJTU**](https://gravity.sjtu.edu.cn/)\n\nWe attend to select PBS/Slurm job queue first, then input arguments like *hours, memory, CPU cores* to spawn a Jupyter server.\n\nWe need to combine *templates* and *wrapspawner* to achieve this goal:\n```shell\n├── jupyterhub\n│   └── templates               # jinja template\n│       ├── page.html           # change the navigation bar, add some button\n│       ├── spawn.html          # user can select and input arguments such as hour, cpu, memory. use JavaScript to hide the input form.\n│       └── spawn_pending.html  # waiting for spawning server, add some message\n└── src\n    ├── gravityspawner\n        ├── gravityspawner.py   # get extra arguments from jinja template, then pass them to batchspawner [thanks wrapspawner.ProfilesSpawner]. set resource limits as well.\n```\n\n## Installation\n\nInstall via **pip**:\n\n   ```shell\n   pip install gravityspawner\n   ```\n   Or, another better way to use **pip**:\n   ```shell\n   python -m pip install gravityspawner\n   ```\n\n## Usage\n1. Add lines in `jupyterhub_config.py`:\n   \n   ```python\n      c.JupyterHub.spawner_class = 'gravityspawner.GravitySpawner'\n   ```\n\n2. If we use `batchspawner.TorqueSpawner`, then add these lines in `jupyterhub_config.py`:\n\n   ```python\n   c.GravitySpawner.profiles = [\n      ('[ LOGIN 01 ] 8 cores 8 GB running forever (unless idle for more than 3 days)', 'local', 'jupyterhub.   spawner.LocalProcessSpawner', {'ip':'0.0.0.0'} ),\n      ('[ SMALL ] Max: [ 72 cores + 400 GB ]', 'small', 'batchspawner.TorqueSpawner',\n         dict(min_max_hour=(1,12),min_max_cpu=(8,72),min_max_memory=(10,360))),\n      ('[ GPU ] Max: [ 72 cores + 400 GB + NVIDIA Tesla V100 32GB ]', 'gpu', 'batchspawner.TorqueSpawner',\n         dict(min_max_hour=(1,12),min_max_cpu=(8,72),min_max_memory=(10,360))),\n      ('[ FAT ] Max: [ 192 cores + 6000 GB ]', 'fat', 'batchspawner.TorqueSpawner',\n         dict(min_max_hour=(1,12),min_max_cpu=(8,192),min_max_memory=(400,6000))),\n   ]\n   ```\n   **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)\n\nThe final *piece of* configuration of `jupyterhub_config.py` like this:\n```python\nimport batchspawner\nimport gravityspawner\n\n# our jinja template, change front-end style and add extra options\nc.JupyterHub.template_paths = ['/opt/jupyterhub/templates']\n\n# specify the spawner we use\nc.JupyterHub.spawner_class = 'gravityspawner.GravitySpawner'\n\n# PBS script to start Jupyter on computing nodes!\nc.TorqueSpawner.batch_script = '''#!/bin/bash\n#PBS -N jupyterhub\n#PBS -q {queue}\n#PBS -l walltime={runtime}:00:00\n#PBS -l nodes=1:ppn={nprocs}\n#PBS -l mem={memory}gb\n####PBS -v {keepvars}\n#PBS -V\n#PBS -j oe\n#PBS -o /home/$USER/.jupyter/jupyterhub.log\nconda deactivate 1\u003e/dev/null 2\u003e\u00261\nconda deactivate 1\u003e/dev/null 2\u003e\u00261\nmodule load anaconda/conda-4.12.0 cuda/cuda-11.3\nsource /opt/conda/conda-4.12.0/bin/activate\nconda activate /opt/jupyterhub/envs/hub02\n{cmd}\n'''\n\n# Defaul options of Spawner. local + small + gpu + fat\nc.GravitySpawner.profiles = [\n   ('[ LOGIN 02 ] 8 cores 8 GB running forever (unless idle for more than 3 days)', 'local', 'jupyterhub.spawner.LocalProcessSpawner', {'ip':'0.0.0.0'} ),\n   ('[ SMALL ] Max: [ 72 cores + 400 GB ]', 'small', 'batchspawner.TorqueSpawner',\n      dict(min_max_hour=(1,12),min_max_cpu=(8,72),min_max_memory=(10,360))),\n   ('[ GPU ] Max: [ 72 cores + 400 GB + NVIDIA Tesla V100 32GB ]', 'gpu', 'batchspawner.TorqueSpawner',\n      dict(min_max_hour=(1,12),min_max_cpu=(8,72),min_max_memory=(10,360))),\n   ('[ FAT ] Max: [ 192 cores + 6000 GB ]', 'fat', 'batchspawner.TorqueSpawner',\n      dict(min_max_hour=(1,12),min_max_cpu=(8,192),min_max_memory=(400,6000))),\n]\n```\n\n## Example\n\nThis is a typical dropdown menu letting the user choose between local **Login node** and **Torque/PBS queues**\n![selection menu](https://github.com/lalalabox/gravityspawner/raw/master/imgs/select.png)\n\nAfter using `jupyterhub/templates`, we can input args according to our selection, e.g.🌰\n1. select **login node**, which is `'local'` in code:\n![select login node](https://github.com/lalalabox/gravityspawner/raw/master/imgs/input_local.png)\n2. select **Torque/PBS gpu queue**, which is `'gpu'` in code:\n![select PBS gpu queue](https://github.com/lalalabox/gravityspawner/raw/master/imgs/input_gpu.png)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgravity-sjtu%2Fgravityspawner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgravity-sjtu%2Fgravityspawner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgravity-sjtu%2Fgravityspawner/lists"}