← Back to home

Physics-Constrained Flow Matching

NeurIPS 2025

Utkarsh *, Pengfei Cai *, Alan Edelman, Rafael Gómez-Bombarelli, Christopher Vincent Rackauckas
*Equal contribution

Massachusetts Institute of Technology

PCFM summary figure

Physics-Constrained Flow Matching enforces hard physical constraints while sampling from a pretrained flow-based model. These include mass conservation and nonlinear boundary constraints. The model requires no retraining.


TLDR

  • PCFM enforces constraints during sampling from pretrained flow-matching models, without retraining or changing the architecture.
  • It enforces initial conditions, Dirichlet and Neumann boundary conditions, global conservation laws, nonlinear residual constraints, and local flux constraints to numerical precision.
  • On reaction-diffusion and Burgers equations with shocks, PCFM satisfies nonlinear and multiple simultaneous constraints while matching or improving MMSE and SMSE compared with the baselines.

Abstract

Deep generative models have recently been applied to physical systems governed by partial differential equations (PDEs), offering scalable simulation and uncertainty-aware inference. However, enforcing physical constraints, such as conservation laws (linear and nonlinear) and physical consistencies, remains challenging. Existing methods often rely on soft penalties or architectural biases that fail to guarantee hard constraints. In this work, we propose Physics-Constrained Flow Matching (PCFM), a zero-shot inference framework that enforces arbitrary nonlinear constraints in pretrained flow-based generative models. PCFM continuously guides the sampling process through physics-based corrections applied to intermediate solution states, while remaining aligned with the learned flow and satisfying physical constraints. Empirically, PCFM outperforms both unconstrained and constrained baselines on a range of PDEs, including those with shocks, discontinuities, and sharp features, while ensuring exact constraint satisfaction at the final solution. Our method provides a flexible framework for enforcing hard constraints in both scientific and general-purpose generative models, especially in applications where constraint satisfaction is essential.


Results

Burgers (fixed IC, shocks)

For the inviscid Burgers equation, we enforce a fixed initial condition, a nonlinear conservation law, and local flux collocation constraints. PCFM captures the shock structure while keeping initial-condition and mass-conservation residuals at machine precision.

Burgers equation IC fixed: solutions and mass residuals

Burgers (Dirichlet + Neumann BCs)

We fix a Dirichlet boundary condition on the left and a Neumann (zero-flux) condition on the right. PCFM satisfies both alongside nonlinear mass conservation, with residuals close to machine precision. Its MMSE, SMSE, and FPD results remain competitive with the baselines.

Burgers equation BC fixed: solutions, mass residual, and BC residuals

Reaction–Diffusion (nonlinear mass + flux)

In this reaction-diffusion problem, mass conservation depends on the nonlinear reaction term and Neumann boundary fluxes. PCFM enforces the fixed initial condition and nonlinear mass conservation to numerical precision while improving solution quality. The tested baselines, including PINN-style losses and updates to the prior noise, struggle to satisfy these constraints together.

Reaction-Diffusion results and mass residuals

The paper includes the full method, additional results, and out-of-distribution tests.


Getting started

Try the Python implementation at cpfpengfei/pcfm. A Julia implementation is also available at utkarsh530/PCFM.jl. Contact us with questions about the datasets or implementations.


BibTeX

@inproceedings{pcfm2025,
  title     = {Physics-Constrained Flow Matching: Sampling Generative Models with Hard Constraints},
  author    = {Utkarsh and Cai, Pengfei and Edelman, Alan and G{\'o}mez-Bombarelli, Rafael and Rackauckas, Christopher},
  booktitle = {Advances in Neural Information Processing Systems},
  year      = {2025}
}