Intro to Python for graduate students

Course aims:

Python moving tonge Intro to python for graduate students is a week-long course designed to introduce the casual Python user to the capabilities of the language in the context of scientific computing at the graduate level.

It aims to prepare students to use Python as a general-purpose programming language in research, to be used both in theoretical and experimental contexts. Tasks like data taking/handling/analysis, generating publication-quality plots, solving differential equations,... will be covered, following the standards in the scientific community.

It consists of self-contained topics that focus on different tasks: Input/Output, plotting, data analysis and scientific computation. They can be coursed separately if required, according to the needs of each particular student. The course is delivered as a series of worked examples that can be used online or as part of the graduate course in Atomic and Molecular Physics. An experienced user will guide the students through the sections and the examples in morning/afternoon long tutorials, to help the students in understanding the tasks at hand, and support them in the usage of Python.

Learning outcomes:

By the end of the course, the student should be able to

  • know how to install and use the Python environment in their preferred OS
  • know where to get information about the programming language, and how to navigate on- and offline manuals
  • identify and produce programs following standards for commenting and style.
  • perform simple tasks using Python to help them in their daily scientific routines.
  • use python to generate publication quality plots, with multiple plots and insets.
  • use python's numerical packages numpy and scipy to perform numerical calculations (linear algebra, differential equations, ...).
  • recognize possibilities for simple optimization in their scripts and ways to implement them.
  • get information about the more advanced packages written for python to solve quantum mechanical problems (parallelization, QuTIP,...).

Homework tasks

The course is broadly divided into 4 different topics (plus an introductory section): Input/Output (I/O), plotting, data analysis, and scientific computing. Each of this topics comes with a "quest", which is a single, large task that brings together most of the key concepts covered in each topic. There are smaller, optional, exercises along the way which focus on individual elements of each topic.

For example, in the section Plotting there are exercises to work on simple plots that focus on the different "turning knobs", like the axes, layout, etc., to understand how plotting works in general; and, in the end, the quest involves reproducing a complex plot.

Here is a list of the quests:

The deadlines for each of the tasks will be set out by the instructor during the day, and will be marked within one week. Model answers will be provided once the exercises have been handed in.

Getting Started

Python comes in bits. Fortunately, someone put the important bits together. Even better, the academic license is free! Oh, and it's completely cross-platform. Get Enthought Canopy here (you'll need to create an account for the academic license):

For making plots with lots of maths in the labels/titles, it's useful to have a LaTeX installation on the computer. Install this first, before enthought! Here are some recommended distributions (they're all free):

We assume that you have a basic working knowledge of Python: what are modules, functions, ... If you have never come across python, you can read some of our basics, and you should read the Introduction to Programming in Python guide at the Python resources page of the Physics Laboratory Guide.

Where to go from here:

The course is designed as sections that should be coursed sequentially, but depending on the abilities of the student, it can be taken as individual parts.

If you are an absolute, complete, beginner, you should read this "What is Python?" guide.

You should familiarize yourself with the basics:

And then, for 4 main sections of the course:

This course is not designed to be a complete python programming guide. We assume you already have some programming experience, however limited and in whichever language that may be. There are many online resources already out there, here are a few links that may come in useful.

Advanced topics:

  • Quantum Toolbox in Python (QuTiP): QuTiP main page
  • and others ... to follow ...


This course has been designed by James Keaveney, David Paredes and Tommy Ogden in close collaboration with the AtMol department in Durham University (UK).

The work is shared with the MIT License.