Book Image

Mastering IPython 4.0

By : Thomas Bitterman, Dipanjan Deb
Book Image

Mastering IPython 4.0

By: Thomas Bitterman, Dipanjan Deb

Overview of this book

IPython is an interactive computational environment in which you can combine code execution, rich text, mathematics, plots, and rich media. This book will get IPython developers up to date with the latest advancements in IPython and dive deep into interactive computing with IPython. This an advanced guide on interactive and parallel computing with IPython will explore advanced visualizations and high-performance computing with IPython in detail. You will quickly brush up your knowledge of IPython kernels and wrapper kernels, then we'?ll move to advanced concepts such as testing, Sphinx, JS events, interactive work, and the ZMQ cluster. The book will cover topics such as IPython Console Lexer, advanced configuration, and third-party tools. By the end of this book, you will be able to use IPython for interactive and parallel computing in a high-performance computing environment.
Table of Contents (18 chapters)
Mastering IPython 4.0
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
6
Works Well with Others – IPython and Third-Party Tools
Index

Preface

Welcome to the world of IPython 4.0, which is used in high performance and parallel environments. Python itself has been gaining traction in these areas, and IPython builds on these strengths.

High-performance computing (HPC) has a number of characteristics that make it different from the majority of other computing fields. We will start with a brief overview of what makes HPC different and how IPython can be a game-changing technology.

We will then start on the IPython command line. Now that Jupyter has split from the IPython project, this is the primary means by which the developer will interface with the language. This is an important enough topic to devote two chapters to. In the first, we will concentrate on basic commands and gaining an understanding of how IPython carries them out. The second chapter will cover more advanced commands, leaving the reader with a solid grounding in what the command line has to offer.

After that, we will address some particulars of parallel programming. IPython parallel is a package that contains a great deal of functionality required for parallel computing in IPython. It supports a flexible set of parallel programming models and is critical if you want to harness the power of massively parallel architectures.

Programs running in parallel but on separate processors often need to exchange information despite having separate address spaces. They do so by sending messages. We will cover two messaging systems, ZeroMQ and MPI, and in relation to both how they are used in already existing programs and how they interact with IPython.

We will then take a deeper look at libraries that can enhance your productivity, whether included in IPython itself or provided by third-parties. There are far too many tools to cover in this book, and more are being written all the time, but a few will be particularly applicable to parallel and HPC projects.

An important feature of IPython is its support for visualization of datasets and results. We will cover some of IPython's extensive capabilities, whether built-in to the language or through external tools.

Rounding off the book will be material on testing and documentation. These oft-neglected topics separate truly professional code from also-rans, and we will look at IPython's support for these phases of development. Finally, we will discuss where the field is going. Part of the fun of programming is that everything changes every other year (if not sooner), and we will speculate on what the future might hold.

What this book covers

Chapter 1, Using IPython for HPC, discusses the distinctive features of parallel and HPC computing and how IPython fits in (and how it does not).

Chapter 2, Advanced Shell Topics, introduces the basics of working with the command line including debugging, shell commands, and embedding, and describes the architecture that underlies it.

Chapter 3, Stepping Up to IPython for Parallel Computing, explores the features of IPython that relate directly to parallel computing. Different parallel architectures will be introduced and IPython's support for them will be described.

Chapter 4, Messaging with ZeroMQ and MPI, covers these messaging systems and how they can be used with IPython and parallel architectures.

Chapter 5, Opening the Toolkit – The IPython API, introduces some of the more useful libraries included with IPython, including performance profiling, AsyncResult, and View.

Chapter 6, Works Well with Others – IPython and Third-Party Tools, describes tools created by third-parties, including R, Octave, and Hy. The appropriate magics are introduced, passing data between the languages is demonstrated, and sample programs are examined.

Chapter 7, Seeing Is Believing – Visualization, provides an overview of various tools that can be used to produce visual representations of data and results. Matplotlib, bokeh, R, and Python-nvd3 are covered.

Chapter 8, But It Worked in the Demo! – Testing, covers issues related to unit testing programs and the tools IPython provides to support this process. Frameworks discussed include unittest, pytest, and nose2.

Chapter 9, Documentation, discusses the different audience for documentation and their requirements. The use of docstrings with reStructuredText, docutils, and Sphinx is demonstrated in the context of good documentation standards.

Chapter 10, Visiting Jupyter, introduces the Jupyter notebook and describes its use as a laboratory notebook combining data and calculations.

Chapter 11, Into the Future, reflects on the current rapid rate of change and speculates on what the future may hold, both in terms of the recent split between IPython and the Jupyter project and relative to some emerging trends in scientific computing in general.

What you need for this book

This book was written using the IPython 4.0 and 4.0.1 (stable) releases from August 2015 through March 2016; all examples and functions should work in these versions. When third-party libraries are required, the version used will be noted at that time. Given the rate of change of the IPython 4 implementation, the various third-party libraries, and the field in general, it is an unfortunate fact that getting every example in this book to run on every reader's machine is doubtful. Add to that the differences in machine architecture and configuration and the problem only worsens. Despite efforts to write straightforward, portable code, the reader should not be surprised if some work is required to make the odd example work on their system.

Who this book is for

This book is for IPython developers who want to make the most of IPython and perform advanced scientific computing with IPython, utilizing the ease of interactive computing.

It is ideal for users who wish to learn about the interactive and parallel computing properties of IPython 4.0, along with its integration with third-party tools and concepts such as testing and documenting results.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "These methods must be named setUpClass and tearDownClass and must be implemented as class methods."

A block of code is set as follows:

    def setUp(self):
        print("Doing setUp")
        self.vals = np.zeros((10), dtype=np.int32)
        self.randGen = myrand.MyRand( )

Any command-line input or output is written as follows:

pip install pytest

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "At a finer level of detail are the bugs listed under the Issues tag and the new features under the Pulls tag."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Mastering-IPython-4. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MasteringIPython40_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.