Edit this page on our live server and create a PR by running command !create-pr in the console panel

More on magic %use

  • Difficulty level: easy
  • Time need to lean: 10 minutes or less
  • Key points:
    • Magic %use NAME --language can start a separate kernel with NAME
    • Magic %use NAME --language LAN --kernel KER can bind a language module to an unsupported kernel
    • Option --color can be used to customize colored prompt of subkernels

More on subkernels

A subkernel will be started with the execution of a cell with the selected language. By default

  • The name of the subkernel is the name of the language
  • The Jupyter kernel for the language. If multiple kernels that support the same language are available, preference will be given to a kernel determined by SoS.
  • The SoS language module for the selected language.
  • A default color determined by SoS.

For example, the following cell starts subkernel Python3, with language Python3, kernel ipython, language module sos-python, and a default color determined by SoS.

In [1]:
This is a subkernel for Python 3

Start multiple sessions of the same kernel

Using the %use magic, you can start another session of the same language by specifying a separate subkernel with language name specified with option --language. A separate color is usually specified to differentiate two subkernels:

In [2]:

As you can see, the two Python3 kernels do not share variables:

In [3]:
Out[3]:
'hello, I am P3'
In [4]:
Out[4]:
'hello, I am Python3'

And you can transfer variables from one kernel to another as usual:

In [5]:
Out[5]:
'hello, I am Python3'

Binding a language module to an unsupported kernel

Each language module supports one or more kerneles (e.g. kernel javascript, and nodejs for JavaScript) for one or more langauges (e.g. both MATLAB and Octave are supported by the sos-matlab langauge module). If there is a kernel that uses one of the supported languages but is not explicitly supported by SoS, you can use the --kernel option in combination with the --language option to link the kernel with the specific language module.

For example, if you have developed yet another kernel for javascript, you can link it with the sos-javascript language module with command

%use myjs --kernel myjs --language JavaScript