Skip to content

Kernel Discovery (architecture)

Don Jayamanne edited this page Jan 21, 2022 · 5 revisions

Pre-requisites

Notebook Controller

Mermaid Diagrams
flowchart TB
    A[NotebookController] --> B & C;
    B["ILocalKernelFinder.listKernels()"];
    C{Remote jupyter\n connection setup?} --> G
    G["IRemoteKernelFinder.listKernels()"];
Loading
flowchart TB
    A["ILocalKernelFinder.listKernels()"] --> C;
    subgraph Local Kernels
    C["localKernelFinder.listKernels()"] --> E & F;
    E["LocalKnownPathKernelSpecFinder.listKernels() \n (list global non-python kernelspecs)"];
    F["LocalPythonAndRelatedNonPythonKernelSpecFinder.listKernels() \n (list kernelspecs inside Python environments & list Python interpreters as kernelspecs)"] --> G & H;
    G["LocalKnownPathKernelSpecFinder.listKernels() \n (list python kernelspecs)"];
    H["IInterpreterService \n Use this to fetch list of all interpreters, their details (such as paths to look for kernelspecs)"];
    end
Loading
flowchart TB
    A[NotebookController] --> B;
    subgraph Remote Kernels
    B["IRemoteKernelFinder.listKernels()"] --> C;
    C["remoteKernelFinder.listKernels()"] --> E & F & G & H;
    E["IJupyterSessionManagerFactory.create() \n (Create Jupyter Session for @jupyterlabs/services)"];
    F["IJupyterSessionManager.getKernelSpecs()"];
    G["IJupyterSessionManager.getRunningKernels()"];
    H["IJupyterSessionManager.getRunningSessions() \n (To get information about running kernels)"];
    end
Loading

Local Kernel discovery:

  • Local kernels are fetch in localKernelFinder.ts
  • The above class fetches kernels using the two classes
  1. LocalKnownPathKernelSpecFinder This is responsible for discovering non-python kernel specs in known paths on disc.
  2. LocalPythonAndRelatedNonPythonKernelSpecFinder This is responsible for discovering kernel specs in the python environments and returning kernel specs that can be used to start Python Environments as kernels. (again, please read pre-requisite section above) This uses LocalKnownPathKernelSpecFinder to fetch Python Kernel specs on disc. This uses IInterpreterService to get a list of all interpreters and find kernelspecs within the interpreter directory. Duplicate kernelspecs are removed here (e.g. if user installed Jupyter, then a kernelspec is registered, but we can just ignore most of them and just list a hand-crafted kernelspec for the Interpreter instead).

Local Kernel discovery

Remote Kernel discovery:

  • Local kernels are fetch in remoteKernelFinder.ts
  • Create a IJupyterSessionManager using IJupyterSessionManagerFactory.create (for the remote connection currently configured).
  • Get a list of kernel specs using IJupyterSessionManager.getKernelSpecs()
  • Get a list of running kernels from IJupyterSessionManager.getRunningKernels()
  • Get more information about the running kernels from IJupyterSessionManager.getRunningSessions()

Remote Kernel discovery

Clone this wiki locally