Ready, Set, Go! Getting Started with Numba

Ready, Set, Go! Getting Started with Numba

Real World Numba - Part I

To get started with numba, we will compute the Mandelbrot Set, a set of points on the complex plane which always remain bounded by a threshold value while solving the quadratic recurrence equation. It is an iterative problem which is also compute intensive and visual in nature. This makes it a good starting point for new numba users to witness the various ways in which one can achieve code speed-up using numba.

This Mandelbrot Set Generator is built using the Tcl/Tk cross-platform UI framework which comes pre-packaged with the python. UI layer (which includes advanced feature such as Zooming) and computational layer are separated for better understanding.

Video Demo

Video Tutorial

Requirements

Install the following dependencies using pip3 command:

$ pip3 install numba Pillow

Tk comes pre-installed with Python and numpy is installed during the numba installation in case it is not available.

Project Repository

To get started with the exercise, simple clone the below project:

Brief description of various parts of the code are provided below:

  • Requisite libraries are imported along with the view_mandelbrot() function from canvas.py (UI Layer) which is responsible for rendering the Mandelbrot Set.
  • The domain size is set as a 600x600 grid and the maximum number of iterations for each point on this grid is limited to 1000 (6000 for parallel codes).
  • mandelbrot() function is used to evaluate the Mandelbrot Set. It returns the RBG color of each point on the grid (complex plane) as a nested list of tuples or a NumPy array.

Each implementation has a dedicated file and the recommended learning sequence that should be followed is provided below:

Screenshot 2021-02-04 at 4.51.39 PM.png

To execute the code just run:

$ python3 filename.py

A Tkinter GUI will pop-up. You can use left mouse button to drag and select an area and zoom into it. Right click to reset the canvas.

Want to learn more about numba ?

Check out articles and talk videos on Real World Python website: