All courseware

PHYSICS-INFORMED NEURAL NETWORKS

Introduction to PINNsLearning from physical laws.

Use the one-dimensional Burgers equation to learn how neural networks incorporate physical laws, solve forward problems, and estimate unknown parameters from observations.

COURSE MATERIALS

Start with the examples.

Download the notebook, Python code, three pretrained models, and the data needed to explore their results.

Download course materials

ZIP · 4.0 MB · Python 3.12

QR code linking to this course page
Open this page on your phone
Save QR code

TWO EXAMPLES

Explore two ways to use PINNs.

01

Forward problem

Learn a solution from known equation parameters, using loss terms for the equation and its initial and boundary conditions.

02

Inverse problem

Use noisy synthetic observations to learn a solution and estimate the equation’s unknown parameters together.

GET STARTED

Run the examples on your computer.

Complete steps 1–3 once, then choose JupyterLab, PyCharm, or VS Code. These instructions cover Windows 10/11 on an Intel or AMD 64-bit PC, and Apple silicon Macs running macOS 14 or later. You will need an internet connection during installation. A CPU is sufficient for this course.

  1. Download and unzip

    Download the course ZIP above. On Windows, right-click it and choose Extract All; on Mac, double-click it. Open the extracted pinn-course folder containing PINN_lecture.ipynb and requirements.txt. Keep both Python scripts and the pinn_results folder alongside them.

    Run the files from this extracted folder. If you already tried a different Python version, use a fresh copy of the extracted folder for the steps below; keep any previous work separately.

  2. Install Python 3.12

    These steps use uv, a tool that downloads Python and creates a separate environment for the course. You can keep your existing Python installations. The course’s supplied package versions require Python 3.12 or newer; use 3.12 for the tested configuration.

    Windows: install Python 3.12
    1. On Windows 10 or 11, open the Start menu, search for PowerShell, and open it.
    2. Copy the following command, paste it into PowerShell, and press Enter. It downloads and runs the official uv installer.
      powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
    3. After installation finishes, close PowerShell and open it again. Run these commands, one line at a time:
      uv --version
      uv python install 3.12

    Wait for the Python installation to finish before continuing. If uv is not recognized, see Help with setup below.

    Mac: install Python 3.12

    First open Apple menu → About This Mac. These package versions need an Apple M-series chip and macOS 14 or later. If your Mac has an Intel processor or an older macOS, contact your instructor for a compatible environment before continuing; installing Python 3.12 alone will not resolve that package restriction.

    1. Press Command + Space, type Terminal, and press Return.
    2. Paste this command into Terminal and press Return. It downloads and runs the official uv installer.
      curl -LsSf https://astral.sh/uv/install.sh | sh
    3. When installation finishes, quit Terminal and open it again. Run these commands, one line at a time:
      uv --version
      uv python install 3.12

    Wait for the Python installation to finish before continuing. How uv installs Python

  3. Prepare the course environment

    The .venv folder will contain this course’s Python and packages. Run each command separately and wait for it to finish. If a command reports an error, resolve it before running the next one.

    Windows: create the environment and install packages

    In File Explorer, open the pinn-course folder that contains requirements.txt. Click the address bar, type powershell, and press Enter. In the new window, run:

    uv venv --python 3.12 .venv
    uv pip install --python .venv\Scripts\python.exe -r requirements.txt
    .\.venv\Scripts\python.exe --version
    Mac: create the environment and install packages

    Open Terminal. Type cd followed by a space, drag the extracted pinn-course folder from Finder into Terminal, and press Return. Run ls and confirm that requirements.txt appears, then run:

    uv venv --python 3.12 .venv
    uv pip install --python .venv/bin/python -r requirements.txt
    .venv/bin/python --version

    The final command should show Python 3.12.x. Installation may take several minutes. Keep this terminal window open for the next step.

  4. Choose where to open the notebook

    Choose one option below. The kernel is the Python process that runs your notebook; it must use the .venv you just prepared.

    JupyterLab in your browser — simplest starting point

    In the terminal from step 3, run the command for your computer.

    Windows / PowerShell

    .\.venv\Scripts\python.exe -m jupyterlab

    Mac / Terminal

    .venv/bin/python -m jupyterlab

    A browser window should open. If it does not, copy the local browser link printed in the terminal and open it in your browser. Keep the terminal running. In JupyterLab’s file list, double-click PINN_lecture.ipynb. If asked for a kernel, choose Python 3 (ipykernel), then continue to step 5.

    PyCharm: select the course interpreter and notebook kernel
    1. Use a current PyCharm release with notebook support. Choose Open and select the entire pinn-course folder.
    2. Open Settings and search for Python Interpreter. Choose Add Interpreter → Add Local Interpreter, then select an existing Python environment. Browse to the executable below and apply the setting.

    Windows: pinn-course\.venv\Scripts\python.exe
    Mac: pinn-course/.venv/bin/python

    On Mac, press Command + Shift + . in the file chooser if .venv is hidden.

    1. Open PINN_lecture.ipynb. In its toolbar, choose the local Managed Server / IDE-Managed Server for this project. If none exists, use Tools → Add Jupyter Connection to add one. Use the project’s .venv interpreter if prompted.
    2. If a kernel selector is shown, select the Python kernel for that environment. Restart an already running kernel after changing the interpreter, then perform the check in step 5.

    Labels vary slightly between PyCharm releases. Interpreter settings · Notebook connections

    VS Code: select the course notebook kernel
    1. Install VS Code. In its Extensions view, install Python and Jupyter, both published by Microsoft.
    2. Choose File → Open Folder and select pinn-course. Open PINN_lecture.ipynb.
    3. Click Select Kernel at the top right of the notebook. Choose Select Another Kernel → Python Environments if needed, then select the Python 3.12 environment inside this folder’s .venv.
    4. If it is missing, open the Command Palette with Ctrl + Shift + P on Windows or Command + Shift + P on Mac. Run Python: Select Interpreter, choose Enter interpreter path, and browse to the executable below. Return to the notebook’s Select Kernel menu and choose that same environment.

    Windows: pinn-course\.venv\Scripts\python.exe
    Mac: pinn-course/.venv/bin/python

    On Mac, Command + Shift + . reveals hidden folders in the file chooser. The editor’s interpreter and the notebook’s kernel can be different. Confirm the notebook selection with step 5. VS Code kernel instructions

  5. Check the kernel, then run the examples

    Add a code cell near the top of the notebook, paste the following, and run it with Shift + Enter:

    import sys
    print("Python:", sys.version.split()[0])
    print("Interpreter:", sys.executable)
    
    import torch
    import pinn_burgers
    print("PyTorch:", torch.__version__)
    print("CUDA available:", torch.cuda.is_available())

    Check that Python is 3.12.x and that the interpreter path points into this course folder’s .venv. If either is wrong, return to step 4 and choose the correct kernel. CUDA available: False is normal on a CPU-only computer or Mac; the examples will use the CPU.

    In the course’s setup cell, leave RETRAIN = False for your first run. Select Run All (or Run → Run All Cells) and wait for the cells to finish. The notebook loads the supplied models, saved metrics, and plots.

    Next time, reopen the same folder and use the same .venv. For JupyterLab, repeat only its launch command in step 4. You do not need to reinstall the packages each time.

Help with setup

“uv” is not recognized / command not found

First close and reopen your terminal after installing uv. If you are using an IDE terminal, restart the IDE too. If the error remains, use the full uv path in place of uv in the commands above:

Windows / PowerShell: & "$env:USERPROFILE\.local\bin\uv.exe"
Mac: "$HOME/.local/bin/uv"

For example, on Mac: "$HOME/.local/bin/uv" python install 3.12. If that file is missing, repeat the installer in step 2 and check that it finishes successfully.

Wrong Python version, or a dependency requires a newer Python

Repeat steps 2–3 in a freshly extracted course folder, then select its new .venv in your notebook. Preserve previous notebooks and training results in the old folder. Changing your terminal’s default Python does not change a running notebook kernel; restart it and repeat the check in step 5.

“No module named …” or a missing kernel

Check the interpreter path in step 5. Return to step 3 and rerun the package installation command for that same .venv. It installs the notebook kernel along with the course packages. Then reopen the notebook and select the environment again.

“requirements.txt” or “pinn_burgers” cannot be found

Open the extracted folder containing both requirements.txt and PINN_lecture.ipynb. If extraction created an outer folder, go inside it to find pinn-course. Start your terminal or open the IDE project there, and keep the scripts and pinn_results together.

The terminal shows “>>>” or installation stops with an error

>>> means you are inside Python. Type exit() and press Enter, then run the installation commands at the normal PowerShell or Terminal prompt. For a failed download, check your internet connection and retry the failed command. If it still fails, send your instructor the full error message and your operating system.