Skip to main content

Metakernel for Jupyter

Project description

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).

https://badge.fury.io/py/metakernel.png/ https://coveralls.io/repos/Calysto/metakernel/badge.png?branch=master https://travis-ci.org/Calysto/metakernel.svg https://anaconda.org/conda-forge/metakernel/badges/version.svg https://anaconda.org/conda-forge/metakernel/badges/downloads.svg

See Jupyter’s docs on wrapper kernels.

Additional magics can be installed within the new kernel package under a magics subpackage.

Features

  • Basic set of line and cell magics for all kernels.
    • Python magic for accessing python interpreter.

    • Run kernels in parallel.

    • Shell magics.

    • Classroom management magics.

  • Tab completion for magics and file paths.

  • Help for magics using ? or Shift+Tab.

  • Plot magic for setting default plot behavior.

Kernels based on Metakernel

… and many others.

Installation

You can install Metakernel through pip:

Installing metakernel from the conda-forge channel can be achieved by adding conda-forge to your channels with:

Once the conda-forge channel has been enabled, metakernel can be installed with:

It is possible to list all of the versions of metakernel available on your platform with:

Use MetaKernel Magics in IPython

Although MetaKernel is a system for building new kernels, you can use a subset of the magics in the IPython kernel.

from metakernel import register_ipython_magics
register_ipython_magics()

Put the following in your (or a system-wide) ipython_config.py file:

# /etc/ipython/ipython_config.py
c = get_config()
startup = [
   'from metakernel import register_ipython_magics',
   'register_ipython_magics()',
]
c.InteractiveShellApp.exec_lines = startup

Use MetaKernel Languages in Parallel

To use a MetaKernel language in parallel, do the following:

  1. Make sure that the Python module ipyparallel is installed. In the shell, type:

pip install ipyparallel
  1. To enable the extension in the notebook, in the shell, type:

ipcluster nbextension enable
  1. 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
  1. 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
  1. 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:

%%px --set_variable results
(* cluster_rank cluster_rank)

Then, in the next cell, you can access results.

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')

Documentation

Example notebooks can be viewed here.

Documentation is available online. Magics have interactive help (and online).

For version information, see the Revision History.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metakernel-0.27.2.tar.gz (186.3 kB view details)

Uploaded Source

Built Distribution

metakernel-0.27.2-py2.py3-none-any.whl (208.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file metakernel-0.27.2.tar.gz.

File metadata

  • Download URL: metakernel-0.27.2.tar.gz
  • Upload date:
  • Size: 186.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for metakernel-0.27.2.tar.gz
Algorithm Hash digest
SHA256 06ca392bdb285b8bb5a5e2e35a6d10beb05aa10147e059e26380ef228085a675
MD5 e028f80b546b0f21d90eb200ec122249
BLAKE2b-256 d2ea705418881a0c8fde0e5331a7da86529a2eadc0f379b3ddef32d1da3ab614

See more details on using hashes here.

File details

Details for the file metakernel-0.27.2-py2.py3-none-any.whl.

File metadata

  • Download URL: metakernel-0.27.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 208.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for metakernel-0.27.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9d591f17703704a1cc757d0408a0d78b95b1ccb628f90e363d6c59e0289c31c2
MD5 7e9a38160dee872f2dcb9b7ceec38fc5
BLAKE2b-256 7a5b46537e57e5a83121d3e8ceca0fd165c4bbda0529cfe6c22ab585de47d497

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page