Skip to content

Commit 9032ece

Browse files
authored
Merge pull request #87 from hbcarlos/kernel_specs
Parameterized kernel specs proposal
2 parents 16ab384 + 4577882 commit 9032ece

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
title: Jupyter Parameterized Kernel Specs
3+
authors: Carlos Herrero, Anastasiia Sliusar
4+
pr-number: 87
5+
date-started: 2022-02-10
6+
shepherd: Johan Mabille
7+
---
8+
9+
# Jupyter Parameterized Kernel Specs
10+
11+
## Problem
12+
13+
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.
14+
15+
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`.
16+
17+
When more than one parameter is available, the number of possible combinations grows in a combinatorics fashion.
18+
19+
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.
20+
21+
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.
22+
23+
## Proposed Enhancement
24+
25+
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` list and `env` dict (respectively the command-line arguments and environment variables).
26+
27+
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.
28+
29+
These kernel parameters will be not saved into the notebook due to security reason. The app will have `allowed_insecure_kernelspec_params` flag which will detect whether we have to accept all kernel spec files as safe or not.
30+
31+
## Detailed Explanation
32+
33+
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.
34+
35+
```=json
36+
{
37+
"display_name": "C++11",
38+
"argv": [
39+
"/home/user/micromamba/envs/kernel_spec/bin/xcpp",
40+
"-f",
41+
"{connection_file}",
42+
"-std=c++11"
43+
],
44+
env: {
45+
"XEUS_LOGLEVEL": "ERROR"
46+
},
47+
"language": "C++11"
48+
}
49+
```
50+
```=json
51+
{
52+
"display_name": "C++",
53+
"argv": [
54+
"/home/user/micromamba/envs/kernel_spec/bin/xcpp",
55+
"-f",
56+
"{connection_file}",
57+
"-std={cpp_version}"
58+
],
59+
env: {
60+
"XEUS_LOGLEVEL: {xeus_log_level}"
61+
},
62+
"language": "C++",
63+
"metadata": {
64+
"parameters": {
65+
"properties": {
66+
"cpp_version": {
67+
"type": "string",
68+
"default": "C++14",
69+
"enum": ["C++11", "C++14", "C++17"]
70+
},
71+
"xeus_log_level": {
72+
"type": "string",
73+
"default": "ERROR",
74+
"enum": ["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"]
75+
}
76+
}
77+
}
78+
},
79+
}
80+
```
81+
82+
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).
83+
84+
In the following screenshots, you can see a small demo of how we envision the UI changes in JupyterLab.
85+
86+
Jupyterlab Launcher | Select c++ version
87+
:-------------------------:|:-------------------------:
88+
![](./launcher.png) | ![](./launcher-select-c-version.png)
89+
90+
91+
![](./notebook-select-kernel.gif)
92+
93+
94+
95+
96+
## Pros and Cons
97+
98+
Pros:
99+
100+
- A less crowded list of kernels specs
101+
102+
Cons:
103+
104+
- Changes are required in multiple components of the stack, from the protocol specification to the front-end.
105+
- Unless we require default values for all parameters, this would be a backward-incompatible change.
106+
107+
## Decisions
108+
109+
- Kernel custom parameters won't be saved into a notebook metadata due to security reasons
110+
- The application can be run with `allowed_insecure_kernelspec_params` parameter which allows a user to see a dialog where they can set up custom kernel parameters
111+
112+
113+
## Checking secure kernelspecs
114+
115+
Upon starting, a kernel client checks whether available kernel spec files are secure:
116+
117+
- if a kernel spec does not have a `metadata.parameters` field, it is considered as secure. The kernel can be started directly.
118+
119+
- if all parameters in a kernel spec `metadata.parameters` have constraining types (i.e. the user cannot enter arbitrary input), the kernel spec is secure. Starting a kernel will show a form where the user can choose the parameters.
120+
121+
If a kernel spec file is not secure and the flag `allowed_insecure_kernelspec_params` is passed when starting the app then a user will be able to fill a form.
122+
123+
If a kernel parameter has a non-constraining type but provides a default value, this latter will be used, and the user won't be able to fill this parameter in the form.
124+
125+
If a kernel parameter has a non-constraining type, and does not provide a default value, then the kernel spec is considered as unsecure. In that case, unless the `allowed_insecure_kernelspec_params` has been passed when starting, the kernelspec is discarded and the user won't be able to start the kernel.
158 KB
Loading
206 KB
Loading
332 KB
Loading

0 commit comments

Comments
 (0)