r/Python • u/--CreativeUsername • Jul 27 '19
Simulating Quantum Mechanics Using Matplotlib and Tkinter
https://gfycat.com/wellgroomedunsteadyballoonfish179
u/towinu Jul 28 '19
Can you please explain what the fuck I’m looking at? I know a very small amount about the subject.
97
Jul 28 '19
it is a really good simulation of the time dependent schroedinger's equation.
ignore Re(\psi) and Im(\psi), those aren't physically meaningful anyway and could (should) be omitted from the simulation since all it does is confuse.
the quantity psi is the wavefunction that represents where a particle "is" in space and time, though "is" is kinda tricky since its probablistic. its somewhere in there.
that also includes the potential barrier. the simulation accurately models quantum tunneling through a potential barrier.
2
Jul 28 '19
Can you explain like I’m 5?
3
u/deadwisdom greenlet revolution Jul 28 '19
The graph is telling you where the particle might be, but no one knows exactly where. Modelling the might-be's is basically quantum mechanics.
1
u/aquic Jul 31 '19
The tunneling through the potential barrier is great! I think is a neat tool to experiment with while teaching QM!
Good job!
0
Jul 28 '19
[deleted]
25
Jul 28 '19
possibly.
if you integrate |\psi|2 over x=-\infty to x=\infty, you get "1".
this means that the particle exists somewhere but only once. you can guess where it is most probable by the maximum of the function but that's no guarantee.
0
Jul 28 '19
[deleted]
24
u/Serialk Jul 28 '19
I don't think that's a correct way to put it, it's not everywhere, it's just fundamentally described by a probability distribution.
5
2
Jul 28 '19
yeah.
measurement has its own time/energy position/momenta uncertainty. its a conjugate variable thing.
1
5
u/Globbi Jul 28 '19
That's not something which can clearly be answered. There are a few approaches on what it means and no agreement among physicists.
All we have are those equations that work well and that's what is being simulated.
5
u/rajbabu0663 Jul 28 '19
This is a good start if you are curious: https://en.m.wikipedia.org/wiki/Finite_potential_well.
5
u/HelperBot_ Jul 28 '19
Desktop link: https://en.wikipedia.org/wiki/Finite_potential_well
/r/HelperBot_ Downvote to remove. Counter: 271002. Found a ^^bug?
3
u/WikiTextBot Jul 28 '19
Finite potential well
The finite potential well (also known as the finite square well) is a concept from quantum mechanics. It is an extension of the infinite potential well, in which a particle is confined to a box, but one which has finite potential walls. Unlike the infinite potential well, there is a probability associated with the particle being found outside the box. The quantum mechanical interpretation is unlike the classical interpretation, where if the total energy of the particle is less than the potential energy barrier of the walls it cannot be found outside the box.
[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information | ^Source ] Downvote to remove | v0.28
23
u/Weihua99 Jul 28 '19
This is absolutely incredible -- I've seen QM simulations like this before in Python but the interactivity you've added really takes it to another level. I love it!
10
21
u/Rouge_Dragon Jul 28 '19
The level of interactivity you have made is quite something. I'm quite surprised by matplotlibs ability to update the plot so quickly, I thought people usually used other opengl kind of things for continuously updating plots and stuff.
4
Jul 28 '19
I wondered the same thing. I've avoided interactive animations with matplotlib for this reason and used bokeh instead, which was a semi-good idea :)
1
u/some_boi_569348 Jul 29 '19
Ipywidgets & the jupyter/matplotlib back-end in ipython notebooks makes animated plots much easier than it used to be!!
I'm still struggling to find a simple solution to dealing with plotting millions of points....
35
u/drunkpolishbear Jul 28 '19 edited Nov 20 '24
Comment has been redacted using PowerDeleteSuite.
10
u/st_malachy Jul 28 '19
I have no idea what’s happening in this graphic, but I hope you’re right and he works for me at least once.
3
u/drunkpolishbear Jul 28 '19 edited Nov 20 '24
Comment has been redacted using PowerDeleteSuite.
5
Jul 28 '19
open the repo and start figuring it out.
you'll see a fair bit of numerical analysis since he's solving a time dependent differential equation. but the ways of solving them are well discussed in the relevant circles.
7
u/jdkwak Jul 28 '19 edited Jul 28 '19
Numerical solutions to differential equations have been around for quite some time.
The impressive thing here is that he learned something very complicated both mathematically and conceptually, and then also had the ability to learn the numerical simulations in order to create an interactive way (GUI!) of visualizing and exploring the mathematics and the physics of it!
The point is: He didn't invent anything new, but he managed to combine all the knowledge and skills of different complicated fields into something really nice, usable and user friendly.
He'll go far I'm sure!
7
u/m3wolf Jul 28 '19
I could watch this for days. Very nicely done.
Out of curiosity, why is there no tunneling when the wave packet reaches that first barrier and reflects? I see tunneling later on after you've really messed up the potential, but not at first.
2
Jul 28 '19
Out of curiosity, why is there no tunneling when the wave packet reaches that first barrier and reflects?
tunneling at any nontrivial probability requires a big shove. its really low probability.
6
5
u/Suspicious_Writer Jul 28 '19
Dat tunneling at 00:30!
1
u/kidpixo Jul 28 '19
That's how a Field-effect_transistor (FET) works! Nice!
1
u/WikiTextBot Jul 28 '19
Field-effect transistor
The field-effect transistor (FET) is an electronic device which uses an electric field to control the flow of current. FETs are devices with three terminals: source, gate, and drain. FETs control the flow of current by the application of a voltage to the gate, which in turn alters the conductivity between the drain and source.
FETs are also known as unipolar transistors since they involve single-carrier-type operation.
[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information | ^Source ] Downvote to remove | v0.28
4
1
u/mrasadnoman Jul 28 '19
Computer scientist here. 👌 Looked at some basic quantum mechanics stuff a year ago. But dont really know what this simulation is representing.
Could you just explain it in a sentence.
2
u/--CreativeUsername Jul 28 '19
The wavefunction of the particle gets reflected and transmitted through potential barriers and wells.
1
u/roseinabox28 Jul 28 '19
Is there a tutorial or git hub for this?
1
u/--CreativeUsername Jul 28 '19
In the readme file I linked to the exercises given in Computational Physics by Mark Newman, which you can download for free. Exercise 9.8 and 9.9 gives a detailed explanation on how to numerically solve the Schrodinger equation in a finite 1D region when there is no potential involved.
As for how to integrate a matplotlib animation with tkinter and add interactivity, I may put a gist out or something like that in the future.
1
u/JanDerion47 flair=None Jul 28 '19
Where can one learn the math to comprehend this?
2
u/--CreativeUsername Jul 28 '19
The usual prerequisites for QM are multivariable calculus, linear algebra and ODEs. You can find these courses in MIT OCW.
1
6
Jul 28 '19
holy shit. you even accurately simulated the tunneling aspect.
1
u/_requires_assistance Jul 28 '19
It doesn't require any special handling, as long as the pde is solved properly.
3
3
u/faintingoat Jul 28 '19 edited Jul 28 '19
the possibility to create and change potential walls in real time is stunning. congrats! where s the script, please?
2
u/IdleRocket Jul 28 '19
You know that scene in Good Will Hunting where Matt Damon draws some lines and circles on a chalkboard and we’re supposed to understand that it’s math.
Yeah, this gives me that same feeling.
1
1
1
1
1
1
1
1
49
u/--CreativeUsername Jul 27 '19 edited Jul 28 '19
And also with numpy, sympy, and optionally numba. Github Repository:
https://github.com/marl0ny/1D-Quantum-Mechanics-Applet.
The code itself is a little messy, and I certainly haven't ironed out all bugs and quirks. Note that this uses numba, if you have it. In my experience numba either slows things down or speeds things up, depending on the computer and environment used. The notebook
Performance_Test.ipynbchecks to see if Numba improves things.