This repository implements a Physics-Informed Neural Network (PINN) to solve ordinary differential equations (ODEs) using automatic differentiation in PyTorch.
Unlike classical numerical solvers, PINNs embed the governing differential equation directly into the loss function, enabling the model to learn solutions that satisfy both data constraints and physical laws.
The current implementation focuses on a first-order ODE and serves as a minimal, extensible foundation for more advanced systems such as nonlinear ODEs and the Lane–Emden equation.
Run the PINN implementation directly in your browser:
The notebook demonstrates:
- End-to-end PINN training
- Automatic differentiation for ODE constraints
- Comparison with analytical solution
We consider the initial value problem (IVP):
This problem admits a unique classical solution due to the smoothness of the right-hand side.
The analytical solution is:
The objective is to train a neural network ( u_\theta(t) ) that satisfies the differential equation and initial condition without explicitly using solution data.
Derivatives d(u_theta(t))/dt are computed using PyTorch’s automatic differentiation (torch.autograd), enabling exact differentiation of the neural network output with respect to its input.
A fully-connected neural network is used:
- Input: t ∈ R
- Hidden layers: 3 layers × 50 neurons
- Activation: Tanh
- Output: u(t)
This architecture is well-suited for smooth function approximation and is commonly used in PINN literature.
PINN-First-Order-ODE/
│
├── src/
│ ├── model.py # Neural network definition
│ ├── loss.py # Physics-informed loss
│ ├── train.py # Training loop
│ ├── utils.py # Plotting and evaluation
│
├── outputs/
│ ├── plots/ # Loss curves and predictions
│ ├── models/ # Saved model checkpoints
│
├── experiments/
│ └── ode_system1/ # Experiment configs and results
│
├── main.py
├── requirements.txt
└── README.md
The trained PINN successfully recovers the analytical solution over the domain t ∈ [0, 2].
- Accurate function approximation across the domain
- Stable convergence of both physics and initial condition losses
- Log-scale loss curves demonstrate consistent optimization behavior
Example outputs include:
- Training loss decomposition (physics vs IC)
- Predicted vs analytical solution plots
git clone https://github.com/saoneenandi/PINN-First-Order-ODE.git
cd PINN-First-Order-ODE
pip install -r requirements.txtpython main.pyOutputs will be saved in the outputs/ directory.
- Autograd-based derivative computation
- Physics-constrained training
- Modular and extensible code structure
- Reproducible experiments
- Clean separation of components
- Only first-order ODEs
- No adaptive loss weighting
- Uniform sampling
- Nonlinear and higher-order ODEs
- Lane–Emden equation
- Singularity handling
- Eigenvalue problems
- Advanced architectures (SIREN, Fourier features)
Raissi, M., Perdikaris, P., & Karniadakis, G. E. (2019).
Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations.
Journal of Computational Physics.
This project was developed as part of an exploration into Scientific Machine Learning, focusing on integrating deep learning with differential equation modeling for physics-driven systems.