diff --git a/.dockerignore b/.dockerignore index c4860c76..15c0a9d5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,4 +13,5 @@ !environments/** !examples/** !openfold3/** -!scripts/** \ No newline at end of file +!scripts/** +!examples/** diff --git a/docs/source/debugging_how_to.md b/docs/source/debugging_how_to.md new file mode 100644 index 00000000..b0f88906 --- /dev/null +++ b/docs/source/debugging_how_to.md @@ -0,0 +1,85 @@ +# Debugging OpenFold + +## Docker + +### Prerequisites + +- VS Code with the debugpy extension +- OpenFold docker image with `debugpy` installed + + +```bash +docker run --rm \ + --ipc=host \ + -it openfold-docker:devel \ + python -c "import debugpy; print(debugpy)" +... + +``` + +### Step 1: Instrument your code + +Put this snippet at the very top of your launch script + +```python +import debugpy +debugpy.listen(("0.0.0.0", 5678)) +print("Waiting for debugger to attach...") +debugpy.wait_for_client() +``` + +For example, put this at the very top of `openfold3/run_openfold.py` + + +### Step 2: Create a launch configuration + +Create `.vscode/launch.json` to tell VS Code to connect to `localhost:5678` on the docker container. + +```json +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Remote Attach", + "type": "debugpy", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder:openfold-3}", + "remoteRoot": "/opt/openfold3" + } + ] + } + ] +} +``` + +> **Note**: Use `${workspaceFolder}` instead if openfold-3 is your only workspace folder. + +### Step 3: Launch your container + +Launch the docker container with the debugger port exposed: + +```bash +docker run --rm \ + --gpus all \ + --ipc=host \ + -p 5678:5678 \ + -it openfold-docker:devel \ + run_openfold predict \ + --query_json /data/query.json \ + --runner_yaml ./examples/example_runner_yamls/low_mem.yml \ + --output_dir /tmp/output +``` + +> **Important**: The `-p 5678:5678` flag is required to expose the debugger port. + +The script will print "Waiting for debugger to attach..." and pause until you connect. + +### Step 4: Attach the debugger + +In VS Code, open the Run and Debug panel (`Ctrl+Shift+D`) and click the green play button to attach. diff --git a/docs/source/index.md b/docs/source/index.md index fd6eb2d1..b228296a 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -67,6 +67,9 @@ Inference precomputed_msa_generation_how_to precomputed_msa_how_to template_how_to + +Development +debugging_how_to ``` ```{toctree} diff --git a/pyproject.toml b/pyproject.toml index 36567390..126a20e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,7 @@ test = [ "pytest-xdist", "pytest-cov", "pytest-benchmark", + "debugpy", ] [project.optional-dependencies]