EuroSciPy 2024

LPython: Novel, Fast, Retargetable Python Compiler
2024-08-29 , Room 6

Python is one of the most used languages today, known for its simplicity and versatile ecosystem. For performance applications such as High Performance Computing (HPC) or any other kind of numerical computing the standard CPython implementation is often not fast enough. To address these issues, enter the fascinating world of LPython, a Python compiler designed to give you the best possible performance for numerical, array-oriented code, and can also generate code using multiple backends like LLVM, C, C++, WASM.


In this talk, we will delve into LPython, an open-source, LLVM-based Python compiler that transposes type-annotated Python code into optimized machine code. It offers rapid Ahead-Of-Time (AOT) compilation to binaries, with an option for Just-In-Time (JIT) compilation and smooth interoperability with CPython. We'll also provide benchmarks, including a comparison with Numba for JIT compilation and Clang++ and g++ for AOT compilation.

We will examine the unique qualities LPython has to offer and learn the "why" behind the compiler. Its main focus is speed, and our benchmarks will validate its competitiveness with the current cutting-edge technology.

Here's the talk outline:

  • Introduction (2 mins): A warm welcome and a brief presenter introduction. An overview of the talk and learning expectations for attendees.
  • What is LPython? (2 mins): Explaining the need for yet another Python compiler. How it operates at each stage and introduction to the LCompilers family.
  • Phases of compilation, Intermediate representation (ASR), Optimizations (5 mins): A look at the internals, from Python code to parsers, Abstract Syntax Tree (AST), Abstract Semantic Representation (ASR), and backends (LLVM, C, C++, WASM, etc). This section also gives a short overview of how low- and high-level machine-independent optimizations are performed.
  • Just-In-Time and Ahead-Of-Time compilation (2 mins): Distinguishing between these two types of compilation in LPython; JIT compiles code during runtime while AOT produces binary output.
  • Interoperability with CPython (2 mins): Discuss how LPython enables seamless integration with CPython libraries. Demonstrate the @pythoncall and @lpython decorators, and their practical uses (e.g., Matplotlib for graphs).
  • Online Demo (2 mins): Live demo of code compilation using LPython in a browser. Displaying AST, ASR, C, and WAT (WebAssembly Text Format) output tabs on the website.
  • Speed and Performance benchmarks (4 mins): Presenting benchmarks against Numba, Clang++, g++, and Python itself, demonstrating LPython’s ability to run on Linux, Mac, Windows, and WebAssembly.
  • Accelerated code sample (1 min): Showcasing how to speed up a simple Python method developed for tomography.
  • User-friendly developer experience (2 mins): Displaying compiler diagnostic messages (errors, warnings, etc) and highlighting the user-friendly developer experience.
  • Conclusion and takeaways (2 mins): Recapping the main points covered in the talk. Encouraging attendees to incorporate LPython into their projects and providing practical advice on integration. Upcoming features will also be discussed.
  • Q&A session (5 mins): Responding to questions and engaging in dialogue.

Prerequisites:

Intermediate experience in Python would be helpful. An interest in learning the basics of Python compilers.

Content URLs:

LPython: https://lpython.org/
LPython blog: https://lpython.org/blog/2023/07/lpython-novel-fast-retargetable-python-compiler/
LPython GitHub: https://github.com/lcompilers/lpython/
Slides/GitHub repo: to be added later.

Speaker Info:

Naman Gera currently works as a Research Software Engineer at the UK’s national synchrotron science facility, Diamond Light Source, based in Harwell Science and Innovation Campus, UK. He is presenting this work done with his past employer, GSI Technology, being a part of the compiler team led by Dr. Ondrej Certik.

When AFK, Naman likes being in nature, climbing mountains, and solo travelling to many countries.

Speaker URLs:

GitHub: https://github.com/namannimmo10
LinkedIn: https://www.linkedin.com/in/namannimmo/
Email: namangera15@gmail.com


Abstract as a tweet

LPython: Novel, Fast, Retargetable Python Compiler

Category [High Performance Computing]

Other

Expected audience expertise: Domain

some

Expected audience expertise: Python

some

Project Homepage / Git

https://lpython.org/

I work as a Research Software Engineer at the UK's national synchrotron science facility, Diamond Light Source, where I develop open-source software for science. I have been involved in the development of some open-source libraries (SymPy being one of them) and compilers (LPython, LFortran).
When I'm not staring at a screen, I enjoy visiting national parks, hiking, and being outside in nature. I adore the Alps and the Himalayas, where I feel insignificant amidst the majestic mountains. I also enjoy travelling to many countries.