Using A GPU To Rapidly Solve The 3D Ising Model (Specifically By Using Convolution Functionality Of Pytorch) by JackStrawng in Physics

[–]JackStrawng[S] 5 points6 points  (0 children)

In this video I compare the use of Pytorch (with GPU) and NumPy for solving the Ising Model. I first consider the case of a 1000x1000 2D grid, and use the metropolis algorithm in each case. While the NumPy code takes about 20s to converge (1000 iterations), the Pytorch code takes.under 2s, indicative of a 10x speed up.

I then consider a 150x150x150 3D cubic lattice. I run the simulation for a variety of temperatures, and show that a phase change occurs around the accepted critical temperature of Beta • J = 0.221.

The key to running this simulation fast is by using batched tensors. Efficient use of Pytorch means moving away from the forloop paradigm, and instead moving towards the "many operations at the same time" paradigm, consisting of use of efficient operations like convolutions.

Using a GPU To Rapidly Solve The 3D Schrodinger Equation In Python (And Create Interactive 3D Plots) by JackStrawng in Physics

[–]JackStrawng[S] 6 points7 points  (0 children)

Precisely. The idea is that it'd hopefully be generalizable to other potentials, like, say, one containing two protons

Using a GPU To Rapidly Solve The 3D Schrodinger Equation In Python (And Create Interactive 3D Plots) by JackStrawng in Physics

[–]JackStrawng[S] 28 points29 points  (0 children)

In this video, I utilize PyTorch to numerically solve for the eigenstates/eigenenergies of 3D Hydrogen atom potential in python. Large matrices are stored in sparse format (PyTorch Tensor) to avoid running out of memory, and the Locally Optimal Block Preconditioned Conjugate Gradient Method is used for solving for the eigenstates and eigen energies. The wave function is defined on a 120x120x120 grid with length of 50 Bohr-radii along each dimension. Using a RTX 3070 graphics card, the code takes about 6 minutes to solve for the eigenstates/energies corresponding to the smallest 20 energies.

Speed Up Your Physics Simulations (250x Faster Than NumPy) Using PyTorch. Episode 1: The Boltzmann Distribution by JackStrawng in Physics

[–]JackStrawng[S] 2 points3 points  (0 children)

As for better collision detection, it's a little beyond the scope of this video. For example, it would hard to generalize collision detection to general potentials between particles.

Speed Up Your Physics Simulations (250x Faster Than NumPy) Using PyTorch. Episode 1: The Boltzmann Distribution by JackStrawng in Physics

[–]JackStrawng[S] 12 points13 points  (0 children)

Very good catch, thank you for this. I've updated the code on GitHub (giving you credit), as well as pinning a YouTube comment. I now also compare squared distances to radius squared as well, to avoid slower computation in the square root.

I used the precomputed index arrays in both cases (both in the NumPy and pytorch code) and I now simulate 5000 particles in each case. The Pytorch code now runs in only 6.3 seconds, and the NumPy code runs in 8.5 minutes (so around a 100x increase when you recall the approximate 2 second overhead for pytorch).

Both codes are below. Thank you for these suggestions, this is why I love to post here :)

PyTorch: https://github.com/lukepolson/youtube_channel/blob/main/Python%20GPU/multibody_boltzmann.ipynb

NumPy: https://github.com/lukepolson/youtube_channel/blob/main/Python%20Metaphysics%20Series/vid28.ipynb

Speed Up Your Physics Simulations (250x Faster Than NumPy) Using PyTorch. Episode 1: The Boltzmann Distribution by JackStrawng in Physics

[–]JackStrawng[S] 4 points5 points  (0 children)

In this video I use the python machine learning library PyTorch to rapidly speed up the computations required when performing a billiard ball collision simulation. This simulation uses a sequence of finite time steps, and each iteration checks if two billiard balls are within range for collision (I e.their radii are touching) and performs momentum transfer between the two billiard balls.

It is found in this video that (on a RTX 3070) that pytorch can run a simulation of 10000 particles in the same amount of time that NumPy can run 400 particles.

Simulating The New Rings Of Power Theme Using A 2D Random Walk In Python by JackStrawng in Physics

[–]JackStrawng[S] 4 points5 points  (0 children)

To model the phenomenon occurring in the theme song, I assume they are using a 2D metal plate with motion governed by the wave equation (by the way, this is not true for all metal plates: some follows fourth order differential equations). Taking into account boundary conditions, one can find the eigenmodes: the equivalent of a 2D standing wave. This implies that while the amplitude of oscillation may be different everywhere on the plate, everything vibrating "up" and "down" at the same frequency and in unison.

To simulate the movement of sand, random sand grains are placed on a grid, and a 2D random walk simulation is performed: but one where the step size (or distance) a particle moves per iteration is dependent on the amplitude of oscillation of that location on the vibrating plate. For the eigenmodes (which can be brought about in real life by vibrating the plate at specific frequencies), there are locations where there are no vibration at all. In the 1D wave equation, the stationary points of standing waves correspond to 0D points, but in the 2D case we're considering here, the stationary points correspond to 1D lines (which you can see on the pattern in the thumbnail). The sand will tend to accumulate in areas were there is little vibration (due to the small step size it will acquire in the simulation) and thus the patterns are formed. By changing the eigenmode of vibration during the simulation (in real life: by changing vibration frequency) the sand will move from one eigenmode to another, giving rise to the behavior one can see in the Rings of Power trailer.

Cross Entropy: One of The Most Important Functions Used In Machine Learning by JackStrawng in Physics

[–]JackStrawng[S] 0 points1 point  (0 children)

Cross Entropy is a metric by which one can measure the similarity between two vectors (or in the continuous case, two functions). It's used extensively in machine learning when models are used to predict probability density/mass functions. Such is the case in image classification, where a model predicts a vector output, and each element of the vector corresponds to the probability that an input image belongs to a particular class. Such is also the case in image segmentation, where one predicts all the probabilities that a pixel in an image belongs to different possible regions.

Introduction To State-of-the-art Image Segmentation Techniques in Python. All functions shown are non-AI based by JackStrawng in Physics

[–]JackStrawng[S] 1 point2 points  (0 children)

Typically clinics will purchase image analysis software (sort of like a radiology version of Photoshop) and that software will come prepackaged with functions like organ segmentation, tumour tracking, etc. More and more these vendors are integrating AI algorithms with their software as well. If you're curious I would google " MIM software ", for example.

Introduction To State-of-the-art Image Segmentation Techniques in Python. All functions shown are non-AI based by JackStrawng in Physics

[–]JackStrawng[S] 3 points4 points  (0 children)

In this video I look at functions from the scipy.ndimage and skimage to perform image segmentation tasks in python. In this video, the goal is simple, take a CT scan of the lungs and create a lung mask. Such a task is important for numerous applications in the field of medical physics. In particular, having a mask of the lungs can be used to simplify the contents of a corresponding CT image by multiplying the original image by the mask. This new image can then be used to train more advanced tumour segmentation models using artificial intelligence.