├── LICENSE ├── README.md ├── _init.py ├── config.conf ├── init.sh ├── requirements.txt └── run_debug.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Simon Schrodi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vscode_remote_debugging 2 | This repository may contain useful scripts for debugging on a remote cluster. 3 | 4 | Note that we are using conda (e.g., mini-forge). If you do not want to use it, you can change the corresponding parts. 5 | 6 | ## How to set up once 7 | 0. Clone this repository into your current working repository, i.e., where you code cool stuff. 8 | 1. Install `debugpy` and `path`. 9 | 2. In `.vscode/launch.json`: `Add configuration` -> `Python` -> `Remote Attach`. You can add any host name and port number (we will configure this in `config.conf`). You can remove `pathMappings`. Also remove comments. 10 | 3. Adapt configurations in `vscode_remote_debugging/config.conf`. 11 | 12 | ## How to debug 13 | 0. Set up a script for debugging similar to `vscode_remote_debugging/run_debug.sh`. 14 | 1. Grab yourself a GPU, e.g. `swrap srun -p super_large_cluster --pty bash`. 15 | 2. Run `bash vscode_remote_debugging/init.sh`. 16 | 3. Run `bash vscode_remote_debugging/run_debug.sh` (might take a second to start). 17 | 4. Attach to the run via VSCode. 18 | 5. Debug as if you were running the code on your local machine. 19 | -------------------------------------------------------------------------------- /_init.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | from path import Path 3 | import json 4 | 5 | parser = argparse.ArgumentParser(description='Setup debugging') 6 | parser.add_argument('--ip', type=str, help='IP address') 7 | parser.add_argument('--port', type=int, help='Port') 8 | parser.add_argument('--path', type=str, help='Path to launch.json') 9 | args = parser.parse_args() 10 | 11 | path = Path(args.path) 12 | assert path.exists() 13 | 14 | print(f'Set debbuging ip to {args.ip} and port {args.port} in {path}') 15 | 16 | with open(path) as f: 17 | data = json.load(f) 18 | 19 | data['configurations'][0]['connect']['host'] = args.ip 20 | data['configurations'][0]['connect']['port'] = args.port 21 | 22 | with open(path, 'w') as json_file: 23 | json.dump(data, json_file, indent=4) 24 | -------------------------------------------------------------------------------- /config.conf: -------------------------------------------------------------------------------- 1 | WORKDIR /path/to/repo 2 | PORT 4242 3 | LAUNCH_JSON .vscode/launch.json 4 | SOURCE /home/usr/.bashrc 5 | ENV my_env 6 | -------------------------------------------------------------------------------- /init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #swrap srun -p testdlc_gpu-rtx2080 --pty bash 4 | 5 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 6 | while read var value 7 | do 8 | export "$var"="$value" 9 | done < $SCRIPT_DIR/config.conf 10 | 11 | cd $WORKDIR 12 | source $SOURCE 13 | conda activate $ENV 14 | 15 | ip=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1') 16 | python vscode_remote_debugging/_init.py --ip $ip --port $PORT --path $LAUNCH_JSON 17 | conda deactivate 18 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | path 2 | debugpy -------------------------------------------------------------------------------- /run_debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 4 | while read var value 5 | do 6 | export "$var"="$value" 7 | done < $SCRIPT_DIR/config.conf 8 | 9 | # python args 10 | arg1="Python" 11 | arg2="arguments" 12 | 13 | cd $WORKDIR 14 | source $SOURCE 15 | conda activate $ENV 16 | python -m debugpy --listen 0.0.0.0:$PORT --wait-for-client $WORKDIR/main.py $arg1 $arg2 17 | conda deactivate --------------------------------------------------------------------------------