From 5f322147400e4601c6707602e904ff38b208bafd Mon Sep 17 00:00:00 2001
From: Viktor Vorobev <vorobev@in.tum.de>
Date: Wed, 9 Mar 2022 14:41:11 +0000
Subject: [PATCH] Merged in NUIT-286 (pull request #40)

NUIT-286, NRRPLT-8239 Using VC with docker installation instructions

* [NRRPLT-8239] add tutorial for running jupyter with local docker installation

[NUIT-286] Adding lost commit

* [NRRPLT-8239] fix inline code

[NUIT-286] Adding lost commit

* [NUIT-286] Update formatting

* [NUIT-286] Update formatting

* [NUIT-286] Update formatting

* [NUIT-286] Fix pylint issues and fix Jennkinsfile

* [NUIT-286] fix reviews

* [NUIT-286] launching_exp.rst edited online with Bitbucket

Approved-by: Eloy Retamino
Approved-by: Vahid Zolfaghari
---
 Jenkinsfile                                   |  2 +-
 .../doc/source/tutorials/launching_exp.rst    | 38 ++++++++++++++++++-
 hbp_nrp_virtual_coach/pynrp/virtual_coach.py  |  4 +-
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 4c67b04..f1c50f9 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -120,7 +120,7 @@ pipeline {
                     // upload package
                     withCredentials([usernamePassword(credentialsId: 'nexusadmin', usernameVariable: 'USER', passwordVariable: 'PASSWORD')])
                     {
-                        sh 'pip3 install twine'
+                        sh 'pip3 install twine packaging'
                         sh 'twine upload -u $USER -p $PASSWORD --repository-url ${NexusPyPiRepoUrl} hbp_nrp_virtual_coach/dist/*.whl'
                     }
                 }
diff --git a/hbp_nrp_virtual_coach/doc/source/tutorials/launching_exp.rst b/hbp_nrp_virtual_coach/doc/source/tutorials/launching_exp.rst
index 65f4445..673d2f6 100644
--- a/hbp_nrp_virtual_coach/doc/source/tutorials/launching_exp.rst
+++ b/hbp_nrp_virtual_coach/doc/source/tutorials/launching_exp.rst
@@ -3,12 +3,15 @@
 ..  sectionauthor:: Eloy Retamino <retamino@ugr.es>
 
 Launching an Experiment from the Virtual Coach
-========================================================
+==============================================
 
 Starting the Virtual Coach
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-There is a special alias for running the Virtual Coach. For this alias to work, :code:`$HBP/user-scripts/nrp_aliases` has to be sourced in your *bash.rc*. The ``configure_nrp`` script takes care of that automatically. The Virtual Coach alias is :code:`cle-virtual-coach` and can be run in three different ways:
+Local source installation
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In case you have installed NRP from the :ref:`source <source-installation>`, there is a special alias for running the Virtual Coach. For this alias to work, :code:`$HBP/user-scripts/nrp_aliases` has to be sourced in your *bash.rc*. The ``configure_nrp`` script takes care of that automatically. The Virtual Coach alias is :code:`cle-virtual-coach` and can be run in three different ways:
 
 There are different ways to start a Virtual Coach instance. With a local :abbr:`NRP (Neurorobotics Platform)` install you can use the alias :code:`cle-virtual-coach` in three different ways:
 
@@ -26,6 +29,37 @@ There are different ways to start a Virtual Coach instance. With a local :abbr:`
 
 This information is also available in the alias help :code:`cle-virtual-coach -h`.
 
+
+Local Docker installation
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can also use Virtual Coach with the local :ref:`Docker installation <docker-installation>`. In order to do that, you should follow these steps:
+
+1. Install the latest NRP Docker version with the command of :code:`./nrp_installer.sh install latest` the script exposes port 8888 by default for the Jupyter.
+
+2. Run :code:`./nrp_installer.sh connect_backend` which opens a terminal inside backend container.
+
+3. Run the command of :code:`cle-virtual-coach jupyter notebook "--ip=0.0.0.0"` inside backend container to start Jupyter.
+
+This will give you a URL like :code:`http://localhost:8888/?token=f027e20b23dd04d34ec827c6ff8ee402ccdf4c775d440766` that you should open with your browser.
+
+If you want to specify another port for Jupyter, the steps above change as follows:
+
+1. When installing nrp you need to add :code:`-np/--notebook_port <port_number>` to install command. For example, the command of :code:`./nrp_installer.sh -np 9875 install latest` will install nrp with port 9875 to be exposed for Jupyter.
+
+2. Run :code:`./nrp_installer.sh connect_backend` which opens a terminal inside backend container.
+
+3. Run the command of :code:`cle-virtual-coach jupyter notebook "--ip=0.0.0.0" --port=9875` inside backend container to start Jupyter on port specified in step 1. This command yields a URL that allow you to access the Jupyter notebook run on the container.
+
+To **test** that the installation was successful, create a new notebook and run this line of code:
+
+.. code-block:: python
+
+    from pynrp import virtual_coach
+
+if you get no error running this cell, your Jupyter notebook is ready.
+
+
 Launching a Simulation
 ^^^^^^^^^^^^^^^^^^^^^^
 The first thing we need to do is to import the Virtual Coach and create a VirtualCoach instance connected to an NRP server.
diff --git a/hbp_nrp_virtual_coach/pynrp/virtual_coach.py b/hbp_nrp_virtual_coach/pynrp/virtual_coach.py
index afb04d2..896a101 100644
--- a/hbp_nrp_virtual_coach/pynrp/virtual_coach.py
+++ b/hbp_nrp_virtual_coach/pynrp/virtual_coach.py
@@ -182,7 +182,7 @@ class VirtualCoach(object):
         # the user is forwarded to the approve page if not approved yet
         if 'access_token' not in urlparse.urlparse(res.geturl()).fragment.lower():
             raise Exception('Login to NRP online and give your consent. Then return to VC.')
-        
+
         url_with_fragment = res.geturl()
 
         # parse and return token
@@ -276,7 +276,7 @@ class VirtualCoach(object):
         sim = Simulation(self.__http_client, self.__config, self)
         for server_i in servers:
             try:
-                if sim.launch(experiment_id, str(experiment_conf), str(server_i), reservation, 
+                if sim.launch(experiment_id, str(experiment_conf), str(server_i), reservation,
                         cloned, self.__storage_token, brain_processes, profiler, recordingPath):
                     return sim
 
-- 
GitLab