Skip to content

Commit 6322120

Browse files
committed
Parameterized kernel specs proposal
1 parent 15e8169 commit 6322120

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Jupyter Parameterized Kernel Specs
2+
3+
## Problem
4+
5+
When creating a new kernel, we need to define a different "specs" file for each possible parameter combination used by the executable. For example, the xeus-cling kernel supports three different versions of the `C++` language, `C++11`, `C++14`, and `C++17`, which is specified by the `--std` command-line option.
6+
7+
When installing xeus-cling, we install three almost identical kernel specs. The only difference is the last parameter of the execution command `-std=c++X`.
8+
9+
When more than one parameter is available, the number of possible combinations grows in a combinatorics fashion.
10+
11+
Besides, some kernels would benefit from being configurable when launching them. For example, the connection information to the database could be specified through kernel parameters rather than kernel magics.
12+
13+
Sometimes when installing multiple kernels, the JupyterLab launcher panel is crowded with too many options to create a notebook or console with a specific kernel. The kernels that users see in the launcher are just multiple kernel specs for one kernel. We could avoid having that many kernels displayed, adding parameters to the kernel specs, showing only one option per kernel, and offering a modal dialog with the different options the user can choose from when selecting a specific kernel.
14+
15+
## Proposed Enhancement
16+
17+
The solution we are proposing consists of adding parameters to the kernel specs file in the form of a JSON Schema that would be added to the specs metadata. These parameters are then used to populate the `argv` and `env` lists (respectively the command-line arguments and environment variables).
18+
19+
Upon starting a new kernel instance, a front-end form generated from the JSON schema is prompted to the user to fill the parameter values. Many tools are available to generate such forms, such as react-jsonschema-form.
20+
21+
Some of the chosen parameter values can be saved in e.g. the notebook metadata so that they don't have to be specified every time one opens the notebook.
22+
23+
## Detailed Explanation
24+
25+
As described in previous sections, we propose to parameterize the kernel specs file. In the example shown below, we can see the kernel specs file from the kernel xeus-cling. We suggest changing the last parameter of the execution command `-std=c++11` to have a variable `-std=${cpp_version}` and adding a new object `parameters` to the metadata of the kernel specs.
26+
27+
```=json
28+
{
29+
"display_name": "C++11",
30+
"argv": [
31+
"/home/user/micromamba/envs/kernel_spec/bin/xcpp",
32+
"-f",
33+
"{connection_file}",
34+
"-std=c++11"
35+
],
36+
"language": "C++11"
37+
}
38+
```
39+
```=json
40+
{
41+
"display_name": "C++",
42+
"argv": [
43+
"/home/user/micromamba/envs/kernel_spec/bin/xcpp",
44+
"-f",
45+
"{connection_file}",
46+
"-std=${parameters.cpp_version}"
47+
],
48+
"language": "C++"
49+
"metadata": {
50+
"parameters": {
51+
"cpp_version": {
52+
"type": "string",
53+
"default": 'C++14',
54+
"enum": ['C++11', 'C++14', 'C++17'],
55+
"save": true
56+
}
57+
}
58+
},
59+
}
60+
```
61+
62+
The JSON schema specification is augmented with a new `save` attribute used to specify whether the parameter is to be saved in e.g. the notebook metadata for future runs.
63+
64+
Note: Using the JSON Schema, we can automate how front-end forms are created directly from the parameters allowing kernels' authors to decide which parameters are necessary and how to validate them. (Note that JupyterLab already makes use of react-jsonschema-form in other parts of its UI).
65+
66+
In the following screenshots, you can see a small demo of how we envision the UI changes in JupyterLab.
67+
68+
Jupyterlab Launcher | Select c++ version
69+
:-------------------------:|:-------------------------:
70+
![](./launcher.png) | ![](./launcher-select-c-version.png)
71+
72+
73+
![](./notebook-select-kernel.gif)
74+
75+
76+
77+
78+
## Pros and Cons
79+
80+
Pros:
81+
82+
- A less crowded list of kernels specs
83+
84+
Cons:
85+
86+
- Changes are required in multiple components of the stack, from the protocol specification to the front-end.
87+
- Unless we require default values for all parameters, this would be a backward-incompatible change.
Loading
206 KB
Loading
Loading

0 commit comments

Comments
 (0)