Skip to main content

Introduction

JupyterLab is an integrated environment that can streamline the development of Python code and Machine Learning (ML) models in Kinetica. Jupyter notebooks integrate code execution, debugging, documentation, and visualization in a single document for consumption by multiple audiences. With JupyterLab, Jupyter notebooks can easily operate on a live Kinetica instance. jupyter_main.png The development process is streamlined because sections of code (or cells) can be run iteratively while updating results and graphs. JupyterLab can be accessed from a web browser and supports a Python console with tab completions, tooltips, and visual output. One of the difficulties of using Jupyter notebooks with Kinetica in the past had been that environments needed to be installed with all the necessary dependencies. In this tutorial, the process will be simplified with a Docker image that integrates the components, so they can run locally on any Intel-based machine. The Docker image integrates the following major components:
  • JupyterLab
  • Kinetica 6.2
  • CentOS 7
  • Python 3.6
The Python environment has the necessary modules for:
  • Interaction with Kinetica using ODBC or the native API
  • Creating and executing Kinetica UDF’s
  • Execution of ML Models on Kinetica (e.g. Pandas, PyTorch, TensorFlow)
The Kinetica Intel build does not give GPU-accelerated performance and should be used for development purposes only.

Prerequisites

This tutorial requires the following:
  • Docker
  • Kinetica Developer Edition

Docker

Docker can be downloaded from the Docker store: After installing, select the Advanced preferences and allocate at least 6GB of memory for the VM as shown below. jupyter_advanced.png

Install

All the required code is available in the kinetica-jupyterlab Git repository: You can use git clone to fetch a local copy.

Setting Permissions

The two volumes that will be mounted in Docker, docker/share & notebooks, need to be writable by the image’s gpudb user, which has a uid of 1000. With some operating systems (osxfs), this is managed automatically by Docker. For others, the directories will need to be given permission directly. From the kinetica-jupyterlab directory, run the following:

Entering the License Key

The database is configured to start automatically, but for this to succeed, a license key must be configured. Edit docker/share/conf/gpudb.conf, uncomment the line with license_key, and add the key:
If the key is invalid, the container will fail to start.

Pulling the Image

This section will demonstrate how to use docker-compose to pull the kinetica/kinetica-jupyterlab image from DockerHub. From the kinetica-jupyterlab directory, go into the docker directory and run docker-compose pull.
The docker image command can be used to verify the download.
Sample output:

Managing the Container

This tutorial uses docker-compose to manage the parameters of the container. This can simplify the configuration process, as all of the settings are in the docker-compose.yml file.

Starting

Run the below docker-compose up command to start the image. The combined log output of Kinetica and JupyterLab will be displayed in the console. This console needs to be open for as long as the container is running. From the kinetica-jupyterlab/docker directory:
Sample output:

Using

To use a Unix shell in the container, open up a separate console session and run the following from the kinetica-jupyterlab/docker directory:

Stopping

To stop the container, use the docker-compose down command. From the kinetica-jupyterlab/docker directory:
Sample output:

Exploring the Environment

To access to GAdmin, open URL http://localhost:8080 and log in as an admin user (default username/password is admin/admin ). To access JupyterLab, open URL http://localhost:8888 and enter password kinetica. When logged in, the file browser will appear on the left. jupyter_landingpage.png Navigate to the Examples folder, and open notebook ex_kapi_io.ipynb. This notebook demonstrates basic interactions between Pandas dataframes and Kinetica via the functions in the KIJO module. jupyter_example.png Select Kernel -> Restart Kernel and Run All Cells… to clear the outputs. Then select the first cell and click the Play button to run each cell. Each notebook has a separate Python process or kernel that remembers the variables that were created when cells were executed. Cells can be modified and re-executed without starting from the beginning. A Python console can also be attached to the same kernel as a notebook. Right click on a cell and select New Console For Notebook. Enter one of the variables executed from the notebook (e.g. _test_df) and then press Shift+Enter to see the contents in the console. jupyter_example_console.png
Use Tab for term completions and Shift+Tab for tooltips.

JupyterLab Contents

This repository contains an integrated environment that provides accelerated development of Kinetica-based ML Models. It makes use of CentOS 7, Kinetica, JupyterLab, and Python 3.6 for this purpose. JupyterLab has the following Python 3.6 libraries for integrating ML libraries with Kinetica: It also has the following libraries for ML model development: Example Notebooks are provided that demonstrate:
  • Connectivity between Pandas Dataframes and Kinetica with ODBC and the native API
  • ML models including an SVD recommender
Within the kinetica-jupyterlab directory, there are two directories of note:
  • docker - contains the scripts necessary to build and run the Docker image
  • notebooks - contains notebooks and Python scripts needed to run them; will be mounted inside the image and its contents will be visible in JupyterLab

Mounted Volumes

Example Notebooks

Example notebooks are located in notebooks/Examples, which document and demonstrate interaction of JupyterLab with Kinetica.

SVD Recommender and Visualization Example

The following set of notebooks contain an example of how to use SVD with Kinetica to build a recommender engine. The notebooks generate result tables and must be executed in-order.

KJIO Utility Library

A set of utility functions collectively called Kinetica Jupyter I/O are located in notebooks/KJIO to simplify the task of interacting with Kinetica from notebooks. The example notebooks demonstrate their functionality.

Conclusion

The JupyterLab environment integrates many components. With it, external datasources can be ingested, the data analyzed with some of the most powerful ML libraries, the results saved to Kinetica, the data further processed with UDFs, and each step visualized, all in a single notebook. Use cases can have documentation and equations added to aid in telling a data-driven story to multiple audiences.

References

Additional online resources are available here: