A Jupyter kernel base class in Python which includes core magic
functions (including help, command and file path completion, parallel
and distributed processing, downloads, and much more).
MetaKernel follows SPEC 0 for minimum supported Python and dependency versions.
To use a MetaKernel language in parallel, do the following:
Make sure that the Python module
ipyparallel is installed. In the
shell, type:
pip install ipyparallel
To enable the extension in the notebook, in the shell, type:
ipcluster nbextension enable
To start up a cluster, with 10 nodes, on a local IP address, in the
shell, type:
ipcluster start --n=10 --ip=192.168.1.108
Initialize the code to use the 10 nodes, inside the notebook from a
host kernel MODULE and CLASSNAME (can be any metakernel kernel):
%parallel MODULE CLASSNAME
For example:
%parallel calysto_scheme CalystoScheme
Run code in parallel, inside the notebook, type:
Execute a single line, in parallel:
%px (+ 1 1)
Or execute the entire cell, in parallel:
%%px
(* cluster_rank cluster_rank)
Results come back in a Python list (Scheme vector), in cluster_rank
order. (This will be a JSON representation in the future).
Therefore, the above would produce the result:
#10(0 1 4 9 16 25 36 49 64 81)
You can get the results back in any of the parallel magics (%px,
%%px, or %pmap) in the host kernel by accessing the variable _
(single underscore), or by using the --set_variable VARIABLE flag,
like so:
Notice that you can use the variable cluster_rank to partition parts
of a problem so that each node is working on something different.
In the examples above, use -e to evaluate the code in the host kernel
as well. Note that cluster_rank is not defined on the host machine,
and that this assumes the host kernel is the same as the parallel
machines.
Configuration
Metakernel subclasses can be configured by the user. The configuration
file name is determined by the app_name property of the subclass. For
example, in the Octave kernel, it is octave_kernel. The user of the
kernel can add an octave_kernel_config.py file to their jupyter
config path. The base MetaKernel class offers plot_settings as a
configurable trait. Subclasses can define other traits that they wish to
make configurable.
As an example:
cat ~/.jupyter/octave_kernel_config.py
# use Qt as the default backend for plots
c.OctaveKernel.plot_settings = dict(backend='qt')