Slicer Jupyter docker with CUDA

Hello I try to customize official slicer docker for jupyter, and integrate it with vs code development in a container.

I managed already to Install and test CUDA - which seem to works ok (pytorch detects it)

Now I have some problems, first I want to ask is it possible to use slicer extensions from the jupyter - primarly but not exclusively I am interested in installing SlicerRadiomics extension and use it from jupyter.

Secondly I try to install extension by modyfing install.sh
and adding after SlicerJupyter is installed


echo "Install extensions"
$slicer_executable -c '
em = slicer.app.extensionsManagerModel()
extensionMetaData = em.retrieveExtensionMetadataByName("SlicerRadiomics")
if slicer.app.majorVersion*100+slicer.app.minorVersion < 413:
    # Slicer-4.11
    itemId = extensionMetaData["item_id"]
    url = f"{em.serverUrl().toString()}/download?items={itemId}"
    extensionPackageFilename = f"{slicer.app.temporaryPath}/{itemId}"
    slicer.util.downloadFile(url, extensionPackageFilename)
else:
    # Slicer-4.13
    itemId = extensionMetaData["_id"]
    url = f"{em.serverUrl().toString()}/api/v1/item/{itemId}/download"
    extensionPackageFilename = f"{slicer.app.temporaryPath}/{itemId}"
    slicer.util.downloadFile(url, extensionPackageFilename)
    # Prevent showing popups for installing dependencies
    # (this is not needed right now for SlicerJupyter, but we still add this line here
    # because this docker image may be used by other projects as a starting point)
    em.interactive = False
em.installExtension(extensionPackageFilename)
'

Yet It gives error

[2022-05-21T18:07:13.536Z] Install extensions
[2022-05-21T18:07:15.830Z] Traceback (most recent call last):
[2022-05-21T18:07:15.830Z]   File "<string>", line 12, in <module>
[2022-05-21T18:07:15.831Z] KeyError: '_id'
[2022-05-21T18:07:16.363Z] The command '/bin/sh -c ./install.sh ${HOME}/Slicer/Slicer &&     rm ${HOME}/install.sh' returned a non-zero code: 1
[2022-05-21T18:07:16.366Z] Stop (15155 ms): Run: docker build -f /home/jakub/projects/slicerModifB/.devcontainer/Dockerfile -t vsc-slicermodifb-cec2d2e6cdb09b3c149f8f6bee02d187 /home/jakub/projects/slicerModifB/.devcontainer
[2022-05-21T18:07:16.367Z] Error: Command failed: docker build -f /home/jakub/projects/slicerModifB/.devcontainer/Dockerfile -t vsc-slicermodifb-cec2d2e6cdb09b3c149f8f6bee02d187 /home/jakub/projects/slicerModifB/.devcontainer
[2022-05-21T18:07:16.367Z]     at Tu (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:221:3219)
[2022-05-21T18:07:16.367Z]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-05-21T18:07:16.367Z]     at async LR (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:221:1567)
[2022-05-21T18:07:16.367Z]     at async zy (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:221:594)
[2022-05-21T18:07:16.367Z]     at async $R (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:226:2007)
[2022-05-21T18:07:16.367Z]     at async Zy (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:226:3112)
[2022-05-21T18:07:16.367Z]     at async BR (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:226:12448)
[2022-05-21T18:07:16.367Z]     at async qR (/home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js:226:12204)
[2022-05-21T18:07:16.370Z] Stop (15293 ms): Run: /snap/code/97/usr/share/code/code /home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/jakub/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-data-folder .vscode-server/data/Machine --container-system-data-folder /var/vscode-server --workspace-folder /home/jakub/projects/slicerModifB --workspace-mount-consistency cached --id-label vsch.local.folder=/home/jakub/projects/slicerModifB --id-label vsch.quality=stable --log-level debug --log-format json --config /home/jakub/projects/slicerModifB/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-05-21T18:07:16.370Z] Exit code 1
[2022-05-21T18:07:16.372Z] Command failed: /snap/code/97/usr/share/code/code /home/jakub/.vscode/extensions/ms-vscode-remote.remote-containers-0.234.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/jakub/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-data-folder .vscode-server/data/Machine --container-system-data-folder /var/vscode-server --workspace-folder /home/jakub/projects/slicerModifB --workspace-mount-consistency cached --id-label vsch.local.folder=/home/jakub/projects/slicerModifB --id-label vsch.quality=stable --log-level debug --log-format json --config /home/jakub/projects/slicerModifB/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-05-21T18:07:16.373Z] Exit code 1

My docker project

This sounds great and it seems that you are making good progress.

Yes, this should be no problem at all. You can install other extensions the same way as SlicerJupyter. You can use any modules in any extensions from Jupyter the same way as from the Python console or any Python module. You can find more information in the Python FAQ.

If _id key is missing from the extension description then it means that the extension is not available for that Slicer version. I would recommend to use the latest Slicer Stable version now (Slicer 5.0.x). You can see the list of extensions available for this version here:

https://extensions.slicer.org/catalog/All/30822/linux

1 Like

Fantastic, yes now it works as I got newer version - when I open python console in the container .Hovewer How to get a token inside the container

as I need http://127.0.0.1:8888/?token to open jupyter notebook server connection - I know that I can do it by building in a normal way docker image from command line but from VS code inside the container it is less obvious for me :slight_smile:

You can print the token to the output and capture it from there; or write the token to a file in a mapped folder and read it from that file.

Alternatively, you can specify a custom token for the Jupyter server, for example by passing it as a command-line argument to the docker container or via an environment variable.

1 Like

ok It is working now thanks @lassoan !, If you consider it worth it You may use it as an example for others (if yes here is the link to repository)

However both dataspell and vs code do not support interactive widgets - that simply works in browser, Is there any IDE that supports it?

Thanks for sharing your results. What were the main changes that you had to do?

VS Code has lots of assumptions about your Jupyter server and kernel which are often not valid. For example, in Slicer’s Python environment the Python interpreter has a special name, we use xeus-python kernel and not the default native Python kernel - which VS Code may not be prepared for.

changed base to nvidia/cuda:11.3.1-base-ubuntu20.04

added some basic libraries like manpages-dev

installed CUDA 11.3

Changed version of the Slicer to newer

installed some python packages mainly pytorch and monai with most of its dependencies
for convenience
created some additional folders, added jupyterlab_github

1 Like