Teaching a Programming Language for Physics PhD students

In summary, the head of the physics department has asked you to teach a programming course for a few of their PhD candidates who unfortunately are very bad in programming. He has shortage in his department and he wants someone from CS to do the job. You looked around and it seems Python and C++ are used more in physics research. You have these books in mind: A Primer on Scientific, Programming with Python Python for Scientists High Performance 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
  • #1
wmac
20
0
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.

Regards
 
Last edited:
Physics news on Phys.org
  • #2
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 let's 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.
 
  • Like
Likes wmac
  • #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 current 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.
 
  • Like
Likes wmac
  • #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.
 
  • #5
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.
 
  • Like
Likes wmac

1. How important is it for Physics PhD students to learn a programming language?

Learning a programming language is becoming increasingly important for Physics PhD students. It allows them to perform complex data analysis, simulations, and modeling which are all essential skills in modern research. Additionally, many journals and conferences now require researchers to provide their code for reproducibility, making programming skills crucial for publishing and collaboration.

2. Which programming language is best for Physics PhD students to learn?

There is no one "best" programming language for Physics PhD students to learn. However, some commonly used languages in the field include Python, MATLAB, and C++. It ultimately depends on the specific research area and personal preference. It is also beneficial to have basic knowledge of multiple languages as they each have their own strengths and weaknesses.

3. How much time should be dedicated to teaching a programming language to physics PhD students?

The amount of time needed to teach a programming language to physics PhD students will vary depending on the students' prior experience and the complexity of the language. However, it is important to dedicate enough time for students to gain a solid understanding and practice with the language. This could range from a few weeks to a semester-long course.

4. What are some effective ways to teach a programming language to physics PhD students?

One effective way to teach a programming language to physics PhD students is to provide a mix of lectures, hands-on coding exercises, and real-world applications. It is also helpful to tailor the lessons to the specific needs and research interests of the students. Additionally, providing resources such as online tutorials and practice problems can aid in the learning process.

5. How can learning a programming language enhance a Physics PhD student's career?

Having programming skills can greatly enhance a Physics PhD student's career prospects. It can open up opportunities for employment in various industries such as data science, software development, and finance. It also allows for more efficient and effective research in academia and can make students more competitive for postdoctoral positions and faculty positions.

Similar threads

  • STEM Academic Advising
Replies
3
Views
956
  • STEM Academic Advising
Replies
6
Views
856
  • STEM Academic Advising
Replies
4
Views
825
Replies
15
Views
2K
  • STEM Academic Advising
Replies
10
Views
2K
Replies
6
Views
937
  • STEM Academic Advising
Replies
4
Views
2K
  • STEM Academic Advising
2
Replies
63
Views
5K
  • STEM Academic Advising
Replies
9
Views
1K
  • STEM Academic Advising
Replies
2
Views
984
Back
Top