23
$\begingroup$

How important is programming in physics?

I am studying physics at university and these first years there is actually no approach (as it is understandable) to what working in physics is like. Now, I know programming is actually important (I've read several posts in forums - even the one present here on Stack Exchange), but I actually was wondering: what 'hardware' is used in physics? Is it worth to learn to manage things like a Raspberry Pi-kind-of board? Or it just wouldn't be worth?

I don't know if that could be of use to answer this question, but I would be interested in condensed matter physics for the future.

$\endgroup$
9
  • 11
    $\begingroup$ Too broad and too opinion-based. Possibly the only valid answer is that there is almost no area of physics where programming is unimportant, but I'm sure a theorist will correct me on that too. $\endgroup$
    – ProfRob
    Commented May 25, 2015 at 9:52
  • 1
    $\begingroup$ Interesting question, but I am afraid it will be closed as primarily opinion based. If not, I can write a long story on my opinion on this issue. Basically do as many physicists do: learn as you need. Most physicists are very lousy programmers, so don't worry to much about it. $\endgroup$
    – Bernhard
    Commented May 25, 2015 at 9:53
  • 3
    $\begingroup$ I feel this is a valuable question and it would be a shame to close it - I can see a number of good answers on the Good Subjective side for this. $\endgroup$ Commented May 25, 2015 at 9:57
  • 1
    $\begingroup$ The variety of hardware and software used in physics is immense. If you're a student and you don't yet know what interests you, where you'll be working, and what you will end up working with, then it is absolutely valuable to learn as much as you can about as many things as you can. The same patterns show up again and again in hardware and software - the more you expose yourself to, the easier it becomes to learn something new when it falls in your lap. $\endgroup$
    – J...
    Commented May 25, 2015 at 13:49
  • 5
    $\begingroup$ The real difficulty with this is that there are no wrong answers here. No right answers either given that what is true in my bit of physics in doubtless wrong in some other corner of the discipline. Short versions: there is no preparatory curriculum of "physics programing", because there is no single notion of programming in physics. Not for software, not for language, not for hardware (which changes ever ten years or so, anyway). $\endgroup$ Commented May 25, 2015 at 15:33

3 Answers 3

35
$\begingroup$

As a computational physicist working in materials/condensed matter, I'm either highly biased or well-placed to comment on this.

Physics, in practice, is divided into three overlapping approaches: experimental, theoretical, and computational. (The highest impact research papers usually include a combined effort from all three.)

If you plan to go into computational research then you will have to do a fair amount of programming. However, I don't know anyone who has made use of Raspberry Pi's for physics research (that's not to say that no one has, but it's a novelty rather than something that is commonly done). In computational physics, your code will almost exclusively be executed either on standard desktop machines or supercomputers (where you use message-passing systems like MPI to exploit huge parallelism). Virtually all universities have their own supercomputers, but you may also be granted access to some larger national or even international supercomputers (such as ARCHER, Jaguar, and so on).

Graphics cards have also become quite popular for physics research in recent years due to the rise of CUDA, and most supercomputers now include several nodes packed with high-end graphics cards. So GPGPU programming is a nice skill to have but by no means a necessity.

It's also worth mentioning programming languages. Mainly for historical reasons, most academic code is actually written procedurally in Fortran (which is so archaic it still has functionality left over from the punch-card era). C/C++, Java, and Python are also widely used, along with the Unix shell (most academic machines run Linux). Those who do a lot of statistical modelling mostly use R or IDL. And those who are too lazy to do real programming - mostly mathematicians and engineers - use MATLAB or Mathematica (okay, I'm being a bit harsh on that one).

Let me finish by discussing theoretical and experimental physics. Virtually every theorist I know does much of their work on computers - programming code to numerically solve, or test something, for instance. And many of their 'theories' are aimed at advancing computational methodologies. A classic example of this is the Hohenberg-Kohn theorems which laid the foundation for density functional theory, and there are now many theorists trying to extend this by developing linear-scaling and real-space DFT.

It has also become common for experimentalists to program. Whether that be microcontrollers like Arduinos (as pointed out by Emilio Pisantry below), scripts to analyse data, or even employ standard simulation techniques to better understand their experimental observations.

$\endgroup$
2
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$
    – David Z
    Commented May 29, 2015 at 9:33
  • $\begingroup$ How about Julia? It seems quite promising. $\endgroup$
    – Shing
    Commented Nov 24, 2018 at 15:17
3
$\begingroup$

Hardware-wise, it would be likely that you would write code on a unix-like system that can distribute code to multiple cores and/or at least one GPU.

If this post relates to what hardware you should be using: I would suggest you set up a desktop PC with the following for a cheap but effective solution:

  • An NVIDIA graphics card - Only NVIDIA graphics cards can run CUDA and consequently work with the most GPU accelerated libraries. AMD / other brands can utilise OpenCL but you may have a situation where your course uses a library only compatible with CUDA. Currently, certain libraries such as python's theano only really support NVIDIA cards because of their CUDA dependency
  • A CPU with at least two cores - so you can play with multicore code
  • Ubuntu is a very simple and effective unix-like platform that will give you a good programming set up
  • Dual Boot Windows - mainly for ease when writing coursework

The above list allows you to play with GPU accelerated code, multi-core programming and lets you install libraries easily through ubuntu.

From my experience, you can often run intensive code on university supercomputers but you may not want to have to go through the effort of accessing them all the time / you might not have the ability to access them all the time.

As a recent physics graduate in the UK, I can say that every job I have been approached about or applied for, related to physics, has had a computational requirement.

As for languages, I have had to learn Python and C/C++ since graduating from a course that taught Fortran. I would recommend learning all three.

$\endgroup$
4
  • 1
    $\begingroup$ You are omitting OpenCL. Whilst CUDA is probably the most advanced add-on to C(++) for GPUs it is not the only one. OpenCL is supported by all three major chipmakers(Intel/AMD/Nvidia). A secondary Windows is imho not necessary. I've been wroking with openSuSe for 5 yrs and only use Windows for FPS games - anything else is too cumbersome on Windows. $\endgroup$
    – Nox
    Commented May 26, 2015 at 12:31
  • 1
    $\begingroup$ Fortran hasn't been FORTRAN since 1991, please update your spelling. $\endgroup$
    – Kyle Kanos
    Commented May 26, 2015 at 20:33
  • $\begingroup$ Thanks for the comment. I have now edited my post to include comments on OpenCL. I agree that windows is very cumbersome for formulaic coursework. Most of us are familiar with it though, and after a boozy night in a university bar, it takes a lot of motivation to learn a new editor! Finally, Windows will most likely already be installed on all cheap laptops so just bolting on ubuntu is fairly straightforward. @KyleKanos , apologies, I was taught FORTRAN 90 standard until I graduated in 2013, so for me it was indeed FORTRAN. $\endgroup$ Commented May 26, 2015 at 20:34
  • 2
    $\begingroup$ The Fortran 90 standard (released in 1991) did away with the all capitals spelling of FORTRAN (which is often used nowadays to specifically mean the 77 standard). If you learned F90, you learned Fortran 90, not FORTRAN. $\endgroup$
    – Kyle Kanos
    Commented May 26, 2015 at 20:38
2
$\begingroup$

Much theoretical physics and simply "learning" physics doesn't require much programming. This is the case deep into many physics fields.

Experimental physics with data processing on the contrary does. Not programming directly, but a good knowledge of calculation and data/matrix-based software. These often require some programming skill, like Matlab or Maple from MathWorks.

When you get to the field of condensed matter physics and molecular structures etc., you will need some statistical physics methods and tools for numerical iteration and simulation, which are impossible without a CAS tool.

Of course, reaching the electronic world often requires some kind of circuit control. An Arduino or Raspberry Pi and whatever else they are all called are tools to control circuits. But often this is not for physics work, unless you step all the way into the digital area and away from the physics principles behind it.

$\endgroup$
1
  • 4
    $\begingroup$ An engineer plugging Matlab - looks like I was right ;) $\endgroup$
    – lemon
    Commented May 25, 2015 at 11:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.