In [14]:
%load_ext load_style
%load_style talk.css
from talktools import website, nbviewer


The load_style extension is already loaded. To reload it, use:
  %reload_ext load_style

The IPython Project

Telling stories with code and data

Scientific computing is about more than just code and data.

It is about telling stories with code and data.

These data driven stories include other types of content:

  • Narrative text
  • Images and video
  • Equations
  • Plots and other visualizations

We go through different phases as we tell these stories:

  • Individual exploration
  • Collaborative development
  • Production execution
  • Debugging
  • Publication
  • Presentation
  • Education

IPython is an interactive computing environment for telling stories with code and data that are interactive, exploratory, social, open and reproducible

  • IPython: open source (BSD) interactive computing environment in Python
  • History:
  • $>$ 20 person years of development, $>$ 150 contributors
  • IPython is the de facto standard environment for interactive work in Python
  • Funded by:
    • Volunteers (mostly)
    • NASA, DOD/DRC, NIH
    • Microsoft, Enthought
    • Alfred P. Sloan Foundation
      • $1.15 million dollar grant for 2013-2014
      • PIs: F. Perez @ UC Berkeley and B. Granger @ Cal Poly

In [16]:
website('http://ipython.org', height=500)


Out[16]:

Core abstractions

  • Kernels run code
    • Stateful computation engine
    • Kernels can run code in any language
    • Capabilities exposed through a langauge agnostic JSON based message protocol
    • ZeroMQ used as a transport layer: high performance, low latency
    • Kernels can run anywhere
  • Frontends provide user interfaces
    • Terminal (the original IPython)
    • QtConsole
    • Notebook
    • Kernel publishes results (text, images, HTML, JSON, JavaScript, LaTeX) back to the frontend
  • Parallel computing
    • Multiple kernels coordinated by schedulers
    • Task = Python function with arguments

The IPython Notebook

A web-based UI for writing and running code

We try to make writing code pleasant:

  • Tab completion
  • Integrated help
  • Syntax highlighting
  • Civilized multiline editing
  • Interactive shorthands (aliases, magics)

In [17]:
%pylab inline


Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

In [18]:
plot(rand(50))


Out[18]:
[<matplotlib.lines.Line2D at 0x108e25c90>]

Languages other than Python

The Notebook supports running code in other languages through two means:

  1. Cell magics
  2. Native Kernels

Cell magics

A cell that begins with %% can contain code in other languages (ruby, julia, R, perl, bash, etc.):


In [21]:
%%bash
echo "Hi there Strata!"


Hi there Strata!

Native kernels

IPython message protocol and Notebook web application are language independent:

  • The IPython Kernel can be replaced by kernels in other languages
  • Initial work has begun on native Ruby, node.js, Julia kernels
  • Plans for native R, MATLAB kernels
  • Native kernels don't require the extra %% syntax

This is not just about Python! While we are passionate about Python, we deeply believe that scientific computing is a multi-language enterprise.

The IPython Notebook

Demo: Importable Python code

The IPython Notebook

An open, JSON based document format


In [22]:
from IPython.nbformat import current
with open('IPython.ipynb') as f:
    nb = current.read(f,'json')

In [23]:
nb.worksheets[0].cells[0:5]


Out[23]:
[{u'cell_type': u'code',
  u'collapsed': False,
  u'input': u'%load_ext load_style\n%load_style talk.css\nfrom talktools import website, nbviewer',
  u'language': u'python',
  u'metadata': {u'slideshow': {u'slide_type': u'slide'}},
  u'outputs': [{u'output_type': u'stream',
    u'stream': u'stdout',
    u'text': u'The load_style extension is already loaded. To reload it, use:\n  %reload_ext load_style\n'},
   {u'html': u'<style>\n\n.rendered_html {\n    font-family: "proxima-nova", helvetica;\n    font-size: 150%;\n    line-height: 1.3;\n}\n\n.rendered_html h1 {\n    margin: 0.25em 0em 0.5em;\n    color: #015C9C;\n    text-align: center;\n    line-height: 1.2; \n    page-break-before: always;\n}\n\n.rendered_html h2 {\n    margin: 1.1em 0em 0.5em;\n    color: #26465D;\n    line-height: 1.2;\n}\n\n.rendered_html h3 {\n    margin: 1.1em 0em 0.5em;\n    color: #002845;\n    line-height: 1.2;\n}\n\n.rendered_html li {\n    line-height: 1.5; \n}\n\n/*.prompt {\n    font-size: 120%; \n}*/\n\n.CodeMirror-lines {\n    font-size: 120%; \n}\n\n/*.output_area {\n    font-size: 120%; \n}*/\n\n#notebook {\n    background-image: url(\'files/images/witewall_3.png\');\n}\n\nh1.bigtitle {\n    margin: 4cm 1cm 4cm 1cm;\n    font-size: 300%;\n}\n\nh3.point {\n    font-size: 200%;\n    text-align: center;\n    margin: 2em 0em 2em 0em;\n    #26465D\n}\n\n.logo {\n    margin: 20px 0 20px 0;\n}\n\na.anchor-link {\n    display: none;\n}\n\nh1.title { \n    font-size: 250%;\n}\n\n</style>',
    u'metadata': {},
    u'output_type': u'display_data',
    u'text': u'<IPython.core.display.HTML at 0x10715e450>'}],
  u'prompt_number': 14},
 {u'cell_type': u'heading',
  u'level': 1,
  u'metadata': {u'slideshow': {u'slide_type': u'slide'}},
  u'source': u'<h1 class="bigtitle">The IPython Project</h1>\n\n<center>\n<img src="files/images/ipython_logo.png" />\n</center>'},
 {u'cell_type': u'heading',
  u'level': 1,
  u'metadata': {u'slideshow': {u'slide_type': u'slide'}},
  u'source': u'Telling stories with code and data'},
 {u'cell_type': u'markdown',
  u'metadata': {u'slideshow': {u'slide_type': u'-'}},
  u'source': u'Scientific computing is about more than just code and data.  \n\nIt is about **telling stories** with code and data.\n\nThese data driven stories include other types of content:\n\n* Narrative text\n* Images and video\n* Equations\n* Plots and other visualizations\n\nWe go through different phases as we tell these stories:\n\n* Individual exploration\n* Collaborative development\n* Production execution\n* Debugging\n* Publication\n* Presentation\n* Education'},
 {u'cell_type': u'markdown',
  u'metadata': {u'slideshow': {u'slide_type': u'fragment'}},
  u'source': u'<h1>IPython is an interactive computing environment for telling stories with code and\ndata that are interactive, exploratory, social, open and reproducible</h1>'}]

Notebook documents

  • Are stored as files in your local directory
  • Can store:
    • Code in any language
    • Text (Markdown)
    • Equations (LaTeX)
    • Images
    • Links to video
    • HTML
  • Can be version controlled
    • Change 1 line of code, get a 1 line diff
  • Can be viewed by anyone online without IPython installed (http://nbviewer.ipython.org/)
  • Can be exported to HTML, Markdown, reStructured Text, LaTeX, PDF
  • Can be viewed as slideshows with live computations

Notebooks make scientific computing social

Any Notebook on GitHub or elsewhere on the internet can be viewed instantly by visiting http://nbviewer.ipython.org.


In [24]:
website('http://nbviewer.ipython.org')


Out[24]:

Users are posting their Notebooks on GitHub and sharing them through nbviewer and Twitter


In [25]:
nbviewer('raw.github.com/agconti/kaggle-titanic/master/Titanic.ipynb')


Out[25]:

An entire book on Bayesian methods has been written using IPython Notebooks

Author: Cameron Davidson-Pilon


In [27]:
website('http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/')


Out[27]:

IPython Notebook gallery

We maintain a gallery of interesting Notebooks that contains a curated list of IPython Notebooks on various topics. Here is one studying chemical reactions:


In [28]:
nbviewer(gist='4316430', width=800)


Out[28]:

An ecosystem of third party tools

IPython provides an open source foundation for an ecosystem of tools and products

The future

  • Notebook conversion (2012)
    • To and from a wide range of formats
    • HTML, LaTeX, PDF, Markdown, reStructured Text
  • Interactive widgets (2012)
    • The IPython kernel already knows how to send JSON representations of objects to the browser
    • We are developing an architecture that will allow interactive JavaScript widgets and Python objects to pass JSON data back and forth.
    • Automatic generation of UI controls for Python objects
  • Multiuser Notebook server (2013)
    • Small to medium groups of users
    • Trusted users - you would give these folks shell accounts

See our development roadmap for details

More information

  • Visit the IPython website
  • IPython is completely open source so you can download it and play with it today
  • The IPython Notebook is a single user web application that you run on your local computer

      $ipython notebook
  • Here are our Quick installation instructions