16–19 Mar 2026
CERN
Europe/Zurich timezone
There is a live webcast for this event.

Speed Without The Pain: Accelerating Python With Numba (Lecture 2)

17 Mar 2026, 10:00
1h
31/3-004 - IT Amphitheatre (CERN)

31/3-004 - IT Amphitheatre

CERN

105
Show room on map

Speaker

Kiran Jonathan

Description

Relevance to iCSC Attendees:

In scientific computing, we often find ourselves at a crossroads when starting a new project: do you reach for a fast, compiled language and sacrifice some development time and readability for performance, or do you reach for good old easy-to-write Python, and prepare to make a few coffees while your simulation or analysis runs? Libraries like Numpy and Scipy do a great job of bridging this divide by providing highly performant compiled backends with simple-to-use Pythonic interfaces. But what do you do when your specific workflow doesn’t conform neatly to one of their vectorised functions? When we find ourselves waiting on slow, Python-only for loops, is it time to brush off our C++ skills?

This is where Numba comes in! With a few simple-to-understand decorators, not only can you just-in-time compile your plain Python code to achieve near-compiled performance, but you can also easily implement parallelism into your code – in fact, so easily that it might feel a little suspicious! The best part is that it’s able to do all of this without compromising the very things that make Python such an inviting choice in the first place: high readability, fast development, and flexibility.

In these sessions, participants will learn about the difference between compiled and interpreted languages and where that stereotypical Python slowness comes from. We’ll go over common use cases to show when you should use something like Numpy, and when you might want Numba instead, whilst giving a practical and hands-on overview of how you can start writing Numba code to speed up your serial (and soon-to-be-parallel) Python code!

By the end, participants will no longer be at a crossroads: they'll be able to achieve speed without the pain!

Session Details:

Python is ubiquitous in scientific computing due to its ease-of-use and its wide support for valuable data analysis, machine learning, and numerical libraries. However, as an interpreted language, plain Python often falls short when it comes to performance, especially in cases where you can’t leverage highly optimised libraries such as Numpy. These sessions aim to give attendees an overview of where these differences in performance come from, what solutions are available, and in particular give practical information on how to apply Numba to speed up their code.

Numba has been chosen due to its high performance yield for its relatively small increase in code complexity, relying mostly on decorators and very small syntax changes for parallelising for loops – this is especially useful when trying to optimise Python code which has already been written, post hoc. It is also highly portable, and is simply installed as a pip module and used alongside the normal Python interpreter, making it very accessible to install and run.

The lectures would cover:
- The difference between compiled and interpreted languages
- How slow pure Python really is, and why it’s so slow
- What options are available for speeding up Python code (Numpy, interpreters, JIT, etc..)
- When these different options are suitable (in particular, why libraries like Numpy should typically be your first choice due to their high levels of optimisation for the problems they address)
- When JIT compilation may be the most appropriate solution
- How to make use of the Numba library for optimising Python code with JIT compilation:
- What Numba is capable of, and what it is isn’t capable of
- How to use Numba decorators to flag functions for JIT compilation
- How to use Numba parallel ranges for easy implementation of parallelism in for loops
- (Optionally) How Numba can be used to write CUDA kernels in plain Python

The exercises would cover:
- Timing and benchmarking code in Python
- Optimising some common vector operations with Numpy
- Optimising an algorithm which does not port well to Numpy using Numba JIT compilation
- Parallelising this algorithm using Numba "prange" (CPU-only, threaded computation)

Comments

If possible, I'd definitely like to travel to CERN and deliver the lectures and exercises in person.

Number of lecture hours 2
Number of exercise hours 1
Attended school CSC 2025 (Lund)

Author

Presentation materials