Predicting Physics With ML
Introduction
Today I’ll be discussing the unique intersection of physics and artificial intelligence, specifically through the lens of Physics Informed Neural Networks (PINN). In this article, we’ll be tackling how to construct a PINN that is tailored to learn the Burgers’ Equation, a significant equation in fluid mechanics. We’ll kick-off by understanding what exactly the Burgers’ Equation is and why it’s important. Next, we’ll unpack the concept of boundary conditions – the rules governing the behavior of a system on its edges. Once we have our basics covered, we’ll dive into the workings of a PINNs. Finally, we’ll be using PyTorch, my preferred ML framework, to tie all these elements together and create our PINN.
Burgers’ Equation
Burgers’ equation is a fundamental equation in fluid dynamics, however, you often see it in other fields such as gas dynamics, traffic flow, and even acoustics. It’s kind of like the “Swiss Army Knife” of mathematical equations due to its simplicity yet wide range of applications to real-life problems.
Imagine you’re at a sports game and everyone does “the wave.” People stand up and sit down in a sequence, creating this visual “wave” that moves around the stadium. Now, let’s say there’s a section of really enthusiastic fans who do a giant leap instead of just standing up. That will create a sort of “bump” in the wave, right? This change then travels around the stadium as a part of the wave. The Burgers’ equation is used to describe and predict how these “bumps,” or disturbances, move and change over time in the wave.
Here’s another relatable example – traffic flow. Suppose there’s been an accident in one lane of a highway that slows down the traffic. Burgers’ equation can be used here as well for predicting the speed and spread of the resulting traffic jam.
Burgers’ equation is a simple yet powerful tool that helps us mathematically describe and predict the behavior of systems that experience such disturbances and let us track how these disturbances propagate over time. This equation helps us simulate the effects a disturbance has on a continuous flow, whether it be fans in a stadium, cars on a highway, or particles in a fluid.
In the world of physics, a “boundary condition” is a rule or a set of rules stating the behavior of a physical system at the edges, or boundaries, of its area of study.
You can imagine a boundary condition as the actual physical constraints that a system has to operate within. It determines how a physical quantity behaves at the boundary of a system or physical problem and establishes the state of a system at a given time and place.
For example, suppose you have a rope tied at both ends and you’re studying the kinds of waves it can support. One boundary condition in this case would be that the vertical displacement of the rope is always zero at the tied ends, because the tied ends are not free to move. This boundary condition will influence the exact forms of waves that can occur and their frequency.
In another example, imagine you are studying heat flow in a metal rod, and you keep one end in ice (keeping it at 0 degrees Celsius) and the other end in boiling water (at 100 degrees Celsius). The temperatures at both ends are constant and they are the boundary conditions for this system which will influence how the temperature distributes across the rod.
In essence, boundary conditions are critical in physics problems because they often determine the unique solution to the scenario or problem
What’s A Boundary Condition?
In the world of physics, a “boundary condition” is a rule or a set of rules stating the behavior of a physical system at the edges, or boundaries, of its area of study.
You can imagine a boundary condition as the actual physical constraints that a system has to operate within. It determines how a physical quantity behaves at the boundary of a system or physical problem and establishes the state of a system at a given time and place.
For example, suppose you have a rope tied at both ends and you’re studying the kinds of waves it can support. One boundary condition in this case would be that the vertical displacement of the rope is always zero at the tied ends, because the tied ends are not free to move. This boundary condition will influence the exact forms of waves that can occur and their frequency.
In another example, imagine you are studying heat flow in a metal rod, and you keep one end in ice (keeping it at 0 degrees Celsius) and the other end in boiling water (at 100 degrees Celsius). The temperatures at both ends are constant and they are the boundary conditions for this system which will influence how the temperature distributes across the rod.
In essence, boundary conditions are critical in physics problems because they often determine the unique solution to the scenario or problem
Pytorch
PyTorch is an open-source machine learning library for Python that’s used for applications like natural language processing, computer vision, and artificial intelligence. It was primarily developed by Facebook’s artificial-intelligence research group and has gained a lot of popularity in the data science community.
One of the neat features about PyTorch is its ease of use. It’s got a pretty simple interface which means you get to spend less time figuring out how to code what you want and more time actually coding it. It’s like that trusty tool in your toolbox that just makes life easier.
PyTorch also offers a major advantage in its seamless transition between CPUs and GPUs. This means, if you’ve got some heavy-duty number-crunching to do or big neural networks to train, you can use a powerful GPU to get things done more quickly. Then, when you’re just experimenting or doing less intensive work, you can switch back to your regular CPU. This kind-of flexibility can be a real game-changer.
What makes PyTorch stand out from the crowd is its dynamic computation graphing feature. In plain English, this means you can alter and play around with your model as it’s running, rather than having to define the whole thing up front and then leave it be, which is the case with many other libraries. This dynamic nature allows for more flexibility and makes it easier to debug and tweak your models on the fly.
Interestingly, PyTorch is also really good for research work. It allows researchers to design complex architectures with ease, thanks to its intuitive pythonic nature and dynamic graphing feature. This is likely the reason why it is so heavily adopted by researchers in both academia and industry.
But it’s not all just about its capabilities. A cool thing about PyTorch is the community behind it. Because it’s open-source, people all over the world contribute to it, adding new features and tools, finding and fixing bugs. So, when in doubt or need some help, you got a global community to back you up.
And, lastly, PyTorch is also pretty robust when it comes to deploying models. Its ONNX (Open Neural Network Exchange) support means that you can easily export your models to other platforms like Caffe2 or Microsoft Cognitive Toolkit.
The Code
Alright, enough talk. Let’s start building this thing. First off, all of the code for this article can be found in my PINNacle repository. Feel free to borrow any of the code you find there.