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
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.
Install the following dependencies using
$ pip3 install numba Pillow
Tk comes pre-installed with Python and
numpy is installed during the
numba installation in case it is not available.
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
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:
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
Check out articles and talk videos on Real World Python website: