Change the future

Wednesday 9 a.m.–12:20 p.m.

IPython in-depth: high-productivity interactive and parallel python

Fernando Perez, Brian Granger, Min RK

Audience level:
Intermediate
Category:
Useful Libraries

Description

IPython provides tools for interactive and parallel computing that are widely used in scientific computing, but can benefit any Python developer.

We will show how to use IPython in different ways, as: an interactive shell, an embedded shell, a graphical console, a network-aware VM in GUIs, a web-based notebook with code, graphics and rich HTML, and a high-level framework for parallel computing.

All materials for this tutorial can be found on our github repository

Abstract

IPython started in 2001 simply as a better interactive Python shell. Over the last decade it has grown into a powerful set of interlocking tools that maximize developer productivity in Python while working interactively.

Today, IPython consists of a kernel that executes the user code and provides many features for introspection and namespace manipulation, and tools to control this kernel either in-process or out-of-process thanks to a well-specified communications protocol implemented over ZeroMQ. This architecture allows the core features to be accessed via a variety of clients, each providing unique functionality tuned to a specific use case:

  1. An interactive, terminal-based shell with capabilities beyond the default Python interactive interpreter (this is the classic application opened by the ipython command that most users are familiar with).

  2. A Qt console that provides the look and feel of a terminal, but adds support for inline figures, graphical calltips, a persistent session that can survive crashes of the kernel process, and more. A user-based review of some of these features can be found here.

  3. A web-based notebook that can execute code and also contain rich text and figures, mathematical equations and arbitrary HTML. This notebook presents a document-like view with cells where code is executed but that can be edited in-place, reordered, mixed with explanatory text and figures, etc. The notebook provides an interactive experience that combines live code and results with literate documentation and the rich media that modern browsers can display:

Notebook screenshot

  1. A high-performance, low-latency system for parallel computing that supports the control of a cluster of IPython engines communicating over ZeroMQ, with optimizations that minimize unnecessary copying of large objects (especially numpy arrays). These engines can be controlled interactively while developing and doing exploratory work, or can run in batch mode either on a local machine or in a large cluster/supercomputing environment via a batch scheduler.

In this hands-on, in-depth tutorial, we will briefly describe IPython's architecture and will then show how to use the above tools for a highly productive workflow in Python.

An outline of the tutorial follows:

Core IPython: interactive use at the terminal and Qt console - IPython basics: the magic command system, shell aliases, full shell access, the history system, variable caching, object introspection tools. - Development workflow: combining the interpreter session with python files via the %run command. - Effective use of IPython at the command-line for typical development tasks: timing, profiling, debugging.

The IPython Notebook - Interactive usage of the notebook - The IPython display protocol: defining custom display methods for your own objects (HTML, Images, JavaScript). - Constructing interactive elements in Javascript that call back to Python. - Converting notebooks to other formats for sharing, blogging and publication.

Parallelism with IPython - basic architecture: the concept of an "interactive IPython cluster" - direct execution of code across engines in a cluster - dynamic load-balancing of tasks - IPython engines in the cloud (illustrated with Amazon EC2 instances).

At the end of this tutorial, attendees will have an understanding of the overall design of IPython not only as a (better) python shell, but as a suite of applications they can use and combine in multiple ways in the course of their development work with Python. They will learn:

  • Tricks from the IPython machinery that are useful in everyday development,
  • what the new high-level applications in IPython --the graphical Qt console and web-based notebook-- can do and how they can be used.
  • how the concepts IPython is based on form a natural foundation for high-level parallel computing with low latency and high throughput.
  • How the overall picture of IPython fits together, so that they can better use its components for the problem at hand.

For full details about IPython including documentation, previous presentations and videos of talks, please see the project website.

Update: See updated tutorial preparation instructions at IPython in-depth: high-productivity interactive and parallel python