Still Noodling Around With Python?

research software engineering
python
ETH
scientific IT services
Getting started with Python is easy given the abundance of free online material. To discuss how researchers can improve their Python beyond those first steps, RSEED invites you to a Znüni session with Franziska Oschmann from the Scientific IT Services (SIS). Our Znüni with Franziska gives you a sneak preview of the ETH SIS course ‘Fast Python’. The 4-day workshop teaches different techniques and tools to resolve performance issues – on a local machine and a High Performance (HPC) cluster alike.
Author

Minna Heim, Matthias Bannert, Franziska Oschmann

Published

May 20, 2024

Znüni with Franziska Oschmann at ETH KOF Swiss Economic Institute on May 30, 09:45.

Join our Python + Gipfeli session on Thu, May 30

“[…] And Python continued to see gains in its usage across GitHub with a 22.5% year-over-year increase driven, in part, by its utility in data science and machine learning.” – GitHub Octoverse Report on the top programming languages.

Much of Python’s popularity stems from its flexibility and general purpose appeal1, yet the idea of this article is to point at Python’s use in research and to present an opportunity to efficiently improve your skills in a programming language that has become ubiquitous in many fields of research. While our innate curiosity as researchers is definitely enough of a driver to get us started with a trending programming language, getting past the first steps requires more commitment and hence comes with prerequisities and opportunity costs.

In other words, the goal of the RSEED Znüni with Franziska Oschmann is to find out whether a deeper dive into Python is for you. The Fast Python workshop is a great opportunity for researchers to improve effectively. Though you should already be somewhat familiar with Python to get the most out of 4-day workshop, you do not have to be an expert, and definitely not a computer scientist.

What Can I learn and Why Is My Current Python Not Good Enough?

Often it is not easy for novice or intermediate programmers to see why whatever works or good enough for me is not good enough. One example of an important skill when problems get harder or require more throughput, is the ability to benchmark one’s code. Benchmarking is important in order to assess one’s need for computing resources and can facilitate cooperation with software engineering experts.

Consider the simplest possible benchmark using the time Python library.

import time

started = time.time()
print("I sleep now for 1.23 seconds")
time.sleep(1.23)
print("Measured execution time is", time.time() - started)
I sleep now for 1.23 seconds
Measured execution time is 1.2366728782653809

Fast Python will cover the basics of profiling and optimizing in Python, and introduce you to some of the most common tools and techniques. It will also provide some best practices for writing fast and efficient Python code including parallel computing.

Are You Ready for 4 days of Fast Python?

The help you assess not only your readiness, but also what it would take to catch up in case you are not there yet, the team at SIS developed a quick self-assessment2 to help you evaluate your starting point. Can you guess the results from execution of the following Python code snippets? Can you explain the snippets and their results to others?

Tip

Do not be discouraged if you cannot answer all snippets immediately! You can use a computer to execute these snippets step by step and work to understand them. The course won’t start tomorrow and there is plenty of great material to help you catch up.

n = 1 + 3 ** 2 + 1_000 // 3 + 10 % 3
print(isinstance(n, float), n)
Answer
False 344
squares = [1, 4, 9, 16, 25]
squares_new = squares
squares_new[1] = 0
print(squares[::-1])
Answer
[25, 16, 9, 0, 1]
l = []
for i in range(10):
    if i % 3 == 0:
        pass
    elif i % 3 == 1:
        continue
    else:
        i *= 10
    if i == 6:
        break
    l.append(i)
    
print(l)
Results
[0, 20, 3, 50]

Fast Python Workshop

When: 2024, tbd.

Where: ETH, in-person.

The 4-day workshop will be fully refunded to committed participants, i.e., participants who take part in all sessions, who are SIS service subscribers. Typically, groups, chairs or insitutions are subscribed to SIS – so make sure to check with your unit whether they have an SIS suscription.

Footnotes

  1. Why Python keeps growing, explained↩︎

  2. You can find the original, stand-alone version of the workshop self-assessment on the course Gitlab page↩︎