1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Teaching a Programming Language for Physics PhD students

  1. Jul 28, 2015 #1
    Hello everyone,

    Head of our Physics department has asked me to teach a programming course for a few of their PhD candidates (mostly theoretical) who unfortunately are very bad in programming. He has shortage in his department and he wants someone from CS to do the job.

    I looked around and it seems C/C++, Fortran and Python are used more in Physics research. I don't know Fortran so I have to choose either C/C++ or Python.

    1- Python is a nice language with some suitable libraries such as numpy etc. and you can draw graphs and diagrams much easier than C/C++. Furthermore it is possible to link it to C/C++ libraries if needed. It is even possible to use clusters, GPGPU and multi-thread facilities with mature libraries (with relative ease). In addition, the written code can be run on either Windows or Linux with almost no change.

    I have these books in mind:
    * A Primer on Scientific, Programming with Python
    * Python for Scientists
    * High Performance Python

    2- C++/C is fast but I worry that lack of easy to use libraries (incompatibilities, difficulty of selecting and using the libraries etc.) becomes another problem for these students. There is also the difficulty of allocating very big arrays and working with pointers etc which need deep understanding and excellent debugging capabilities. The advantage is that it will be fast even with their large (sometimes super large) arrays.

    3- The dean suggested that even Matlab might be Ok but having talked to his students, Matlab has proven too slow for them and they have problem with memory consumption of Matlab (some arrays would not fit while I could fit them easily on even a Laptop with C language).

    I'll appreciate if those with postgraduate teaching experience or the PhD candidates could comment.

    Last edited: Jul 28, 2015
  2. jcsd
  3. Jul 28, 2015 #2


    User Avatar
    Science Advisor
    Education Advisor

    Tough one. I'm a PhD candidate in physics who uses all of the languages you mentioned regularly (+ some more), and I can't really see Python or C++/C being used interchangeably -- there are situations where you really want to use C/C++, and situations where you really want to use Python.

    How much time do you have?

    For total novices, I'd pick python due to it's ease of use, but if they have some ability to program, C/C++ is probably better for being applicable to people doing HPC stuff. However, what's the point of this course - is it to teach them to be better programmers in general (in which case, the language doesn't matter so much, but the techniques), or to be really good at language X?

    Python does have the added issue of being rather unique in terms of how lazy it lets you be. If you picked it, you'd be better off avoiding the more "pythonesque" syntax.

    One of our internal CS guys gave our entire department a (~4 hr) primer on C/C++ once, and that was hugely useful - but it was pitched at "here, you all can program reasonably well in some other language, here are the quirks unique to C/C++ you need to know".

    ETA: I wouldn't even consider Matlab to be honest.
  4. Jul 28, 2015 #3
    I think you should start out with defining your goals: What do you think is a good set of skills that the students should have and can realisticaly have after a single course? Without knowing the detailed background and on a brainstorming level my goals would be to give the students a basic technology stack which allows them to
    - know how to create a computer program and let it run
    - perform calculations that for whatever reason they cannot do on paper, like forward-integrating differential equations and numerically solving equations
    - store the calculation results in a format they can read-in again
    - have means for quick generation of overview plots and to create publication-grade plots of the results
    - have a working technique for dealing with problems/errors (be it proper debug outputs or a debugger or something else)

    Generally, I would assume the idea is to give these people a head-start. Not to give them thorought training in all details. Once people can start working sensibly, they can figure out details for themselves. Physics PhDs often consider themselves to be very good at this, after all.

    Performance and curent trends in computer science should be secondary, I think. Performance in physics applications often comes from a suitable approach to the problem or the algorithm. Things like GPU-programming is probaby more for the people who don't need an introduction to programming by the time they enter grad school. Knowing how to operate the university's or department's computing cluster may be helpful for some.
  5. Jul 28, 2015 #4
    e.bar.goum and Timo,

    Thank you very much. Your comments were very useful. I have 3 hours per week for a whole semester (a 3 units optional course) so I guess I should go deep in order to fill the semester. Or perhaps I can first cover C++ and then some Python to cover their plotting and more general needs.

    The high level objective is to enable them to handle their programming needs. I hear that they cannot even convert the suggested algorithms into working programs and some of them have tasks that need more than simple programming skills (e.g. need to manipulate very huge arrays sometimes bigger than the available RAM, doing calculations with very high precisions exceeding those of normal variables, performing very long calculations that take weeks to complete etc). I also want them to prepare plots and graphs of their results.

    I am planning to have a very exercise intensive course pushing them to write actual programs.

    Thank you again for your comments.
  6. Jul 28, 2015 #5


    User Avatar
    Science Advisor
    Education Advisor

    That's enough to do both. I'd actually do python first, briefly, so that they can learn the basics, then go onto c/c++. If they're in grad school, they should be able to figure out easy stuff like plotting in Python pretty much on their own. I think you should focus on bigger picture stuff - those algorithms, manipulating arrays, etc.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook