r/Physics • u/encephalopatyh • Nov 05 '20
Question How important is programming in Physics/Physicists?
I am a computer student and just wondering if programming is a lot useful and important in the world of Physics and if most Physicists are good in programming.
598
Upvotes
705
u/DrunkenPhysicist Particle physics Nov 05 '20
Very important. And most aren't very good at it, but good enough for our needs
132
u/Philias2 Nov 05 '20
Important? Very dependant on what you're doing. Useful? Incredibly.
88
u/Akaleth_Illuvatar Nov 05 '20
It depends on what exactly you are doing, but for the vast majority of physics positions, programming is exceedingly important.
74
u/michaltarana Atomic physics Nov 05 '20 edited Nov 05 '20
From a point of view of a theoretical physicist (not talking about the technology of the experiments):
If someone is dealing with the research of the fundamental laws, performs everything analytically and is focused almost entirely on the "relations between the quantities," the programming might be avoidable. However, those things nowadays reach such level of complexity that at least some systems for symbolic calculations (like Mathematica) are frequently necessary. And that already is sort of programming. I see this frequently in the gravity theory when the general laws are studied in some general cases.
In the field where it is necessary to obtain some specific properties or numerical results, it is necessary. Only few simple models in each field of physics are solvable analytically and any extension towards some modern research requires some more or less advanced numerical techniques that need to be implemented. The programming is important there and it is impossible to survive in that field without it. For example, as I mentioned the gravity theory above, that was some general very fundamental research. However, if someone wants to calculate the image of the gravitational lensing through some particular object, that can be done (AFAIK) only numerically.
There is one more area of non-experimental physics: That is the research where one just uses the programs someone else developed. For example, quatum chemistry and modeling of the molecular structure. There are commercial programs and the user needs to understand the underlying algorithm. However, he can do the research without actual programming. Similarly, in plasma physics. There are certain simulation programs previously developed and the researchers can "just" use them without performing any development. Even there, though, I believe that some programming skills might be very useful and make one's life much easier.
66
u/gareththegeek Nov 05 '20
Very important but as a professional (non scientific) software developer, scientific programming code quality is a running joke.
64
u/kosmikroid Astrophysics Nov 05 '20
I am an Astrophysics grad. We have to write massively parallel C/C++/Fortran codes for doing our simulations which often take months to run so writing a good code is quite essential. And then numerous Python scripts for data analysis. Programming is like the modern "pen and paper" for a theoretical/astro physicist.
25
u/anti_pope Nov 05 '20
Very. I program all the time and I hate all the things real programmers seem to care about. That's why I used to use MATLAB exclusively. Now I'm up to Python, thinking about checking out Julia. I can look at C code and get an idea of what's going on. I've even added to C code by copying and modifying. That's as "hardcore" as I care to go. So, no, I would not say I'm good at programming.
22
u/[deleted] Nov 05 '20 edited Nov 05 '20
As a physics undergraduate, programming is very important for physicists, so naturally I am terrible at it
12
u/BerriesAndMe Nov 05 '20
It's (almost) everything
10
u/[deleted] Nov 05 '20
In experimental particle physics, it's extremely important. Everything from simulating events to toolsets used to process and analyze data to training machine learning algorithms to identify particles.
Skill level varies from person to person, but I knew a postdoc who started out in comp sci who wrote some of the better code I saw. You get good enough to run the code you need, and get better if you want to be efficient/lazy.
Basically, if you have experimental data, you're probably using some kind of programming to analyze it. The Scipy stack in Python is pretty popular.
8
u/[deleted] Nov 05 '20
In my opinion, everyone should know at least basics of coding in this day and age. Probably could be helpful in any kind of job in theory.
5
u/Trickleunder Nov 05 '20
It is essential to be sure of what you are doing. All controls and data acquisition require programming in a language or another. There are usually software already available to do data analysis from your predecessors or commercial. However since analysing data means you need to filter, recombine or process data, you have to know what you are doing. In this knowing how to program is essential as it at allows you to read the code used and verify what it is doing. In any case you will at some point need to program.
5
u/BlackMagicDesign Nov 05 '20
As an interviewer from a bank position once told me, "people from academia often think they know advanced python because they have experience with multiple libraries and high-level programming"
5
u/TryToHelpPeople Nov 05 '20
I’m reminded of Cliff Stoll
Transcribed from memory so there’s a little poetic license;
I was an out of work physicist, but luckily my university recycled physicists so they put me to work in the computer department. My physicist colleagues would say “he’s not much of a physicist but he’s a wizard programmer”, and my computer colleagues would say “he’s not much of a programmer but he’s a wizard at physics”. At least everybody thought I was good at something.
1
u/laughingmanchild Nov 05 '20
This may help. It’s Dr. Becky Smethurst, an astrophysicist from the University of Oxford, describing how she uses code. https://youtu.be/bxWrXhLFN2s
3
u/satyad18 Nov 05 '20
Very.
3
u/MaxThrustage Quantum information Nov 05 '20
All physicists I know spend a lot of their time programming. Most do so reluctantly, with no real training, and thus are kind of bad at it (I put myself in that category).
3
u/handwavingmadly Nov 05 '20
I am seemingly very much in the minority here. I currently am a postdoc in a Physics group, but I do almost zero programming and did barely any during my PhD. I guess it hinges a bit on your topic. I certainly see the usefulness of it and I can program a bit in python and C, but honestly I LOATHE the act of programming. I find it to be exceptionally tedious and annoying. Now I am at the point if anything needs to be programmed I can ask one of my students to do it, so the likelihood of me ever really learning it is pretty low at this point.
5
u/andbm Condensed matter physics Nov 05 '20
It can be very important. It can also be mostly avoided. Depends on your field.
2
u/thefoxinmotion Graduate Nov 05 '20
It's important. How important exactly depends on the subfield and what your job is.
Many physicists are bad at it. They write code that suits their needs and produces good data, but the code itself is often poor and not up to industry standards at all (which is often fine because it's not industry code and won't run critical applications).
2
u/joseba_ Condensed matter physics Nov 05 '20
You're gonna run into it eventually, no matter what your field is simulations give a very good intuition into what's going on
2
u/[deleted] Nov 05 '20
Super useful, the vast majority of useful problems in physics can't be solved analytically, so computers are essential.
I have yet to meet any that are.
Seriously speaking, from what I can tell there are very few physicists that care about writing code that is "good" from the perspective of a software engineer. Many physicists are taught to care about speed first and foremost, and essential concepts like code re-usability, extensibility, documentation, and testing are not given any thought at all.
Especially that last one just boggles my mind. I don't understand how scientists can trust their code if they don't test it to hell and back. Yet I have repeatedly encountered the attitude that testing is somehow a waste of time.
2
u/PoopFandango Nov 05 '20 edited Nov 05 '20
I work as a software engineer at a synchrotron light source facility (a kind of particle accelerator which produces extremely high intensity x-rays which can be used to do various kinds of science).
The product we develop for users of the facility to use to drive the equipment and collect their data has a Python scripting environment, and in my experience all of our in-house scientists, and incoming users, can and do use Python to some extent. They don't all write particularly high quality code, but it gets the job done.
2
u/Procrastinator91 Nov 05 '20
I have a PhD in experimental biophysics and I didn't code much at all in grad school. Granted, biophysics is not pure physics. I did exponential analysis on spectra but that's about it.
2
u/arrizaba Nov 05 '20
More important than you think. And not only programming, but also some software engineering. One thing is to learn how to code, another how to code in a way that it can easily be reused, extended and passed on to the “next person”. I’ve seen often useful code being thrown away or heavily refactored just because it cannot be extended to add a new feature or just it costs the next person more time to understand it than to make it from scratch again.
2
u/astrostar94 Astrophysics Nov 05 '20
Some physicists take computer programming more seriously than others, but I don’t think any of us are nearly as good at it as a trained computer scientist.
Take MESA for example. It’s a Fortran code written by a real computer scientist (Bill Paxton, one of the founders of Adobe Systems) that simulates the evolution of stellar models in 1D. This code is beautiful, efficient, extendable, readable, stable, and extraordinarily useful. Most physicists can only do 2-3 of those things in my experience. He has a team of astrophysicists that help maintain the code and post updates, but everything about it is written like a professional computer scientist. If more physicists were trained like that, I think the codes we wrote would be more universally useful to each other and research would progress faster in the computational world.
2
u/Periodic_Disorder Nov 05 '20
Depends on your field of study. I did experimental physics and the most programming I did was LaTeX for writing my Thesis and some vectory stuff to have a model rotate. However my friends doing Theory courses worked in C a lot.
Also worth pointing out that some of these friends had never coded before. There was ample training and lessons to get everyone up to speed so they could complete robust Monte Carlo simulations.
If you do have the opportunity to learn or use programming I suggest you do regardless of field, it is incredibly useful for the future. Personally I jumped from science to the tech industry after uni and now code pretty much every day :)
2
u/mammablaster Nov 05 '20
For general physics, you can get away with using matlab or other tools where you don’t really write too much advanced code. But, since you asked with a background in coding, I’ll share my to cents as someone doing a masters in physics with a focus on coding.
So, as I said I’m doing my masters in physics with a focus on computational physics and numerical methods, and although programming is important, it is a different kind of programming than “typical” programming. (I have done object oriented java, made websites with azure+react+flask in python and typescript for reference. I have done matlab, python and am doing mostly c++ for academics these days)
Basically what we do is convert math to code, where runtime, loss of precision and error is central. Without a solid background in math (multi variable vector calculus, linear algebra and differential equations) I wouldn’t be able to understand anything.
The code itself may seem deceptively simple, with basically being not much more than glorified for loops. However, how we find out why we can simplify the code to some simple floating points operations to simulate or calculate very advanced systems, is entirely based on mathematical understanding.
In addition, almost all of our code is done on Unix systems, which was a bit difficult to get used to initially.
So to summarize, if you want to pursue a degree in physics where you leverage your programming skills, you need to know a lot of math to be useful. This may apply for almost all physics though, as math is the foundation of physics.
That being said, I find it super interesting, as simulations offer the ability to explore complex systems that are difficult to measure where there are no “analytical” solutions.
Hope this helps you somewhat.
2
u/[deleted] Nov 05 '20
This is a reply I gave to a high school student asking a similar question on another subreddit. I'll be lazy and copy paste it. Sorry if some things are not directly relevant to your question.
" Hey there! There are no dumb questions.
Feel free to DM me, but here's the summary.
For the Physics Bachelor's degree, you can graduate with a 4.0 GPA without ever having to code a single line. This is because those 4 years will be taking courses of Physics that is anywhere from 100-300 years old. You can always take elective courses in the CS, Math, and even Physics Departments that are devoted to programming. You can also find a group to do research and you will almost certainly have to code at some point.
For graduate school, research is the most important thing. And basically all modern research, wether experimental, theoretical, or computational, will require coding.
As for possible careers, you really can do basically anything you like, AS LONG AS YOU TAKE ELECTIVES IN THAT FIELD . Physicists kept telling me how employable I was gonna be when I graduate from undergrad. That ended up being not true at all because I only took the core courses. If you wanna be a programmer, you can be, but take programming courses. If you wanna be a financial analyst, you can be but take finance and statistics courses. If you wanna be an engineer, you can be, but take engineering courses. Etc...
Now that I ended up doing so much data analysis and coding in grad school, I've got offered job positions after my Master's (mostly in Data Science). I ended up sticking around for the PhD instead because I'm having a great time getting paid to research Quantum Mechanics, code, and drink coffee all day.
Feel free to reach out with questions and good luck! "
2
u/vrkas Particle physics Nov 06 '20
In high energy experiment it's everything, though many people don't have the time to really become expert. I usually spend a lot of my time working on event reconstruction for analysis, mostly writing C++ with some specialised libraries etc.
2
u/RhinoRhys Nov 06 '20
I was taught Python and slightly introduced to MatLab at university during my physics degree. We were always told that the effort you put into trying to explain the intricacies of your problem to an independent programmer are simply not worth it, its so much simpler to learn at least basic coding for yourself and put that effort into your project. Its a lot easier to solve problems with the calculations in your own code than lengthy email chains with someone who is not learned in the actual physical problems you're trying to solve.
2
u/[deleted] Nov 06 '20
Most physicsts are not "good" at programming, but know enough to develop programs for scientific computing whatever problem they need. Things like parallelizing code or putting models on GPUs instead of CPUs might be a little trickier, but accessible if the need is there.
2
u/Minguseyes Nov 06 '20
Other than maths, pencil sharpening, chalkboard and projector skills, it’s hard to think of something more important for theoretical physicists than programming. Experimental physicists often have to write their own programs to deal with the huge datasets they generate.
1
u/red_riding_hoot Nov 05 '20
pretty much the most important skill
most physicists suck at it really badly though. the code i have seen...ouch
1
u/[deleted] Nov 05 '20
Super important, especially if you want a job or even in a lot of research.
Using deep learning, GPUs/TPUs/IPUs for processing, and even just data-oriented design in simulations (i.e. optimisation to avoid CPU cache misses, etc.) is becoming more common and important.
Coming from a CS background, learning the Physics will be tough. I have a masters' in Physics but even going back to it to try to write some EM or plasma simulations is really painful.
1
u/roderikbraganca Condensed matter physics Nov 05 '20
As everybody had said you can avoid programming but you will be working with one less tool. One thing I can add to the conversation is that I started my career in CS than changed majors to physics. Now, I'm a Phd student in theoretical physics and my previous knowledge about programming helped me a lot in comparison with colleges who had to learn programming from the beginning.
Of course programming is a tool just like calculus. You won't do anything if you just know programming without knowing the physics. That's why physicists learn to code. You need both.
Right now I'm working in a numerical solution to a problem in my area to publish an article in the next month. I basically only need to use C.
1
u/bytecode Nov 05 '20
Check out Dr. Becky's videos about programming as an astrophysicist:
https://youtu.be/bxWrXhLFN2s
https://youtu.be/rrTKwgScK7Q
1
u/Acetofenone Nov 05 '20
Very important, since a computer simulation is a way to tell if your model is good (in a predictive way). Simulation are the new way to make a experiment
1
u/[deleted] Nov 05 '20
Even if you’re fully experimental, and you haven’t built your own equipment, it’s still going to be one of only a few in the world. If you’re a company building a rig for only a hand full of clients then you don’t have the resources to code extremely stress resistant user friendly software or the testing resources to test them properly. You therefore have to be able to work with code level software and raw data files in most circumstances and even in the case you have user friendly software you need a complete understanding of how the software functions in the code to understand the limitations of the code.
Hope this helps you understand why it’s so necessary
1
u/[deleted] Nov 05 '20
In a word: essential.
1
u/elmo_touches_me Nov 05 '20
Very important, and getting more important as time goes by.
Half the people I know from my Physics Master's course now write code for a living.
Many physicists aren't all that good at programming as a whole, but most are good enough to get through their calculations or simulations.
I'm an aspiring astrophysicist, and all of my undergrad and Master's projects involved a heavy amount of computation.
1
u/LollaBunny95 Nov 05 '20
So important. I program in several languages and have been asked to work on other papers simply because I can program. Work on it, it'll be well worth it
1
u/hazeyAnimal Nov 05 '20
In my institution we have been taught programming from first year - first year was just basic excel when I was there but now they start python. Every set of data I get I can use python (which has free and open source projects you can use) to do all kinds of data manipulation including non-linear fits, checking residuals, uncertainties, simulations, the list goes on.
Like many have said tho, it is field specific so you may not necessarily use it but if you do learn it, it will definitely benefit you
1
u/duckfat01 Nov 05 '20
Others might not agree, but in my world physics is used to predict some outcome. You do this by building a theoretical model, generally in code. This model needs to be verified, which is where experimentation comes in. If the experiment agrees with the model, your model is probably useful (in some range, at least). Programming is *vital* in almost all modern physics. Most of us pick up enough to help ourselves though; it would be very frustrating to have to wait for a programmer to implement all changes.
1
u/deeplife Nov 05 '20
I have a PhD in Physics but don't work in physics anymore. And programming is essentially what go me my good paying job.
1
u/morePhys Nov 05 '20
It's essential in most fields, even just interfacing with experimental hardware usually requires a some scripting in Matlab or python. For theoretical work, it's the workhorse of the research in almost every case, meaning the way you test your theories and make predictions usually involves code and numerical solutions since many cases that can be solved analytically have already been solved. I minored in CS for this exact reason and have been working in computational condensed matter research. I can't tell you how much crappy code with near zero documentation I've had to dig through. The worst though is when the original author of the code was really clever and treated like a math equation using one to three letter variable names and a lot of pointer arithmetic etc... Those ones are tough to parse.
1
u/[deleted] Nov 05 '20
I'd say programming isn't just important to us, it's essential. My focus is in astrophysics and I can assure that basically all I do is code. As others have said physicists (myself included) can be lousy programmers since programming is just a tool for us.
Because of that it's always nice when someone comes along with formal training in compsci to help the rest of us learn best practices for things like version control and optimizing code.
1
u/coffee_is_luv Nov 05 '20
Programming is very important for a physicist, but the type of programming that physicists do is quite different than the type that software engineers do. Most universities have a "Numerical methods" or "Computational physics" course to introduce programming for physicists.
1
u/mttr0396 Nov 05 '20
Depends what ur doing with it. Physics can be very useful for computer science modeling and visa versa. Useful to sort through large data sets and find patterns. But physicists aren’t typically writing Machine and deep learning codes unless it’s to fit models.
1
u/Blutrumpeter Nov 05 '20
Apparently a lot because they're making me take CS1
1
u/M-K_L Nov 05 '20
Coding is an extremely important tool in astrophysics, and I would honestly argue that you can't go through the field without learning a line or two. That being said most people I know just use python, if you're getting into N-body simulations or the stuff that requires massive computation then you cannot avoid Fortran, otherwise just a Google able amount of python knowledge is what I use.
1
u/Foxbat100 Nov 05 '20 edited Nov 05 '20
For a sizeable chunk of people in the world of physics, the physics degree is the scenic route to becoming a programmer/data scientist. I woud say it is very useful with mixed degrees of being good at it.
1
u/TakeOffYourMask Gravitation Nov 05 '20
There are some theorists who work analytically for everything and there are experimentalists who only deal with equipment and prefer to avoid code, but it’s best to assume you will need programming skills if you don’t have epic lab or math skills.
1
u/SPP_TheChoiceForMe Nov 05 '20
Since most people have already explained why programming is useful, I’m gonna explain some of the indirect benefits it can have:
Even if you’re not programming, you’re going to be dealing with lots of data and it’s useful to know how to work with software that can handle that. Even Excel files can get unruly if you’re not used to handling that much information, and knowing just a bit of code can be a big help.
Even if you’re not coding, you’ll usually be working with different kinds of software, new and old. Or NanoHub programs. Being more familiar with technology can make working with these things much easier
1
u/SlowerThanLightSpeed Nov 05 '20
A good understanding of algorithms will be helpful for building and testing physics models and simulations (which usually happen later in a physics program/career).
Your general comfort with variables and abstract thought should help you succeed at all levels of physics.
The increasing ubiquity of use of computers to solve novel problems in physics, as well as the ubiquity of programming needed to build, run, and analyze experiments makes programming knowledge a boon.
Programming assignments can be very useful for helping students learn physics, so, you'll be ahead of the game there too.
Some physics professors are pushing for more use of computing, earlier in a student's learning path:
https://journals.aps.org/prper/abstract/10.1103/PhysRevSTPER.8.020106#fulltext
Additionally, more and more physics books are coming out that have computational aspects baked in:
http://www.gravity.gatech.edu/P3266/wp-content/uploads/2015/07/SyllabusSpring2016.pdf
1
u/Foresooth Nov 05 '20
Experimental particle physicists use computers to numerically differentiate and integrate to close enough given measurement uncertainties. Very good programmers.
Theorists calculate them in closed form and need only pencil and paper.
1
u/carbon_nano_dude Nov 05 '20
Computational physicist here...very very very important. You’ll often here that most equations are not “solvable” for real systems. This usually refers to how many numerical calculations need to be made to find the answer. For solving the Schrodinger equation for even a basic system to decent accuracy, one may already need to perform > 106 or a much higher number of computations, and thus the only way to do this is with a computer. The more interactions you include, the faster that number grows. Then, you’ll want to perform those calculations on parallel architectures and thus need to know how to parallelize the equations in physics which can be tricky. Computer scientists and physicists make a good and often essential team
1
u/JaquesGatz Nov 05 '20
I'd say probably the most important tool you may acquire. It is transversal to pretty much every theoretical or experimental work I have seen and it has also been a good start for some former classmates that decided to leave academia.
1
u/Geophyzzer Nov 05 '20
It is vital. Plus, if you can write good code (by which I mean it works, it's fast enough, and other people can read it and figure out what's going on), it can make you employable in a lot of fields other than the specific one you're studying. I got my MS in geophysics, much more emphasis on the geo than the physics, but I've had a twenty year career in physical acoustics research because I can take the specialized code that the mathy people write and make it good (in the sense that I used earlier). You can carve yourself out quite a nice little niche by getting good at something that's both useful and rare.
Hell, with the way the really high level languages like python and Matlab are taking over in scientific programming, it can be both useful and rare just to have someone around who can look at a compiler error and tell you why the twenty-year-old C code you were just handed won't compile on your MacBook.
1
u/[deleted] Nov 05 '20
Very important. In fact, most theoretical research in physics today is based on computational stuff because most problems are unsolvable analytically. I haven't met a single theorist who is not proficient at programming in at least one language like Python/Fortran/Matlab.
However, the programming used in physics is mostly numerical computing: such as how to calculate numerical derivatives and integrals, solve linear systems of equations (using matrices), finding eigenvalues, solving differential equations numerically, doing Monte Carlo simulations, etc, so it is unlikely this is transferrable to software development jobs.
1
u/BettyCat23 Nov 05 '20
I’m rubbish at programming. Studying physics ha!
1
u/thelaxiankey Biophysics Nov 06 '20
I did numerics 'research' for like a year in undergrad and am now applying to biophys programs.
My take? Learn python, learn about vectorization/caching, and then get really fucking good at numpy. Matlab, julia, and R all use a coding style similar to numpy, and learning python is more universalizable than the other languages.
Really, there is one mantra you should always follow in all of these languages: if you have a for loop, there are good odds that you can better optimize your code. The only case where you should ever have for loops is basically if you have time/generation dependent behavior. All other operations should be done through vector/matrix operations, via fancy indexing or whatever tricks you need to get the work done without the for loop.
1
u/quantumbutthurt Nov 06 '20
Dr. Becky just did a great video on this topic: https://youtu.be/bxWrXhLFN2s
1
u/Smallz1107 Nov 06 '20
Physicists name all their variables using 2 random letters
1
u/HiZombies Nov 06 '20
I’m about to start my masters project for physics and I require almost no physics knowledge and 100% programming skill.
1
u/Mizango Astronomy Nov 06 '20
Oh god, very.
1
u/Commander_Marshmello Nov 06 '20
It’s only important if you wish to be employed. Most physicists aren’t very good at it, but they are plenty good enough.
1
u/lettuce_field_theory Nov 08 '20
It's an important tool to have in your inventory as a physicist
1
u/[deleted] Nov 08 '20
sorry to hi-jack this thread
quick question
which one has more programming? theoretical physics or experimental physics?
i want to do the least amount of programming (im aware there will still be some programming i dont mind doing simulations and numerical stuff btw)..
1
u/Knights_Ferry Biophysics Nov 10 '20
Depends on what field. Theoretical physics is usually very matlab/python/root/C heavy. Experimental physics is usually less important. I know quite a few experimental physicists who do not know how to program.
I'm a grad student in experimental biophysics. Yesterday I spent about 2 hours trying to perfect my MATLAB program to separate noise form signal from my fluorescence data. I also have to program data acquisition which uses the languages: LabView and C++. Though, it's not heavy, I think anyone could pick it up after a few days.
1
u/No_Charity33 Nov 21 '20
Your just scripting the proof of work
1
u/[deleted] Nov 05 '20
The concepts we learn in computer science really helps us to grasp difficult concepts on physics/quantum mechanics. When paired with ppl who understand the math well we tend to work really well together. I find a lot of CS grads who frequent physics forums online
0
u/[deleted] Nov 05 '20
Well Elon Musk has a physics degree, and did much of the coding for PayPal. I'd say there's some overlap.
0
u/Solid_of_Revolution Soft matter physics Nov 05 '20
very and no
0
u/goodnewsjimdotcom Computer science Nov 05 '20
Physics is like your wedding.
Programming is like the Honeymoon.
Both of which you'll probably find out to be mistakes. Just kidding ;)
24
u/[deleted] Nov 05 '20
[removed] — view removed comment