NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Physics-Constrained Flow Matching: Sampling Generative Models with Hard Constraints

Utkarsh Utkarsh, Pengfei Cai, Alan Edelman, Rafael Gomez-Bombarelli, Christopher Vincent Rackauckas

Introduction

Deep generative models, particularly diffusion and flow-matching architectures, have emerged as powerful tools for simulating complex physical systems. By learning the underlying distribution of solutions to Partial Differential Equations (PDEs), these models can accelerate scientific discovery in fields ranging from fluid dynamics to materials science. However, a significant hurdle remains: physical systems are governed by strict, non-negotiable laws, such as the conservation of mass, momentum, and energy.

Traditional approaches typically enforce these laws through "soft constraints," where physical violations are added as penalty terms to the training loss function—a method popularized by Physics-Informed Neural Networks (PINNs). While effective at guiding the model, soft constraints rarely achieve exact satisfaction of physical laws. In many engineering applications, even minor deviations from these constraints can lead to unphysical results or numerical instability. This paper introduces Physics-Constrained Flow Matching (PCFM), a zero-shot inference technique designed to enforce hard nonlinear physical constraints on pretrained generative models without requiring retraining.

The PCFM Framework

PCFM is a post-hoc method that operates during the sampling phase of Functional Flow Matching (FFM) models. It ensures that the generated samples reside on the "constraint manifold"—the mathematical subspace where all physical laws are perfectly satisfied.

The Sampling Process

The PCFM algorithm modifies the standard ODE integration used in flow matching through a three-step correction cycle at each timestep:

  1. Forward Shooting and Projection: As the model generates a solution from Gaussian noise, PCFM performs a "forward shoot" to estimate the final state. This estimate is then projected onto the constraint manifold using a custom, batched Gauss-Newton solver. This solver is optimized for speed and can handle complex nonlinear constraints.
  2. Reverse Update via Optimal Transport: Once a physically consistent target is identified, the algorithm must update the current intermediate state. PCFM utilizes an Optimal Transport (OT) displacement interpolant to map the corrected target back to the current timestep, ensuring the trajectory remains stable and coherent.
  3. Relaxed Correction: To prevent the hard constraints from diverging too far from the model's learned data distribution, a penalized correction step is applied. This ensures the sampling path respects the physical boundaries while still following the high-probability regions learned by the generative model.

Experimental Evaluation

The authors evaluated PCFM across a diverse suite of PDE benchmarks, each presenting unique numerical challenges:

  • 1D Heat Equation: Testing linear constraints involving initial conditions and global mass conservation.
  • 2D Navier-Stokes Equation: Modeling incompressible fluid flow to evaluate linear global vorticity conservation.
  • 1D Reaction-Diffusion Equation: Introducing nonlinear mass conservation and Neumann boundary fluxes.
  • 1D Inviscid Burgers' Equation: A rigorous test involving the formation of sharp shocks and discontinuities, requiring the enforcement of nonlinear mass and mixed Dirichlet/Neumann boundary conditions.

Key Results and Insights

Precision and Accuracy

PCFM achieves machine-precision constraint satisfaction (Constraint Error $\approx 0$) across all tested scenarios. Beyond mere compliance, the method significantly improves the fidelity of the generated solutions. On the challenging Burgers' equation, PCFM reduced the Mean Squared Error (MSE) by over 99% compared to existing constrained baselines like D-Flow and DiffusionPDE.

Efficiency and Scalability

Despite the inclusion of an iterative solver in the inner loop, PCFM is highly efficient. The custom batched Gauss-Newton solver allows the method to run 4–6 times faster than gradient-heavy alternatives. The additional computational overhead for the projection step is minimal, typically adding only 1–3% to the total sampling time.

The Value of Hard Constraints

A counter-intuitive finding of the research is that adding more constraints often improves performance. In soft-penalty methods, increasing the number of constraints typically complicates the optimization landscape. In PCFM, however, providing additional physical rules (such as local flux conservation) helps guide the generative flow more accurately toward the true solution manifold.

Conclusion

Physics-Constrained Flow Matching demonstrates that exact physical consistency can be achieved in generative modeling without the need for expensive retraining or complex architectural changes. By shifting the burden of constraint satisfaction to a zero-shot inference step, PCFM provides a robust and efficient path forward for AI-driven scientific simulation. Future work aims to extend this framework to handle inequality constraints (e.g., ensuring non-negative density) and to optimize the solver for high-dimensional 3D simulations by leveraging structural sparsity in constraint Jacobians.

Summary updated

BibTeX
@inproceedings{utkarsh2025physics,
  author = {Utkarsh Utkarsh and Pengfei Cai and Alan Edelman and Rafael Gomez-Bombarelli and Christopher Vincent Rackauckas},
  title = {{Physics-Constrained Flow Matching: Sampling Generative Models with Hard Constraints}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=cf4etwjY7n},
}
Figure