Jupyter/IPython Kernel Tools
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).
.. image:: https://badge.fury.io/py/metakernel.png/ :target: http://badge.fury.io/py/metakernel
.. image:: https://coveralls.io/repos/Calysto/metakernel/badge.png?branch=master :target: https://coveralls.io/r/Calysto/metakernel
.. image:: https://travis-ci.org/Calysto/metakernel.svg :target: https://travis-ci.org/Calysto/metakernel
.. image:: https://anaconda.org/conda-forge/metakernel/badges/version.svg :target: https://anaconda.org/conda-forge/metakernel
.. image:: https://anaconda.org/conda-forge/metakernel/badges/downloads.svg :target: https://anaconda.org/conda-forge/metakernel
See Jupyter's docs on
wrapper kernels_.
Additional magics can be installed within the new kernel package under a
magicssubpackage.
... and many others.
You can install Metakernel through
pip:
.. code::bash
pip install metakernel --upgrade
Installing
metakernelfrom the
conda-forgechannel can be achieved by adding
conda-forgeto your channels with:
.. code::bash
conda config --add channels conda-forge
Once the
conda-forgechannel has been enabled,
metakernelcan be installed with:
.. code::bash
conda install metakernel
It is possible to list all of the versions of
metakernelavailable on your platform with:
.. code::bash
conda search metakernel --channel conda-forge
Although MetaKernel is a system for building new kernels, you can use a subset of the magics in the IPython kernel.
.. code:: python
from metakernel import registeripythonmagics registeripythonmagics()
Put the following in your (or a system-wide)
ipython_config.pyfile:
.. code:: python
# /etc/ipython/ipythonconfig.py c = getconfig() startup = [ 'from metakernel import registeripythonmagics', 'registeripythonmagics()', ] c.InteractiveShellApp.exec_lines = startup
Use MetaKernel Languages in Parallel
To use a MetaKernel language in parallel, do the following:
ipyparallelis installed. In the shell, type:
.. code:: bash
pip install ipyparallel
.. code:: bash
ipcluster nbextension enable
.. code:: bash
ipcluster start --n=10 --ip=192.168.1.108
MODULEand
CLASSNAME(can be any metakernel kernel):
.. code:: bash
%parallel MODULE CLASSNAME
For example:
.. code:: bash
%parallel calysto_scheme CalystoScheme
Execute a single line, in parallel:
.. code:: bash
%px (+ 1 1)
Or execute the entire cell, in parallel:
.. code:: bash
%%px (* clusterrank clusterrank)
Results come back in a Python list (Scheme vector), in
cluster_rankorder. (This will be a JSON representation in the future).
Therefore, the above would produce the result:
.. code:: bash
#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 VARIABLEflag, like so:
.. code:: bash
%%px --setvariable results (* clusterrank cluster_rank)
Then, in the next cell, you can access
results.
Notice that you can use the variable
cluster_rankto partition parts of a problem so that each node is working on something different.
In the examples above, use
-eto evaluate the code in the host kernel as well. Note that
cluster_rankis not defined on the host machine, and that this assumes the host kernel is the same as the parallel machines.
Metakernelsubclasses can be configured by the user. The configuration file name is determined by the
app_nameproperty of the subclass. For example, in the
Octavekernel, it is
octave_kernel. The user of the kernel can add an
octave_kernel_config.pyfile to their
jupyterconfig path. The base
MetaKernelclass offers
plot_settingsas a configurable trait. Subclasses can define other traits that they wish to make configurable.
As an example:
.. code:: bash
cat ~/.jupyter/octave_kernel_config.py # use Qt as the default backend for plots c.OctaveKernel.plot_settings = dict(backend='qt')
Example notebooks can be viewed here_.
Documentation is available online. Magics have interactive help (and online).
For version information, see the Revision History_.
.. _here: http://nbviewer.ipython.org/github/Calysto/metakernel/tree/master/examples/
.. _help: https://github.com/Calysto/metakernel/blob/master/metakernel/magics/README.md
.. _online: http://Calysto.github.io/metakernel/
.. _History: https://github.com/Calysto/metakernel/blob/master/HISTORY.rst