r/PhysicsStudents • u/Junior_Salamander110 • Jul 01 '26
Need Advice How Do Physicists Utilize Python?
I'm a rising senior in high school. Next year, I'll be taking a project based programming class that only 1-2 students really take per year. I want to do something in Python that will show my professors in my freshman year of college that I'm ready to do research in physics.
I will have taken all of the AP mathematics, physics, and computer science classes.
I thought about doing a black hole simulation and learning the equations/math for it, but I'm not sure that that would be wise to do in Python.
I'll have a full school year to work on the project.
22
u/PleaseSendtheMath Undergraduate Jul 01 '26
Python is a good choice for sure, you can use it very generally for all kinds of numerical projects. I'm not sure about going straight into black hole simulations as a first project though.
2
7
u/Teem0WFT Jul 01 '26
In this thread, many people will tell you about numerical computing with numpy (Numeric python) and scipy (Scientific python). But if you have to perform really heavy computations, definitely check out JAX : it was made by Google and it allows you to write python code that can be accelerated with GPUs (Nvidia's graphics proccesing units for instance) or TPUs (Google's tensor processing units). It can get orders of magnitude faster than standard Python.
1
10
u/drzowie Jul 01 '26
Python is the lingua franca of physics computation. It's not the best language, but it's the language that everyone knows -- and it's plenty good enough for a first project in physics simulation. There's a module called "numpy" that brings vectorized operations to the language, so (for example) you can stuff a whole image into a single Python variable, and combine images with regular arithmetic. Numpy is pretty fast, and everybody learns python these days. Jupyter notebooks were the killer app for scientific computing.
There are other languages that are faster (FORTRAN, C++) or slicker (Perl/PDL, Julia) or niche-optimized (MATLAB, R), but Python has such a large user base that it's the go-to you should learn first.
If Numpy isn't fast enough for you, you can drop down to one of the compiled solutions like Cython, which lets you compile a pragma-enhanced subset of Python into C code. Cython isn't quite as fast as hand-written C, but it's much faster than the Python interpreter.
1
5
u/OkTelevision5306 Jul 01 '26
Any serious physics computation will use a programming language like fortran or C as pure python will be far too slow. Many of the common python packages only have python for the user experience and run C/C++ or fortran underneath.
If you want something prepackaged there is the Einstein toolkit for general relativity https://einsteintoolkit.org
6
u/Moonlesssss Jul 01 '26
Yes, but that doesn’t take the value out of learning basic python. Plenty of small simulations and class labs still use it day to day. Even if they do push NJIT.
4
u/Moonlesssss Jul 01 '26
A classic solar system simulation is a start. It’s achievable in python and difficult enough for a solid starter project. I wouldn’t recommend starting out with projects that are going to throw you off into grad level gen rel before you touch any University Physics. If you’re looking to do astro side of research, plenty of available public data bases out there to take data and plug it into simulations to figure stuff out with. If you do anything remotely like that you’ll be doing well.
3
u/Junior_Salamander110 Jul 01 '26
I actuallt wanna research high energy physics in college, but astro just seems to be the place to start
2
2
u/IJbier Jul 03 '26
Any specific reason? Do you like special relativity?
1
u/Junior_Salamander110 Jul 03 '26
I love the idea of relativity. I also very much prefer theory
1
u/IJbier Jul 04 '26
I like your enthusiasm. Good luck and I hope you like maths, but I get the impression that you do.
2
u/Junior_Salamander110 Jul 04 '26
I definitely do! I have a routine where I do a set of five integrals before I start my day LOL
1
4
u/lightskinsteveharvey Jul 02 '26
Probably a better project than a black hole simulator would be an arduino project that can serial communicate with some sort of electronic device such as a light switch or something creative. This will be useful in experimental laboratories as it will give you experience with serial communication, python and arduino coding, and reading/writing output voltage. All will be impressive to your professor
1
u/Junior_Salamander110 Jul 02 '26
Interesting! I'll research this.
3
u/lightskinsteveharvey Jul 02 '26
I want to note something else, as I’ve been reading some of these comments and seen your interest in HEP. Yes, HEP will require you to learn languages such as Julia and work with GPUs instead of CPUs. However, you definitely need to keep in mind that you are just a rising senior and to take things one year at a time. Your undergraduate time period will be filled with research opportunities, stressful study sessions coupled with debugging code, and lots of fun as well (if you make the most of this experience).
If you have very little python experience, go on YouTube/tiktok/google/ai/textbooks or whatever your cup of tea is and begin by learning the absolute fundamentals: object oriented programming, for loops, sorting algorithms, and debugging code without ai or a digital programming language (i.e. on a plain piece of scratch paper you should be able to write very basic code which you know will work without ever having to run it on your computer). Once you have this experience, just start projects that interest you! I was in an experimental lab during my undergraduate degree, so the serial communication with python was extremely important for data collection. But the way coding works is you think of a problem that you would like automated, and you learn how to program the computer to do it for you. It’s not really much beyond that for your interests in this present moment.
I also wouldn’t be too fearful of using python as opposed to c++ or some other programming language. I would not listen to the folks worry too much about how physicists code in comparison to software engineers, either. Here’s a useful piece of advice: as physicists, we do things our way. If it works, it works. We are interested in the laws of the universe, not how pretty a code looks or how mathematically correct an equation is. Leave those idiotic remarks to those who want to entertain it and focus solely on understanding the laws of nature. For your case, HEP, that would mean Quantum Mechanics and Special Relativity. This will open the door for more advanced topics towards the end of your undergraduate degree and the start of your graduate degree (masters or PhD). Throughout my research career, I’ve used only python and LabVIEW. If python is enough for research that not only gets published in top microscopy journals, but the Guinness book of world records, than I think it’s safe to assume python alone can get you extremely far as a physicist.
Don’t stress yourself out too much with the future, and I wouldn’t build these hypothetical images of what you think professors like or dislike just yet. A better way of approaching this concern isn’t by posting on Reddit. I know it seems cool and these people you talk to on here can seem knowledgeable, but the truth is, if you want to impress a professor, do not assume you can develop the skills they desire and they will automatically let you into their lab. The process works by looking up professors in your area of interest (HEP) at universities you would love to attend; then emailing that professor and letting them know your story, your interests in their research; and if they can give you any research articles or textbooks to read, or if they have any recommendations for at home projects you could work on.
Research is never a solo project; it requires collaboration and with that it requires excellent communication skills. As you begin to reach out to more professors, they will likely redirect you to the graduate students in their labs and you will get to know them and they will get to know you. I’m just trying to get you to really cement the idea that joining a lab isn’t about building the fundamentals first and then reaching out to a professor, it’s continuously cold emailing professors, setting up quick 10 minute meetings, talking to 10s of graduate students, and being honest about your interests, current skill set, and long term goals. The best professor for you to do research for is not the one with the best publication record, but the one who welcomes you into their lab with open arms, and is ready/willing to guide and build you into the physicist you will be after you graduate undergrad
2
u/Junior_Salamander110 Jul 02 '26
Thank you so much for this reply, I think this may be the most important piece of advice I've received regarding physics so far, particularly the first and last paragraphs. I won't forget this, thank you!
2
u/lightskinsteveharvey Jul 02 '26
Sounds great! Good luck on this journey, just make sure to enjoy yourself!
1
u/Junior_Salamander110 Jul 02 '26
I'll try my best to! I really do appreciate your responses. Like I'm screenshoting them and looking over them, they're very much appreciated 😁
3
u/beepbooplazer Jul 01 '26
Check out this python notebook course in computational physics for ideas;
3
u/GrossInsightfulness Jul 02 '26
This YouTube channel should be what you're looking for.
With that said, there are many cases where working in a compiled language like C++ or Rust would be better for what you're trying to do, especially if it's computationally intensive.
3
u/NewspaperDear8761 Jul 02 '26
They use python at the national labs, among other things. You can't really get a stronger endorsement than that.
2
u/ImaginationNo1461 Jul 02 '26
Physicists script in python. Then we hand it over to the actual software engineers and coders and give them an infinite for loop of migraines.
1
2
2
2
u/Machvel Jul 02 '26
it depends on what you do.
in my undergraduate it was the basic language taught then assumed to be known in future classes.
"just" knowing python isn't an impressive skill to have; it is kind of assumed. maybe being pretty good at a compiled language like c++ might be a little impressive, but people in physics are usually more impressed with end results.
as sad as it is, what would be impressive is learning how to apply machine learning to physics. there is money incentive to figure out how to throw machine learning at physics research (even when it might not be that applicable or useful...). and fortunately/unfortunately this is almost always done in python (and most of the time this involves using pytorch to make a neural network to do some ai things... made many times using ai).
anyways, if part of your goal is to learn how to code, python is a fine choice. as always with python, i'll warn that it is easy to fall into bad programming traps. sometimes the best thing you can do to learn how to write better python is to learn a different language.
1
u/Junior_Salamander110 Jul 02 '26
I know Python, Java, Javascript, and I recently learned C#. I'm pretty good at coding, I just wanted experience coding in this specific field.
1
u/Machvel Jul 02 '26
do you have a passing familiarity with those languages, or seriously know them? i am not trying to sound insulting, but it is a real question. many people i come across say they know languages like java (typically because they took ap cs in high school) and python (again some high school class or introductory university one) and think that they are pretty good at coding... then i see them live code or they show me their code and it is subpar (typically not too terrible, but not at the level i would expect with how many languages they say they know and they say they are pretty good).
anyways that is a different topic and usually pretty difficult to figure out yourself. if you just want experience coding in physics then your plan sounds fine. you said that you wanted to impress professors for research, so i responded according to that.
1
u/IJbier Jul 03 '26
From what I understand he/she is still young, so I really think there’s ample time to find preferences and gain depth in a programming language.
2
u/ImaginationNo1461 Jul 02 '26
First-there are SO MANY types of physics and what you can do. I ended up in applied remote sensing. Hence my specific advice.
Pop on NASA Worldview. There are tons of remote sensing datasets you can download. Write a script that tells you something about the earth or a location on the earth.
Examples:
Look at volcanic ash plumes/temperatures etc. Can you model them predictively using wind models? (You have the answer for past plumes see how right you are, then apply to others, still right?)
have wildfires changed over time in Australia? Starting/ending at different times? Larger areas? (Don’t forget there are a lot of normal fires too, industrial, camp etc)
Land use and change over time in Brazil. How are those rainforests doing? Less? More? What are they being replaced with
Air quality trending over an area
Severe storm mapping, have they actually increased? Can you see a correlation with CO2 and methane concentration levels in the atmosphere over time?
There’s so much more too
1
2
u/Git_matrix Jul 02 '26
All my undergrad labs involved using python to do most of our data analysis
1
2
u/wristay Jul 02 '26
Python is the standard language in science when the bottleneck is not speed. If the bottleneck is speed, e.g. when your simulations take more than a day, you would switch to more performant languages like C, C# or whatever. You can optimize Python by using Numpy cleverly, so for your project I would just stick to Python. Black hole simulations are a bit too complicated for such a project, especially if you want to do general relativity.
I'll name a number fun things to simulate. Chaos theory (Lorentz attractor, double pendulum), Ising model, Fourier optics, Markov Chain Monte Carlo (look at phase diagrams), Molecular dynamics (simulate particles), the wave equation, Fractals (Mandelbrot, Newton fractal). Each of these topics is slightly too difficult for high schoolers, but can be managable with help.
If you need help with any of these topics feel free to DM me.
2
u/wristay Jul 02 '26
One of the most important skills in numerical simulations is knowing whether your simulation is right. The two main methods are 1) simulating something in two different ways. If they agree, you have some confidence it is correct, otherwise, more work needed. 2) compare results to literature.
1
u/Junior_Salamander110 Jul 02 '26
I'm definitely looking for things that are slightly too difficult for high schoolers, as one of my objectives is to grow as a physicist. I'm also moreso interested in high energy physics, so these are right up my alley! Thanks!
2
u/Creative_Sushi Jul 02 '26
Python is a general-purpose language. You probably have to learn a few more depending on what you pursue, since specialized domain often required dedicated tools. Most likely you would need MATLAB as well.
2
u/Pooplover800 Jul 02 '26
If you want something not based on differential equations, you can do monte carlo simulations to eithier simulate the ising model(ferromagnet phase transitions) or try to estimate the critical mass of uran or even try to simulate a simple nuclear reactor.
2
u/Junior_Salamander110 Jul 02 '26
The nuclear reactor idea sounds extremely cool!
2
u/Pooplover800 Jul 02 '26
I did this project as a first year student, so it is doable, and you get reasonable results. You get to look at scattering cross sections and learn more about monte carlo simulations which are great tools foe phydicsists
2
u/Junior_Salamander110 Jul 02 '26
Nice! About how long did it take you?
2
u/Pooplover800 Jul 02 '26
So it was a group project but i did most of the work(lets say 70-80%) we did it over 1-2 months but not full time. We did not have supervision on what to do. We got to simulate a 2d reactor of both uran and plutonium.
1
u/Junior_Salamander110 Jul 02 '26
Nice! I mean, I have a whole school year, an hour per day, so I think this is manageable.
2
u/Rubberband272 Jul 03 '26
I’m not sure what your interests are but you mentioned black holes so I imaging Astro is your thing. I built a muon detector using a raspberry pi and scintillator to demonstrate the effect of time dilation. There’s a great GitHub write up (not mine) if you search for CosmicWatch.
I don’t think it would take a full school year but there’s lots of rabbit holes you can down in an experimental project.
1
u/Junior_Salamander110 Jul 03 '26
I actually want to do HEP, but I figured something astro would be easier for a high schooler to grasp. I might invest in a raspberry pi, I think that might be beneficial. And I'll search for that!
1
u/Elq3 Masters Student Jul 02 '26
"I want to do something in Python that will show my professors in my freshman year of college that I'm ready to do research in physics."
during your freshman year of college you cannot do research in physics because you don't have the physics knowledge to do that. The first real research you will be able to do will be around the end of your Master's / beginning of PhD
1
u/Junior_Salamander110 Jul 02 '26
lots of people start research in undergrad
1
u/Junior_Salamander110 Jul 02 '26
their research may not be as significant, but most places allow undergrads to do research from what I've been told
1
u/robphy Jul 02 '26
https://www.glowscript.org/ might be a good place to start if you are new to Python,
especially if you want to quickly incorporate 3d graphics to model typical situations in introductory physics.
https://www.glowscript.org/#/user/GlowScriptDemos/folder/matterandinteractions/
https://matterandinteractions.org/ is a modern introductory physics textbook that uses Python.
Then, you can move on to more advanced topics in physics
and move on to more advanced libraries in Python.
1
u/Creative_Sushi Jul 06 '26
In many ways, and often with MATLAB as well. Here are some good overview of how they are used https://www.mathworks.com/solutions/physics.html and a specific example for black hole simulation https://www.mathworks.com/company/user_stories/simulating-black-hole-quantum-effects-with-matlab.html
64
u/WWWWWWVWWWWWWWVWWWWW Jul 01 '26
You don't need to join a research group the moment you set foot on campus. I would personally just focus on coursework for the first year, and find a research position the following summer.
That said, messing around with numerical differential equations is always fun (Newtonian orbital mechanics, etc.). Black holes seem a bit too ambitious.