Teaching (Python) programming for self-driving labs

I recently came across the following via a blog post, which is a topic I and many others have thought a lot about. What are some of the best practices involved with teaching Python to scientists who don’t have a background in programming? Especially considering time limitations and a very application-oriented focus.

(Note about the blog post that pointed me here: CodeGrade seems like a nice solution, though I use GitHub Classroom when making coding assignments).

I collected a variety of resources at Hackathon resources | Bayesian Optimization Hackathon for Chemistry and Materials for learning Python (see “Python” section). While I haven’t used these myself (see note at bottom of this post), these are either ones that have been recommended to me by people in the accelerated discovery field or ones I’ve identified that seem to have a nice structure and set of topics.

While designing https://ac-microcourses.readthedocs.io/, I tried to identify the bare minimum of Python topics/background required and made a Python refresher assignment with a GitHub Classroom integration based on this. Feedback I’ve received is that there can be so many new things for AC microcourses where some would feel more comfortable with something focused more exclusively on Python for materials / chemistry informatics and self-driving labs. However, GitHub Classroom and the way I use it gives people experience using the same tools they would as a software developer and learning best practices. I try to give full walkthroughs (usually video walkthrough) for pieces that aren’t directly tied to the learning outcomes of that particular assignment while avoiding being stifling for things that are tied to the learning outcomes.

As an aside, I took a rather unique path of learning Python. As an undergrad in physics, I learned Mathematica as my first language with some very structured and high-quality courses from the school (computational physics classes) and frequently used it in courses for assignments through the end of grad school. As a master’s student in mech eng I used MATLAB extensively. As a Ph.D. in materials science & eng, I taught myself Python via Python kernels within Mathematica on a specific project and passing data back to Mathematica when I got too frustrated, then back to the Python kernel. I almost exclusively used Google / stackoverflow for looking things up.

Really curious to hear others’ thoughts on these topics, both in terms of lessons learned, best practices, gotcha-s to avoid, and specific content/courses/tools that have been effective for you. I know many professors in the field have given this a lot of thought and have personal anecdotes of how things have gone.

2 Likes

A nice perspective by @sergei2:

The New Language of Science: How to Learn Python Effectively

Also came across Introduction to Python for Researchers (Online Course) | Current students | Imperial College London which is listed as a pre-requisite for Overview — Machine Learning for Materials.

Throwing my two cents here as someone learning python instead of teaching.
When i first learned programming, it was through codeacademy and w3schools and having to open hundreds of tabs to find the right snippet of code to copy and paste.
Today when I “write” code with the assistance of LLMs, part of me is appreciative of how much time its saving and part of me hates how much time was wasted in my youth.

Today, I think it’s less important to learn how to “write” code, but understanding and interpreting what an LLM is spitting out is still necessary. I don’t love the term prompt engineering, but the logic which you feed your LLMs is important. It’s still important to teach people how to think like a programmer in order to get good outputs from an LLM

1 Like

Teching Python for experimentalists is always a tough balance between achieving something complex and developing “good code” that can be reused.

I have taught many workshops on Python for the Lab, happy to know your perspective on what are the best areas to focus that can have the largest impact.

1 Like

Agreed about the tradeoff. Any thoughts on the topics in GitHub - AC-Classroom/python-refresher? (Focused primarily on some basic syntax and as a refresher)

Would you be willing to share an outline of one of those workshops?

First I only found the Python Refresher, but then I came across the Robotics course. That seems fantastic! I’ll take a deeper look when I have the time.

This is the code that students develop over 3 days. It revolves around controling an instrument to acquire the IV curve of a diode.

Classes are introduced as a representation of a device, which tends to lower the barrier in the topic (data persistance, interaction between attributes, etc.), as well as multi-threading and user interfaces with PyQt.

When I started I thought it was too ambitious considering the only requirement was that students know “some programming”, meaning they already know what while or for loops are, of what an if-statement means. But most managed to pick it up rather fast and propose creative solutions around.

1 Like