What I want to do
I am working on a multi-GPU server, and would like to open a Jupyter notebook that only runs on some currently unused GPU (which may change from session to session).
In other words, at the beginning of each session, I want to export CUDA_VISIBLE_DEVICES=i, replacing i with the index of a currently unused GPU. Then I want to open a Jupyter notebook that actually sees this environment variable.
Crucially, I want to open the Jupyter notebook in VS Code (i.e., my local VS Code with the remote development extension).
Both my local machine and the server run on Linux.
I am aware that:
- I could open the notebook in my local browser instead
- or I could set the environment variable inside the notebook.
These are not the answers I am looking for. VS Code has a nicer user experience, and I don't want to edit the first cell of my notebook every time I open it.
What I tried
Ideally I would like to do (inside the VS Code remote development terminal):
export MYVAR=todayschoice
code test.ipynb
where a minimal test.ipynb could just contain a single cell %env. Unfortunately, the output currently does not contain MYVAR. Using code with the options -r or -n does not change anything.
On my local machine, I would work around the issue by typing the commands in my system's terminal instead of VS Code's terminal. (I tried it and it worked.) This is not possible in the remote case because the server doesn't have VS Code.
jupyter notebookinstead ofcode? This would open the notebook in my browser (the first alternative I mentioned in my question). But why can't I "open a snapshot of the "inherited" environment" in VS Code instead? -- Anyway, right now I'm setting the variable inside the notebook (in VS Code, the second alternative I mentioned), and it works okay, but I'd still be interested in other solutions.