Remote Debugging with VS Code

Introduction

In this tutorial, we will show how to set up remote debugging with VS Code on the Neuro Platform using the Neu.ro project template.

Initializing a new project

Make sure you have Neu.ro CLI and cookiecutter installed:
1
$ pip install pipx
2
$ pipx install neuro-all cookiecutter
3
$ neuro login
Copied!
Then, initialize an empty project:
1
$ cookiecutter gh:neuro-inc/cookiecutter-neuro-project --checkout release
Copied!
The project initialization command asks several questions about your project:
1
project_name [Name of the project]: Neuro VSCode
2
project_dir [neuro-vscode]:
3
project_id [neuro-vscode]:
4
code_directory [modules]:
5
preserve Neuro Flow template hints [yes]:
Copied!

Configuring the project

Add debugpy to your project's requirements.txt file (located in the project's root folder):
1
neuro-flow
2
3
flake8
4
mypy
5
isort
6
black
7
debugpy
Copied!
Add the following lines to the beginning of your code file. In this example, it's modules/train.py.
1
import debugpy
2
debugpy.listen(("0.0.0.0", 5678))
3
debugpy.wait_for_client()
Copied!
Next, configure the project's environment on the Neu.ro Platform:
1
$ neuro-flow build myimage
Copied!
When the image is built, you can upload your code from a local file to the platform storage:
1
$ neuro-flow upload code
Copied!
By default, this will upload everything from your project's modules folder to the storage:<your_project_id>/modules storage folder. To configure the source and the target for this command, go to your project's .neuro/live.yml file and find the code section under volumes:
1
volumes:
2
data:
3
remote: storage:$[[ flow.project_id ]]/data
4
mount: /project/data
5
local: data
6
code:
7
remote: storage:$[[ flow.project_id ]]/modules
8
mount: /project/modules
9
local: modules
10
config:
11
remote: storage:$[[ flow.project_id ]]/config
12
mount: /project/config
13
local: config
14
read_only: True
Copied!
Here, you can specify your local code folder and the storage folder you want to upload this code to.

Running your code

In this example, we will be running a training job based on the code contained in the train.py file we just uploaded to the platform storage. To do this, run:
1
$ neuro-flow run train
Copied!
Once the job is running, detach from it by pressing Ctrl+P, Ctrl+Q and run the following command:
1
$ neuro job port-forward <job-id> 5678:5678
Copied!
This will allow you to access the job by the 5678 port.

Debugging

Open your code file in VS Code and navigate to Run > Start Debugging or press F5:
Select Remote Attach:
Enter localhost as the host name and the job's port number (in this case, it's 5687):
When this is done, you can set the breakpoint and start debugging.