Learning Programming for Physics Research in Grad School

  • Thread starter Thread starter creepypasta13
  • Start date Start date
  • Tags Tags
    Physics Programming
Click For Summary
SUMMARY

The discussion emphasizes the importance of programming skills for physics research, particularly in computational physics. Key recommendations include learning MATLAB, C/C++, and Python, as these languages are heavily utilized in various physics domains such as astrophysics and condensed matter. Participants suggest focusing on problem-solving and practical projects rather than solely relying on textbooks. Resources like "Numerical Recipes in C" and online libraries are highlighted as valuable for hands-on learning.

PREREQUISITES
  • Basic understanding of programming concepts and syntax in C++ and MATLAB
  • Familiarity with computational physics principles
  • Knowledge of algorithms and data structures
  • Experience with version control systems (e.g., Git)
NEXT STEPS
  • Learn Python and its scientific libraries, particularly SciPy and Matplotlib
  • Explore advanced C/C++ programming techniques, focusing on memory management
  • Engage with online coding platforms to practice computational physics problems
  • Study the "Numerical Recipes in C" for practical algorithm implementation
USEFUL FOR

Graduate students in physics, computational physicists, and researchers looking to enhance their programming skills for effective simulations and data analysis in their respective fields.

  • #31
Your choice of programming language doesn't matter since you are still relatively new to it. Pick any language and stick with it to the end. The reason I say this is because once you master a language then it is really easy to pick up other languages because it would just be a matter of learning new syntax and unique features. Don't worry about the speed of your first language either, it should not be a critical feature at this point. I would recommend python as it is very easy to use, with vast efficient API's written in C. If your code is slow in that language, then you can use a technique called profiling to find out which parts are slow and you can optimize these parts in C or fortran and interface to other languages with shared libraries (those .dll files on windows and .so files on linux). As long as your language gets the job done use it.

Edit: I noticed the original post asked nothing about which programming language to use, but somehow the discussion digressed that way. I agree with what one poster said about any programming experience is good experience. I would like to add that if you get frustrated with learning the language then by all means take a break. Often the solution comes up when you are more relaxed and if you don't then you have the opportunity to revisit problems with a fresh perspective.
 
Last edited:
Physics news on Phys.org
  • #32
Birkeland said:
In general, just pick a language and work through it. While all languages have their differences, once you learn how to program in one language you can pick up any other language pretty quickly.

So just pick whatever you feel more comfortable with.

Fizex said:
Your choice of programming language doesn't matter since you are still relatively new to it. Pick any language and stick with it to the end. The reason I say this is because once you master a language then it is really easy to pick up other languages because it would just be a matter of learning new syntax and unique features. Don't worry about the speed of your first language either, it should not be a critical feature at this point. I would recommend python as it is very easy to use, with vast efficient API's written in C.

I would say I am most familiar and comfortable with MATLAB at the moment as there's still lots about C++ and Python that I don't know about. I would say I'm already familiar with most of its basic functions so when I've been doing some practice problems these past few days, the thing I'm learning the most about are the syntax to create plots.

twofish-quant said:
Download programs that other people have written and then add something to it. It's really important if you want to programing to be able to read other people's code. You might download something, and then find it *PAINFUL* to read and impossible to change, at which point you know what bad code looks like.

Most of the programs I've found online are either really complex to me (ie involve hundreds or thousands of lines of C++ code) or too simple. But I found this site to be the closest to my level
http://www.algarcia.org/nummeth/Programs2E.html
 
  • #33
Looking at others people's codes and trying to analyze and understand how it works is a waste of time in my opinion.

What you can do which should benefit you much more is to pick some field and write a code/program in connection.
For example, if you like semiconductor physics then you can write a code for bandstructure calculation and visualization/plotting.

Edit: if I'm not mistaken, computational physics books basically consist of tackling multiple mini projects/codes.
 
  • #34
If it matters for the discussion, every undegraduate physics major in my university must take a numerical analysis course in which they learn the basics of fortran 90 so as to write simple programs.
 
  • #35
I never really quite understood the point of FORTRAN 90. Why not just use C, or in the case of compatibility issues, just make calls to the old F77 code?
@twofish: I checked out boost::math. This seems like a much better library than what I've been trying to use (GNU Scientific Library). I will have to download it and play around with it.

I still don't know. I've always been told that C++ was rather thrown together and not really well managed as far as features go. I'm still something of a noob with it, but sometimes I catch glimpses of this, so I always imagined that something like D (or another more elegant/organized/easier language) would come along and make the world happy again.
physiker_192 said:
Looking at others people's codes and trying to analyze and understand how it works is a waste of time in my opinion.

What you can do which should benefit you much more is to pick some field and write a code/program in connection.
For example, if you like semiconductor physics then you can write a code for bandstructure calculation and visualization/plotting.

Edit: if I'm not mistaken, computational physics books basically consist of tackling multiple mini projects/codes.

Completely disagree. This is exactly how I learned how to program 8 years ago, and how I learned each programming language I know. Maybe I'm different, but I've never actually read a programming book and only half paid attention in the two classes I took for Java and MATLAB.

I don't know how useful it is to tell people how they should learn because programming can be rather difficult and abstract the first time you encounter it. What works for me or you might not work so well for someone else. I think it's more helpful to tell how you learn instead of telling people how they should learn.
 
Last edited:
  • #36
physiker_192 said:
Looking at others people's codes and trying to analyze and understand how it works is a waste of time in my opinion.

Not if you're working in a research group that has already developed code that you're asked to modify, e.g. by adding new features.
 
  • #37
jtbell said:
Not if you're working in a research group that has already developed code that you're asked to modify, e.g. by adding new features.

This is true, but for beginning, I find it more useful to start from scratch and learn the things (e.g. objects) as one would need them, by doing so, one might have to look at other codes just to see how certain parts work.

Immediately jumping to large codes is not encouraging in my opinion, especially if the code has a GUI and a large number of classes.
hadsed said:
Completely disagree. This is exactly how I learned how to program 8 years ago, and how I learned each programming language I know. Maybe I'm different, but I've never actually read a programming book and only half paid attention in the two classes I took for Java and MATLAB.

I think it's more helpful to tell how you learn instead of telling people how they should learn.

I too didn't pay much attention during the compulsory programming classes either, which I found that they get more annoying as they progress (linked lists etc...). I started the other way around, writing small non-computational codes, till I decided to write a computational MATLAB code to calculate the bandstructure of Silicon. Being the first real code, I took me sometime to finish due to various issues, I had to learn how to write MATLAB functions (was annoying because I didn't recognize the syntax properly) and so on.
 
  • #38
physiker_192 said:
Looking at others people's codes and trying to analyze and understand how it works is a waste of time in my opinion.

It's not for any non-trivial project. Computational astrophysics codes often have 100,000 lines and *decades* of effort put into them. Reading those codes is seriously important, and writing clean code so that people ten years from now can figure out what you are doing is even more so.

And it will seriously help you get a job. Microsoft Windows has about 10 million lines of code and 10,000 programmers, and being able to read and write clean code is seriously important.

It will also help you develop gut feelings. For example, my stomach turns every time I see bad code, because it reminded of the times in which I had to spend *months* fixing something that could be fixed in five minutes had someone properly designed things.

What you can do which should benefit you much more is to pick some field and write a code/program in connection.

This won't work for computational astrophysics. The thing about astrophysics codes is that they often will contain parts that are coded by hyper-experts in a field. For example, there is no way that I can completely comprehend nuclear physics as well as someone that has been spending several years studying it, and there is no point in my duplicating his or her work, if they have provided the subroutines so that I can just call the EOS routines.

For example, if you like semiconductor physics then you can write a code for bandstructure calculation and visualization/plotting.

This is kindergarten.

Edit: if I'm not mistaken, computational physics books basically consist of tackling multiple mini projects/codes.

Yes. This is first grade stuff. Textbooks are useful, but you aren't going to learn coding from a textbook any more than you can learn to ride a bike by just reading about it.
 
  • #39
hadsed said:
I never really quite understood the point of FORTRAN 90. Why not just use C, or in the case of compatibility issues, just make calls to the old F77 code?

Fortran 90 has some structures that tell the compiler (this line can be parallelized, put everything in the L1 cache). If you have a good compiler, they can take the hint and generate better code.

I still don't know. I've always been told that C++ was rather thrown together and not really well managed as far as features go. I'm still something of a noob with it, but sometimes I catch glimpses of this, so I always imagined that something like D (or another more elegant/organized/easier language) would come along and make the world happy again.

C++ is a mess but so is the human body. C++ is an example of how evolution sometimes works better than intelligent design. People add random stuff to C++, some of it sticks, most of it doesn't, and the language evolves.
 
  • #40
physiker_192 said:
Immediately jumping to large codes is not encouraging in my opinion, especially if the code has a GUI and a large number of classes.

That's actually the point. Very well written code is a joy to read. If the code has a GUI and a massive number of classes with no documentation, then it's painful to figure out what is going on. This is your first lesson in how not to write things.
 
  • #41
What about theoretical high energy physics ? Is programming of use in this case?
 
  • #42
zahero_2007 said:
What about theoretical high energy physics ? Is programming of use in this case?
Yes, absolutely. For one thing, knowing how to use a computer algebra system (i.e. Mathematica) is a huge boon. Many calculations done in high-energy physics involve working with matrices or other multi-indexed objects, which basically comes down to repeating the same operation on many different mathematical expressions, and Mathematica's programming facilities are perfect for that sort of work. Also, a lot of work in theoretical HEP is done with computer simulations these days, and in order to work with one of these you would have to know how to write it and maintain it, understand the algorithms involved, and be able to analyze and process the output, all of which require programming skill.
 
  • #43
zahero_2007 said:
What about theoretical high energy physics ? Is programming of use in this case?

Look at this:

http://root.cern.ch/drupal/
 
  • #44
physiker_192 said:
Looking at others people's codes and trying to analyze and understand how it works is a waste of time in my opinion.

Welcome to the real world. Million+ line projects don't get done by a group of people that have the same experience/coding philosophy/design standard/documentation standard and so on.

Also this reminded me of some young programmers in a diploma I did, where they all wanted to have their own game engine built entirely from scratch which was going to be superior and so on.

When there is only finite time to work on complex projects, you will need other peoples libraries to get the job done in time. For a lot of projects there is no way around this.

Also its good to see others code to put yourself relative to other people. You may find out that you're coding is not so crash hot, or you might find out a horrible way of doing something so that you have a mental note of what is really bad. Sometimes it's good to get how you are relative to other people both better and worse than yourself.
 

Similar threads

Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
1K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K