Gradient-Free Generation for Hard-Constrained Systems

Chaoran Cheng, Boran Han, Danielle C. Maddix, Abdul Fatir Ansari, Andrew Stuart, Michael W. Mahoney, Bernie Wang

Generative models that satisfy hard constraints are critical in scientific and engineering applications where physical laws or system requirements must be strictly respected. While existing constrained generative models—especially those developed for computer vision—rely heavily on gradient information, this approach is often sparse, computationally expensive, or inaccurate in fields like solving partial differential equations (PDEs).

To address this, researchers have introduced ECI (Extrapolation-Correction-Interpolation) sampling, a zero-shot, gradient-free framework that guides pre-trained flow-matching models to strictly satisfy hard constraints.

The Challenge of Hard Constraints in SciML

In generative modeling, guiding a pre-trained model to satisfy specific conditions is typically achieved using soft constraints. This involves calculating the gradient of a loss function and using it to nudge the generation process. While effective for tasks like image inpainting, this method struggles in Scientific Machine Learning (SciML).

When generating solutions for PDEs, constraints are not mere suggestions; they are strict physical laws (e.g., conservation of mass) or rigid boundary conditions. Relying on gradient guidance for these hard constraints is highly problematic. It requires backpropagation through ODE solvers, making it computationally expensive and memory-intensive. Furthermore, it is prone to gradient imbalances and almost never satisfies the physical constraints exactly.

Illustration of guiding an unconstrained generative prior using hard constraints (Initial and Boundary Conditions) for the Stokes Problem.

ECI Sampling: A Gradient-Free Solution

To overcome these limitations, the authors propose ECI sampling, applied to pre-trained Functional Flow Matching (FFM) models. Instead of using gradients to guide generation at each timestep, ECI employs a deterministic, gradient-free loop:

  1. Extrapolation (E): The method takes the current noisy intermediate state and uses the model's vector field to predict the final, "clean" solution (at $t=1$).
  2. Correction (C): A hard constraint projection is applied to this clean prediction. For instance, if a boundary must be exactly $0$, those specific values are forced to $0$. If mass must be conserved, an oblique projection corrects the integral.
  3. Interpolation (I): Noise is added back to this corrected clean state to return it to the current timestep.

This E-C-I step effectively "backpropagates" the constraint information into the noisy data without computing a single gradient. The framework also utilizes mixing iterations—repeating the ECI step multiple times at the same timestep—to smoothly blend constrained and unconstrained regions, preventing unnatural artifacts. Iterative correction proves vastly superior to post-hoc fixing; simply forcing boundaries to fit constraints at the end of generation creates massive, physically impossible artifacts.

Experimental Validation and Key Results

The framework was evaluated on a diverse set of simulated and synthetic PDE systems, including the 1D Stokes Problem, 1D Heat Equation, 2D Darcy Flow, 2D Navier-Stokes (NS) Equation, and the Generalized Porous Medium Equation (GPME) family. To evaluate the high-level quality of the generated physics distributions, the authors adapted the Fréchet Inception Distance (FID) into a new metric called the Fréchet Poseidon Distance (FPD), utilizing the pre-trained PDE foundation model "Poseidon."

Quantitative results across various PDE datasets. ECI sampling consistently achieves 0 constraint error (CE) and outperforms baselines in Mean/Std MSE and FPD metrics.

The empirical results highlight several major advantages of the ECI framework:

  • Exact Satisfaction: ECI sampling achieved exactly 0 constraint error across all tested PDE systems. In contrast, gradient-based baselines (like DiffusionPDE and D-Flow) consistently left residual errors.
  • Massive Efficiency Gains: By bypassing the ill-conditioning and memory bloat of gradient-based solvers, ECI is highly efficient. On the Stokes problem, ECI sampling achieved a 440x speedup and used 310x less GPU memory compared to the gradient-based D-Flow method.
  • Superior Distributional Quality: ECI outperformed all zero-shot baselines in capturing the true distribution of the physics, achieving state-of-the-art scores in Mean/Std MSE and the newly introduced FPD metric.
  • Zero-Shot Regression Capabilities: If provided with enough hard constraints to make a PDE "well-posed" (having one unique solution), the ECI sampling process naturally collapses the generative distribution into a highly confident, deterministic prediction. In zero-shot neural operator tasks, the ECI-guided generative model matched or beat standard Fourier Neural Operators (FNOs) explicitly trained from scratch for those specific tasks.

Limitations and Future Directions

While highly effective, the framework relies on two main hyperparameters: the number of mixing iterations and a noise re-sampling interval. The optimal settings for these are task-dependent and rely on the variance of the specific PDE system. Currently, selection relies on heuristic guidelines rather than rigorous theoretical methods.

Future work will likely focus on the theoretical analysis of these hyperparameters. Furthermore, because ECI sampling is a generalized framework for hard constraints, its application can theoretically be expanded beyond SciML into other domains requiring strict adherence to rules, such as time-series forecasting and supply chain optimization.

Summary updated

BibTeX
@inproceedings{cheng2025gradient,
  author = {Chaoran Cheng and Boran Han and Danielle C. Maddix and Abdul Fatir Ansari and Andrew Stuart and Michael W. Mahoney and Bernie Wang},
  title = {{Gradient-Free Generation for Hard-Constrained Systems}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=teE4pl9ftK},
}
Figure