In standard deep learning, we treat rules as suggestions. If we want a neural network to obey a physical law—like ensuring that fluid flow is incompressible or that a predicted temperature doesn't exceed a physical maximum—we typically add a penalty term to the loss function.
As Fangcheng Zhong and colleagues point out in Neural Fields with Hard Constraints of Arbitrary Differential Order, these "soft constraints" are notoriously unreliable. The network might get close to the rule, but it rarely satisfies it exactly. For safety-critical systems or precise physical simulations, "close" isn't good enough.
A growing body of research is shifting the paradigm from penalizing violations to preventing them by design. By baking constraints directly into the mathematical architecture of the model, researchers are creating networks that are physically and logically consistent by construction.
The Potential Field Trick
One of the most effective ways to guarantee a constraint is to change what the network is actually predicting. Instead of asking a network to predict a vector field (like wind velocity) and hoping it is "divergence-free," we can force it to predict an underlying "potential" field.
In Linearly Constrained Neural Networks, Johannes Hendriks and his team demonstrate that if you pass a scalar potential through a specific linear operator (like a curl or a gradient), the resulting output is mathematically guaranteed to satisfy the desired physical property. Because the constraint is satisfied by the very definition of the operation, the network cannot "leak" or produce physically impossible results, even before it has seen a single piece of training data.
Mapping the Feasible Region
When the constraints aren't differential equations but rather boundaries—like resource limits in a network or temperature bounds in climate science—the problem becomes one of geometry. The set of all valid answers forms a "feasible region," often a high-dimensional shape called a polytope.
Meiyi Li introduces a framework called LOOP-LC in Learning to Solve Optimization Problems with Hard Linear Constraints. The core mechanism is a "gauge mapping." Imagine a simple unit ball (a circle or sphere). The network makes a prediction inside this simple ball, and a mathematical transformation then "stretches" that ball to perfectly fit the complex, multi-sided shape of the feasible region.
This approach, also explored by Qiao Xiang in the context of bandwidth reservation (Optimizing in the Dark: Learning an Optimal Solution through a Simple Request Interface), ensures that every single forward pass of the network lands inside the "safe" zone.
Why Hard Constraints Speed Up Learning
Beyond safety, hard constraints act as a powerful form of regularization. By shrinking the space of possible functions the network can represent, we make the learning task much easier.
Anna Scampicchio and James Anderson provide a theoretical foundation for this in Physics-informed learning under mixing: How physical knowledge speeds up learning. They prove that when physical knowledge is built-in, the learning rate can jump from a "slow" rate to a "fast" $O(1/T)$ rate.
This efficiency is visible in practice. Alex Hernández-García and David Rolnick show in Multi-variable Hard Physical Constraints for Climate Model Downscaling that models with hard constraints achieve 100% physical consistency. This allows them to generalize to extreme climate scenarios that weren't in the training data—situations where "soft" models often break down and predict impossible weather.
The Linear Frontier
Despite these successes, there is a recurring wall in the literature: linearity.
Almost all current "by-construction" methods rely on linear operators or linear inequalities. Fanqi Yan and Guy Van den Broeck note in their work on hybrid probabilistic inference (Hybrid Probabilistic Inference with Logical Constraints: Tractability and Message Passing) that while linear constraints are becoming tractable, non-linear physical boundaries or complex geometric constraints remain an open challenge.
As Gonzalo E. Constante Flores argues in Enforcing Hard Linear Constraints in Deep Learning Models with Decision Rules, the field is currently mastered at handling "flat" constraints. The next step—and the current focus of researchers like Johannes Schmidt-Hieber and Axel Munk—is extending these hard guarantees to the curved, non-linear manifolds that define the most complex systems in our world.