Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few miscellaneous docs updates #3344

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/NotebookswithJupyter.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Using .NET Interactive with Jupyter
# Using .NET Interactive as a Jupyter kernel

To use the .NET Interactive kernel for your multi-language notebooks in Jupyter Notebook, JupyterLab, and other Jupyter frontends, you first need to register .NET Interactive as a kernel with Jupyter.
To use the .NET Interactive kernel for your multi-language notebooks in Jupyter Notebook, JupyterLab, and other Jupyter frontends, you first need to register .NET Interactive as a kernel with Jupyter.

Make sure you have the following installed:

Expand All @@ -13,7 +13,7 @@ Make sure you have the following installed:
> jupyter kernelspec list
python3 ~\jupyter\kernels\python3
> dotnet --version
7.0.200
8.0.100
```

(The `dotnet` minor version isn't important.)
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ If you're just starting out here, you might want to start with the [FAQ](./FAQ.m
## Technical overview

* [Architecture](kernels-overview.md)
* [Jupyter kernel installation](NotebookswithJupyter.md)
* [Install as Jupyter kernel](NotebookswithJupyter.md)

## .NET Interactive Developer Documentation

Expand All @@ -46,6 +46,7 @@ If you're just starting out here, you might want to start with the [FAQ](./FAQ.m

## Extending .NET Interactive

* [Adding support for new Jupyter subkernels](adding-jupyter-kernels.md)
* [Building your own extension](extending-dotnet-interactive.md)
* [Adding magic commands](extending-dotnet-interactive.md#adding-magic-commands)

17 changes: 9 additions & 8 deletions docs/adding-jupyter-kernels.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Adding Jupyter Kernels
# Adding support for new Jupyter subkernels

.NET interactive kernel already supports connecting to any Jupyter kernel as a sub kernel. The kernel can be selected by specifying the kernel spec in the jupyter connect command as shown below.
.NET Interactive already supports connecting to any Jupyter kernel as a subkernel. The Jupyter kernel can be selected by specifying its kernel spec in the `#!connect jupyter` command as shown below.

```
#!connect jupyter --kernel-name pythonkernel --conda-env base --kernel-spec python3
```

This will enable kernel launch, code execution and code completion if provided by the kernel. However, by default Jupyter messaging protocol does not have support for variable sharing so the connected kernel will not have variable sharing enabled.
This will enable kernel launch, code execution, and code completion if provided by the kernel. However, by default Jupyter messaging protocol does not have support for variable sharing, so the connected kernel will not have variable sharing enabled.

In .NET interactive kernel variable sharing is enabled for IPython and IR kernels by using the `comms` message support in [Jupyter messaging protocol](https://jupyter-client.readthedocs.io/en/stable/messaging.html#custom-messages). As long as a Jupyter kernel supports registering comms target and handling comms messages, variable sharing can be enabled for these kernels.
In .NET Interactive, variable sharing is enabled for the IPython and IR kernels by using the `comms` message support in [Jupyter messaging protocol](https://jupyter-client.readthedocs.io/en/stable/messaging.html#custom-messages). As long as a Jupyter kernel supports registering comms targets and handling comms messages, variable sharing can be enabled for these kernels.

### To enable variable sharing for Jupyter sub-kernel, follow the steps below:
### To enable variable sharing for a Jupyter subkernel, follow these steps:

1. Ensure that the kernel to be added supports handling [`comms`](https://jupyter-client.readthedocs.io/en/stable/messaging.html#custom-messages) messages. If not, variable sharing cannot be enabled.

2. If intended kernel supports `comms` messages, create a language specific script for it under the [LanguageHandlers](https://github.com/dotnet/interactive/tree/main/src/Microsoft.DotNet.Interactive.Jupyter/CommandEvents/LanguageHandlers) folder in the .NET interactive kernel repo.
3. This script is sent to the kernel on kernel launch, and should then create a _comm message handler_ and a _comm target_, that is named `dotnet_coe_handler_comm`.
That is responsible for registering the target and the comm handlers. Take a look at the [python script](https://github.com/dotnet/interactive/blob/main/src/Microsoft.DotNet.Interactive.Jupyter/CommandEvents/LanguageHandlers/python/coe_comm_handler.py) here. The expected schema of messages to be send back in the comm_msg data field is

3. This script is sent to the kernel on kernel launch, and should then create a _comm message handler_ and a _comm target_, that is named `dotnet_coe_handler_comm`. This script is responsible for registering the target and the comm handlers. Take a look at the [python script](https://github.com/dotnet/interactive/blob/main/src/Microsoft.DotNet.Interactive.Jupyter/CommandEvents/LanguageHandlers/python/coe_comm_handler.py) here. The expected schema of messages to be send back in the comm_msg data field is

```json
{
Expand All @@ -38,7 +39,7 @@ In .NET interactive kernel variable sharing is enabled for IPython and IR kernel

`commandOrEvent` is a serialized json string reflecting either the [KernelEventEnvelope](https://github.com/dotnet/interactive/blob/main/src/Microsoft.DotNet.Interactive/Connection/KernelEventEnvelope.cs) or the [KernelCommandEnvelope](https://github.com/dotnet/interactive/blob/main/src/Microsoft.DotNet.Interactive/Connection/KernelCommandEnvelope.cs). The type field is used to indicate whether the message is an event or a command.

On launch, the .NET interactive kernel will run the script on the kernel to set up target and then try to send a `comm_open` message to the kernel to establish a comm connection.
On launch, .NET Interactive will run the script on the kernel to set up target and then try to send a `comm_open` message to the kernel to establish a comm connection.

Variable sharing will only be enabled when the comm channel sends a ACK back with a `kernelReady` message and handles the send/request/request_value messages.

Expand Down
Loading
Loading