Skip to content

Creating a simple JupyterLab Extension (1. Show status of the kernel, 2. Show kernel execution time in milliseconds).

License

Notifications You must be signed in to change notification settings

sboettch/jupyterlab-statextension

Repository files navigation

JupyterLab Building Extensions: Status Bar Time Widget Mod

Description: The task is to create a simple JupyterLab environment frontend extension (refer to JupyterLab Lab Task.pdf). We want to be able to:

  1. Show status of the kernel
  2. Show kernel execution time in milliseconds

0. SETTING UP (estimated time: 45 minutes)

Before we begin, there are a few tutorial resources:

We want to ensure that JupyterLab is up-to-date and that we can successfully install an extension ("jupyter labextension install @..."). For further documentation, please see Extensions.

The exercise we are going to do isn't very different from the tutorial exercise that's outlined in jupytercon2020-developingextensions. It would be easy to download/unzip that, and work out of the tutorial (and even follow along the slides). So, that's basically what we highly recommend/do here -- at the end, we'll clean the code up to publish/share!


1. STATUS OF THE KERNEL (estimated time: 1 hour)

For this portion, there are a few tidbits we need to ensure to import:

import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
ILabStatus
} from '@jupyterlab/application';

import { INotebookTracker } from '@jupyterlab/notebook';

import { IStatusBar } from '@jupyterlab/statusbar';

import { Widget } from '@lumino/widgets';

The goal of this part is that we want to know the status of the kernel. It should flash to busy (from idle) when the kernel is executing.

Additional helpful reading resources can be found here:


2. KERNEL EXECUTION TIME (estimated time: 1.5 hours)

Now for the interesting bit. Say we have a cell time.sleep(10) in our Notebook. Let's run that. Part #1 will show the status flash to busy from idle. How long do we expect that to be? 10s (10,000 milliseconds). We want to be able to show that kernel execution time (that's our goal anyway). But how to do that?

Basically, the instinct here is to start counting time when the kernel status first "flashes" from idle to busy (start counting, get time). At the point when the kernel resumes the idle state (from busy to idle), we stop time. Now, we could run up the clock in milliseconds up till the final time. But our task says, "You should put the number of milliseconds it took the kernel to execute." Basically, all we need to do is take the difference between the final time and the start time. Remember that we want to ensure clarity (eliminate error from vagueness), so we should check to be able to calculate difftime between datetime objects/formats that are unambiguous.

There is existing discussion on (measuring, accessing) kernel execution time for JupyterLab. Some works are going to be useful for reference/information only, and you can come across older code that isn't maintained or can't just be copied in snippets into our codebase (language, multiple incompatibilities). Refer to:


3. TESTING (estimated time: 50 min)

After building index.ts, open up a new Untitled.ipynb within the JupyterLab environment to test the extension.

Hatchling backend issues might be encountered, and if that's the case--starting here may be helpful:

Total Estimated Time: 245 minutes (4.083 hours)

About

Creating a simple JupyterLab Extension (1. Show status of the kernel, 2. Show kernel execution time in milliseconds).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published