Difference between revisions of "Jupyter"

From KENET Training
Jump to: navigation, search
Line 75: Line 75:
  
 
=== Basic Cell Operations ===
 
=== Basic Cell Operations ===
<syntaxhighlight lang="python">
 
# Code cell - Press Shift+Enter to run
 
import pandas as pd
 
import matplotlib.pyplot as plt
 
  
# Create sample data
+
Notebooks consist of cells where you can write and execute code. Here is a simple example to get you started:
data = pd.DataFrame({
 
    'x': range(10),
 
    'y': [i**2 for i in range(10)]
 
})
 
  
# Plot
+
<code python>
plt.plot(data['x'], data['y'])
+
# Code cell - Press Shift+Enter to run
plt.title('Sample Plot on KENET HPC')
+
import pandas as pd
plt.show()
+
import matplotlib.pyplot as plt
</syntaxhighlight>
+
 +
# Create sample data
 +
data = pd.DataFrame({
 +
    'x': range(10),
 +
    'y': [i**2 for i in range(10)]
 +
})
 +
 +
# Plot
 +
plt.plot(data['x'], data['y'])
 +
plt.title('Sample Plot on KENET HPC')
 +
plt.show()
 +
</code>
 +
 
 +
There are three main cell types in JupyterLab. '''Code''' cells contain executable code and are the default type. '''Markdown''' cells contain formatted text, equations, and documentation. '''Raw''' cells contain plain text that is not executed or formatted.

Revision as of 08:12, 9 January 2026

JupyterLab (Web) Tutorial - KENET HPC Cluster

Overview

JupyterLab is an interactive web-based environment for notebooks, code, and data, ideal for data science, scientific computing, and machine learning workflows.

Use Cases:

  • Interactive data analysis and visualization
  • Machine learning model development and experimentation
  • Creating reproducible research notebooks
  • Teaching and sharing computational narratives
  • Real-time data exploration with GPU acceleration

Access: Available through the KENET Open OnDemand web portal at https://ondemand.vlab.ac.ke


Prerequisites

Before using JupyterLab, ensure you have:

  • Active KENET HPC cluster account
  • Access to Open OnDemand portal
  • Basic knowledge of Python, R, or Julia
  • Data files stored in /home/username/localscratch

Launching JupyterLab

Step 1: Access Interactive Apps

  1. Log into Open OnDemand: https://ondemand.vlab.ac.ke
  2. Click Interactive Apps in the top navigation menu
  3. Select JupyterLab from the dropdown list
Navigate to Interactive Apps → JupyterLab

Step 2: Configure Job Parameters

Fill in the job submission form with your requirements:

Parameter Description Recommended Value
Partition Queue for job execution normal (CPU) or gpu (GPU tasks)
Walltime Maximum runtime in hours 2 hours for testing, up to 192 for long jobs
CPU Cores Number of processor cores 4-8 cores (adjust based on workload)
Memory RAM allocation 16 GB for data science, 32 GB for large datasets
Working Directory Starting directory /home/username or your project folder
Job configuration form with recommended settings

Template:Tip

Step 3: Submit and Wait

  1. Click Launch button
  2. Wait for job to start (Status: "Queued" → "Running")
  3. Click Connect to JupyterLab button when available (typically 30-60 seconds)
Session card showing "Running" status with Connect button

Quick Start Guide

Creating Your First Notebook

  1. Click File → New → Notebook or click the Python 3 tile in the Launcher
  2. Select kernel: Python 3, R, or Julia (if available)
  3. Start writing code in cells
Creating a new notebook in JupyterLab

Basic Cell Operations

Notebooks consist of cells where you can write and execute code. Here is a simple example to get you started:

# Code cell - Press Shift+Enter to run
import pandas as pd
import matplotlib.pyplot as plt

# Create sample data
data = pd.DataFrame({
    'x': range(10),
    'y': [i**2 for i in range(10)]
})

# Plot
plt.plot(data['x'], data['y'])
plt.title('Sample Plot on KENET HPC')
plt.show()

There are three main cell types in JupyterLab. Code cells contain executable code and are the default type. Markdown cells contain formatted text, equations, and documentation. Raw cells contain plain text that is not executed or formatted.