Physics-Informed Machine Learning
Learning outcomes
- Write the physics-informed loss with a data term and a residual term evaluated at collocation points.
- Compare three ways to combine physics and data, fitted physical parameters, a learned residual, and a physics-constrained network.
- Fit the TCLab energy balance to measured data and identify which parameters the data determine.
Book chapter: Process Dynamics, Modeling, and Identification (Volume 1), Chapter 11, Model Structure Selection and Identifiability on a Temperature Control Lab (PDF).
Practice in 15 minutes: 3 · Fit an Energy Balance to Data, 29 · Virtual Metrology and Run-to-Run Control
Model: Combined, a physics-based structure with learned parts, from fitted parameters to a network trained against the governing equation.
Decision: Training chooses the parameters or weights; the combined model then serves an estimator or MPC the same way a physics model does.
Learning: Learning fills the part the physics does not know, and the physics limits what the learned part can do outside the data.
Physics-Informed Machine Learning (PIML) is an emerging paradigm that integrates scientific domain knowledge (physical laws, constraints, or models) into machine learning workflows. In engineering systems—especially dynamic systems governed by differential equations—purely data-driven models often struggle with generalization and physical consistency. PIML addresses these challenges by blending first-principles physics with data-driven learning, thereby reducing required data, improving extrapolation, and ensuring that model outputs obey known physical rules. This survey outlines key methods to inject physics into ML models, presents code examples for simple dynamic systems (e.g. damped oscillators, reactors, thermal systems), and reviews both foundational and recent literature. Optimization applications, such as model predictive control (MPC), are emphasized alongside forward simulation.
I. Methods of Injecting Physics into ML Models
PIML techniques can be broadly categorized into several approaches which, when combined appropriately, yield models that are both accurate and interpretable.
A. Physics-Based Feature Engineering
Feature engineering uses physical insights—such as conservation laws, symmetry, and nondimensional numbers—to construct input features that better capture underlying dynamics.
For example, consider a pendulum where the true acceleration depends on sin(θ) rather than θ itself. Using sin(θ) as a feature allows even a linear regression model to capture the nonlinear dependence of acceleration on the angle.
from sklearn.linear_model import LinearRegression
# Generate synthetic data for a pendulum
g, L = 9.81, 1.0
theta = np.linspace(-np.pi, np.pi, 100).reshape(-1, 1) # angles from -π to π
acc_true = -(g/L) * np.sin(theta) # true angular acceleration
# Model 1: Linear regression on raw angle (theta)
model_raw = LinearRegression().fit(theta, acc_true)
pred_raw = model_raw.predict(theta)
# Model 2: Linear regression on sin(theta) as feature
X_feat = np.sin(theta) # physics-inspired feature
model_feat = LinearRegression().fit(X_feat, acc_true)
pred_feat = model_feat.predict(X_feat)
# Evaluate at a sample angle
test_angle = np.array([[50 * np.pi / 180]]) # 50 degrees in radians
print("True acceleration:", -(g/L) * np.sin(test_angle))
print("Linear model (raw theta) prediction:", model_raw.predict(test_angle))
print("Linear model (sin(theta)) prediction:", model_feat.predict(np.sin(test_angle)))
B. Custom Neural Network Architectures with Physical Structure
Neural network architectures can be designed so that they inherently respect physical laws. Examples include Hamiltonian Neural Networks (HNNs) and Lagrangian Neural Networks. These models embed conservation laws into their topology, such that—for instance—a Hamiltonian network is constructed so that dq/dt = ∂H/∂p dp/dt = –∂H/∂q are satisfied automatically.
# Define a simple HNN model: input (q, p) -> output H (the system energy)
class HNN(torch.nn.Module):
def __init__(self, hidden_dim=32):
super().__init__()
self.net = torch.nn.Sequential(
torch.nn.Linear(2, hidden_dim),
torch.nn.Tanh(),
torch.nn.Linear(hidden_dim, 1) # output: scalar H
)
def forward(self, q, p):
# Stack q and p to form the input vector and return H(q, p)
return self.net(torch.stack([q, p], dim=-1)).squeeze(-1)
hnn = HNN(hidden_dim=16)
optimizer = torch.optim.Adam(hnn.parameters(), lr=0.01)
# Synthetic data: small oscillations of a mass-spring system (q: position, p: momentum)
t = torch.linspace(0, 10, steps=101)
q_data = torch.cos(t)
p_data = -torch.sin(t)
dq_data = torch.gradient(q_data, spacing=(t,))[0] # true dq/dt = p for m=1
dp_data = torch.gradient(p_data, spacing=(t,))[0] # true dp/dt = -q for k=1
# Training loop to enforce Hamilton's equations as loss
for epoch in range(1000):
idx = torch.randint(0, len(t), (32,))
q, p = q_data[idx], p_data[idx]
H = hnn(q, p)
# Compute gradients of H with respect to p and q via autograd
dH_dp = torch.autograd.grad(H, p, grad_outputs=torch.ones_like(H),
retain_graph=True, create_graph=True)[0]
dH_dq = torch.autograd.grad(H, q, grad_outputs=torch.ones_like(H),
retain_graph=True, create_graph=True)[0]
dq_pred = dH_dp # predicted dq/dt
dp_pred = -dH_dq # predicted dp/dt
dq_true = dq_data[idx]
dp_true = dp_data[idx]
loss = torch.mean((dq_pred - dq_true)**2 + (dp_pred - dp_true)**2)
optimizer.zero_grad()
loss.backward()
optimizer.step()
q_test, p_test = 1.0, 0.0
H_pred = hnn(torch.tensor(q_test), torch.tensor(p_test)).item()
print("Learned Hamiltonian at (q=1, p=0):", H_pred)
print("True Hamiltonian at (q=1, p=0):", 0.5 * q_test**2 + 0.5 * p_test**2)
C. Physics-Based Constraints in the Loss Function (Soft Constraints)
Physics-Informed Neural Networks (PINNs) integrate the governing equations directly into the loss function as penalty terms. The loss penalizes the residual of the underlying PDE or ODE, so that the neural network learns a solution that satisfies both the data and the physics.
For a network `\hat x_\theta(t)` that approximates the solution of `dx/dt = f(x, u, p)`, the loss adds the mean squared data error at the `n_d` measurement times `t_i` and the mean squared equation residual at `n_c` collocation points `t_j`, which need not coincide with the data:
$$\begin{gathered} L(\theta) = \underbrace{\frac{1}{n_d} \sum_{i=1}^{n_d} \left\| \hat x_\theta(t_i) - y_i \right\|^2}_{L_{\text{data}}} \\ \; + \; \lambda\, \underbrace{\frac{1}{n_c} \sum_{j=1}^{n_c} \left\| \frac{d\hat x_\theta}{dt}(t_j) - f\big(\hat x_\theta(t_j), u(t_j), p\big) \right\|^2}_{L_{\text{physics}}} \end{gathered}$$
The time derivative of the network comes from automatic differentiation. The weight `\lambda` trades fit to data against fit to the equation; a term for the initial condition is often added. If `p` is unknown, it is trained along with `\theta`.
# Known parameters for a damped oscillator: m*ddx + c*dx + k*x = 0, with m=1, k=1, c=0.1
c, k = 0.1, 1.0
# Neural network representing x(t)
model = torch.nn.Sequential(
torch.nn.Linear(1, 20),
torch.nn.Tanh(),
torch.nn.Linear(20, 1)
)
# Collocation points in time domain
t_colloc = torch.linspace(0, 10, steps=100, requires_grad=True).reshape(-1, 1)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01)
for epoch in range(1000):
x_pred = model(t_colloc)
# Compute first and second derivatives with respect to time
dx_pred = torch.autograd.grad(x_pred, t_colloc, grad_outputs=torch.ones_like(x_pred),
retain_graph=True, create_graph=True)[0]
ddx_pred = torch.autograd.grad(dx_pred, t_colloc, grad_outputs=torch.ones_like(dx_pred),
retain_graph=True, create_graph=True)[0]
# Compute ODE residual: ddx + c*dx + k*x should be zero
ode_residual = ddx_pred + c * dx_pred + k * x_pred
phys_loss = torch.mean(ode_residual**2)
# Enforce initial conditions: x(0) = 1, dx(0) = 0
x0_pred = model(torch.zeros(1, 1))
dx0_pred = torch.autograd.grad(x0_pred, torch.zeros(1, 1),
grad_outputs=torch.ones(1, 1), create_graph=True)[0]
ic_loss = (x0_pred - 1.0)**2 + (dx0_pred - 0.0)**2
loss = phys_loss + 100 * ic_loss
optimizer.zero_grad()
loss.backward()
optimizer.step()
D. Hybrid Modeling with Differential Equations or Simulators
Hybrid modeling—also known as gray-box modeling—combines known physics with data-driven ML components. This can take the form of serial, parallel, or component-replacement strategies.
For instance, one can replace an unknown reaction rate term in a chemical process model with a neural network learned from data, and then embed this hybrid model into an ODE solver.
from sklearn.neural_network import MLPRegressor
from gekko import GEKKO, ML
# Create training data for the unknown physics f_true(x) = -0.2*x^2
X = np.linspace(0, 2, 21).reshape(-1, 1)
y = -0.2 * X.ravel()**2
mlp = MLPRegressor(hidden_layer_sizes=(5,), activation='tanh', max_iter=5000).fit(X, y)
# Set up GEKKO model and import the trained MLP
m = GEKKO(remote=False)
m.time = np.linspace(0, 5, 101) # simulate 5 seconds
x = m.Var(value=1.0)
# Create scaling for GEKKO's ML interface (custom scaler with min/max values)
data = np.concatenate([X, y.reshape(-1, 1)], axis=1)
# Assume the scaler is defined with known min/max (details omitted for brevity)
scaler = ML.CustomMinMaxGekkoScaler(data, features=[0], label=[1])
mma = scaler.minMaxValues()
ml_model = ML.Gekko_NN_SKlearn(mlp, mma, m)
f = ml_model.predict([x])
# Define the hybrid ODE: dx/dt = -0.5*x + f(x)
m.Equation(x.dt() == -0.5 * x + f)
m.options.IMODE = 4 # dynamic simulation mode
m.solve(disp=False)
print("Hybrid model final x:", x.value[-1])
E. Data Assimilation and Regularization with Physical Priors
Data assimilation techniques—such as Kalman filters or Moving Horizon Estimation (MHE)—continuously update the model state or parameters by blending model predictions with measurements. Regularization with physical priors (e.g., smoothness, monotonicity) further guides the learning towards physically plausible solutions.
import numpy as np
# True system: dx/dt = -k_true * x, with k_true = 0.4
k_true = 0.4
t_points = np.linspace(0, 5, 51)
x_true = np.exp(-k_true * t_points)
x_meas = x_true[-1] # measurement at t=5
# GEKKO model for parameter estimation (MHE)
m = GEKKO(remote=False)
m.time = np.linspace(0, 5, 51)
k = m.FV(value=1.0, lb=0, ub=2)
k.STATUS = 1 # allow optimization to adjust k
x = m.Var(value=1.0)
m.Equation(x.dt() == -k * x)
# Define controlled variable for measurements
y = m.CV(value=np.nan * np.ones(len(m.time)))
y.FSTATUS = 0
y.MEAS = np.nan * np.ones(len(m.time))
y.FSTATUS[-1] = 1 # provide measurement feedback at final time
y.MEAS[-1] = x_meas
m.Equation(y == x)
m.options.IMODE = 5 # MHE mode
m.options.EV_TYPE = 1 # L2 norm in objective
m.solve(disp=False)
print("Estimated k:", k.value[0])
print("Predicted x(5):", x.value[-1], "Measured x(5):", x_meas)
Three Ways to Combine Physics and Data
In the course's notation, with states `x`, inputs `u` and parameters `p`:
- Physics structure with fitted parameters (gray-box estimation): `dx/dt = f(x, u, p)` with `p` fitted to data.
- Physics plus a learned residual: `dx/dt = f(x, u, p) + N_\theta(x, u)`, where the network `N_\theta` learns only what the physics misses.
- A network constrained by physics: `\hat x_\theta(t)` trained with the loss above.
The heater energy balance, one of the models in the tclab-sim app, is the plain case of the first. With heater power `Q`, ambient temperature `T_a`, heat transfer coefficient `U`, area `A`, emissivity `\epsilon`, the Stefan-Boltzmann constant `\sigma` and heater factor `\alpha`, the energy balance in kelvin is
$$m\, c_p\, \frac{dT}{dt} = U A \left(T_a - T\right) + \epsilon\, \sigma A \left(T_a^4 - T^4\right) + \alpha\, Q$$
Fitting `U` and `\alpha` to a step test takes seconds and extrapolates to other heater levels because the structure is right. The second way adds a small network for what the balance misses, such as heat exchange with the second heater or the sensor lag. The third way is the most flexible and the hardest to train; it pays off when the equation is known but data are sparse.
Data from an app. Every app in apmonitor.com/apps exports its run as CSV with Export CSV. For this page, use tclab-sim: run a heater step sequence, export the run, fit `U` and `\alpha` with GEKKO, and then train a residual network on what the fitted balance leaves.
II. Comparison of PIML Techniques
| Approach | Strengths | Limitations |
| Feature Engineering | Simple to implement; leverages domain insight; improves interpretability | Requires accurate a priori identification of key physical features; may not capture complex dynamics fully |
| Custom Neural Architectures | Guarantees adherence to physical laws (e.g. conservation) by design; yields physically interpretable representations | Requires specialized knowledge for design; less flexible if system deviates from assumed physics |
| Physics-Based Loss (PINNs) | General and flexible; learns solutions that satisfy PDE/ODE constraints even with limited data; naturally addresses inverse problems | Training can be slow and challenging; balancing physics and data loss requires careful tuning |
| Hybrid Modeling | Combines the strengths of first-principles and ML; improved accuracy with limited data; high interpretability of known physics components | Integration can be complex; interfacing ML with simulators requires careful scaling and calibration |
| Data Assimilation & Regularization | Adaptive correction with real-time data; enhances robustness; gently guides the solution towards physical plausibility | Additional computational overhead; tuning of assimilation parameters is often problem-dependent |
III. Conclusion
Physics-informed machine learning represents a significant advancement in bridging the gap between black-box AI and traditional engineering practices. By embedding physical laws into the ML modeling process—whether through feature engineering, custom neural architectures, physics-based loss functions, hybrid modeling, or data assimilation—engineers obtain models that are more data-efficient, generalizable, and interpretable. This synthesis of physics and data empowers more reliable dynamic optimization and control strategies, as demonstrated by the presented MPC case study for a chemical reactor.
Looking ahead, active research is exploring not only the parameters but also the discovery of entire physical laws via data-driven methods, further enhancing the robustness and interpretability of PIML in complex engineering applications.
Case Study
Physics-Informed Learning of Thermophysical Properties

Generative AI Learning
Check the answer: At steady state the balance fixes only a combination of U and alpha, and the initial slope fixes alpha/(m cp). Fit U and alpha on your own run with m, cp, A and eps fixed, and look at the correlation of the two estimates. If the assistant says all six can be fitted from one step, the parameter correlation from your fit shows why not.
IV. References
- Karniadakis, G. E., Kevrekidis, I. G., et al. (2021). Physics-informed machine learning. Nat. Rev. Phys., 3(6), 422–440. NSGA-PINN for Physics-Informed Neural Network Training
- Willard, J., Jia, X., et al. (2022). Integrating Scientific Knowledge with Machine Learning for Engineering and Environmental Systems. ACM Comput. Surv. 55(4): 73. Integrating Scientific Knowledge with Machine Learning for Engineering and Environmental Systems
- Raissi, M., Perdikaris, P., & Karniadakis, G. (2019). Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear PDEs. J. Comput. Phys., 378, 686–707.
- Greydanus, S., Dzamba, M., & Yosinski, J. (2019). Hamiltonian Neural Networks. NeurIPS 2019. Hamiltonian Neural Networks
- Karpatne, A., Watkins, W., Read, J., & Kumar, V. (2017). Physics-guided Neural Networks (PGNN): An Application in Lake Temperature Modeling. SIAM Int. Conf. on Data Mining (SDM). Integrating Scientific Knowledge with Machine Learning for Engineering and Environmental Systems
- Parish, E. & Duraisamy, K. (2016). A paradigm for data-driven predictive modeling using field inversion and machine learning. J. Comput. Phys., 305, 758–774.
- GEKKO Documentation (2020). Machine Learning in GEKKO. Machine Learning — GEKKO documentation
- Sanyal, S. & Roy, K. (2023). RAMP-Net: Robust Adaptive MPC for Quadrotors via Physics-informed Neural Networks. IEEE Int. Conf. Robotics and Automation (ICRA).
- Zheng, Y. & Wu, W. (2023). Physics-informed recurrent neural network based MPC for chemical processes. J. Process Control, 118, 65–77.
- Patel, D. et al. (2024). Model Predictive Control Using Physics Informed Neural Networks for Process Systems. ADCHEM 2024, IFAC-PapersOnLine, 57(9), 276–281.
- Gunnell, L., Lu, X., Vienna, J.D., Kim, D-S, Riley, B.J., Hedengren, J.D., Uncertainty propagation and sensitivity analysis for constrained optimization of nuclear waste vitrification, 2025, doi: 10.1111/jace.20446 Article (Open-Access)
- Arce Munoz, S., Hedengren, J.D., Transfer Learning for Thickener Control, Processes, Special Issue: Machine Learning Optimization of Chemical Processes, 2025, 13, 223, doi: 10.3390/pr13010223 Article
- Arce Munoz, S., Pershing, J., Hedengren, J.D., Physics-Informed Transfer Learning for Process Control Applications, Industrial & Engineering Chemistry Research, 2024, doi: 10.1021/acs.iecr.4c02781 Article
- Gunnell, L., Nicholson, B., Hedengren, J.D., Equation-based and data-driven modeling: Open-source software current state and future directions, Computers & Chemical Engineering, 2024, 108521, ISSN 0098-1354, DOI: 10.1016/j.compchemeng.2023.108521. Article
- Park, J., Babaei, M.R., Arce Munoz, S., Venkat, A.N., Hedengren, J.D., Simultaneous Multistep Transformer Architecture for Model Predictive Control, Computers & Chemical Engineering, Volume 178, October 2023, 108396, DOI: 10.1016/j.compchemeng.2023.108396 Article
- Babaei, M.R., Stone, R., Knotts, T.A., Hedengren, J.D., Physics-Informed Neural Networks with Group Contribution Methods, Journal of Chemical Theory and Computation, American Chemical Society, 2023, DOI: 10.1021/acs.jctc.3c00195. Article