Jupyter Notebook Server Service

The example execute_jupyter_notebook_server.py demonstrates executing a Jupyter Notebook server as a Trains service. The example script creates an SSH server, and runs Jupyter Notebook as a subprocess. We integrate Trains into the notebooks running on the Jupyter Notebook server by passing environment variables to the subprocess which point to a Trains configuration file, a Trains Server host configuration (web server, API server, and files server), and Trains API credentials. Trains logs the server links and console output, including the notebooks run on the server, in the example script's Task. When the script runs, it creates an experiment named Remote Jupyter NoteBook which is associated with the examples project in the Trains Web (UI).

Running the Jupyter Notebook server service

  1. The example script must run at least once before it can execute as a Trains Agent service, because the Task must be stored in Trains Server to enqueue for Trains Agent to fetch and execute.

    python execute_jupyter_notebook_server.py

  2. Trains Agent must be running in services mode and listening to the services queue.

    For example:

    trains-agent daemon --services-mode --detached --queue services --create-queue --cpu-only

  3. Enqueue the Jupyter Notebook server Task.

    1. In the Train Web (UI), Project page > examples project > right click the Remote Jupyter NoteBook experiment.
    2. In the context menu, click Enqueue > select the services queue > ENQUEUE.

    The status changes to Pending and then to Running. Once it is running, the Jupyter Notebook server is ready to run notebooks.

Logging the Jupyter Notebook server

Trains stores the Jupyter Notebook server links in the Task.comment property which appears in the Trains Web (UI), INFO tab, DESCRIPTION area.

task.comment += "\n" + "".join(
    line for line in new_lines if "http://" in line or "https://" in line
    )

It shows the server links are:

[I 12:54:48.940 NotebookApp] http://osboxes:8889/?token=3be82d87e83268934dd086e3b136cc408d4bd12e23409f3a
[I 12:54:48.940 NotebookApp]  or http://127.0.0.1:8889/?token=3be82d87e83268934dd086e3b136cc408d4bd12e23409f3a
        http://osboxes:8889/?token=3be82d87e83268934dd086e3b136cc408d4bd12e23409f3a
     or http://127.0.0.1:8889/?token=3be82d87e83268934dd086e3b136cc408d4bd12e23409f3a

The Jupyter Note Server console output appears in the RESULTS tab, LOG sub-tab, including log entries for the notebooks run on the server.

To test the Jupyter Notebook, we ran a notebook named audio_preprocessing_example.ipynb. The log shows it was saved:

[I 12:57:27.758 NotebookApp] Saving file at /Projects/trains-internal/examples/frameworks/pytorch/notebooks/audio/audio_preprocessing_example.ipynb