SnareNet: Flexible Repair Layers for Neural Networks with Hard Constraints

Ya-Chi Chu, Alkiviades Boukas, Madeleine Udell

TL;DR

SnareNet is a new neural network architecture that enforces strict, nonlinear, input-dependent constraints on model outputs using a differentiable "repair layer." By combining a regularized Newton-style update with a novel "adaptive relaxation" training strategy, it achieves significantly better optimality and feasibility than existing methods in optimization and robotics tasks.

What Problem Does This Paper Address?

Deep learning models are increasingly used as "surrogate solvers"—fast approximations for complex mathematical problems in power systems, fluid dynamics, and robotics. However, standard neural networks are "unconstrained"; they might predict a robot's path that goes through a wall or a power grid state that violates the laws of physics.

Existing solutions generally fall into two camps:

  1. Soft Constraints: Adding a penalty to the loss function. This is easy to implement but "leaky"—the model often still violates constraints at inference time.
  2. Hard Constraints: Building the constraints into the architecture. While effective for simple bounds (like ensuring a value is between 0 and 1), it is notoriously difficult for complex, nonlinear, and input-dependent constraints. Previous "hard" methods often struggle with training stability, high memory usage, or are limited to linear constraints.

Methods

SnareNet introduces two primary innovations to bridge this gap:

1. The Differentiable Repair Layer

SnareNet appends a "repair module" ($\mathcal{R}$) to the end of a baseline neural network. When the network produces an initial (potentially "illegal") prediction $\hat{y}$, the repair layer uses a Levenberg-Marquardt (LM) regularized Newton update to steer that prediction toward the feasible region.

  • Why LM? Standard Newton methods can be unstable. The LM regularization ensures the update remains local and converges reliably even when the constraint mapping is complex.
  • Feasibility Control: Unlike previous methods, SnareNet allows users to specify a tolerance ($tol$), giving practitioners explicit control over the trade-off between strictness and computation time.

2. Adaptive Relaxation (The "Snare")

Training a network with hard constraints from scratch is difficult because a randomly initialized network starts very far from the feasible region. If you force it to be feasible immediately, the gradients become unhelpful.

  • The Strategy: SnareNet starts training with a very loose "relaxed" feasible set that "snares" the network's initial outputs.
  • The Decay: As training progresses, this slack ($\epsilon$) linearly decays to zero. This allows the network to explore the solution space freely in early epochs before being gradually "reeled in" to satisfy the strict constraints by the end of training.

Datasets

The authors evaluated SnareNet on three distinct benchmarks:

  • Linearly-Constrained Non-Convex Programs (NCPs): 10,000 instances of non-convex optimization problems.
  • Quadratically Constrained Quadratic Programs (QCQPs): 10,000 instances with varying numbers of inequality constraints (10, 50, and 100), testing the model's ability to handle many simultaneous restrictions.
  • Neural Control Policies: A simulated unicycle robot task requiring the model to navigate to a goal while avoiding multiple elliptical obstacles, modeled using Control Barrier Functions (CBFs).

Key Insights and Ideas

  • The Range Space Challenge: For nonlinear constraints, a simple projection might fail because the "image" of the constraint function is often a subset of the total space. SnareNet solves this by navigating specifically within the constraint map's range space.
  • Stability via Relaxation: The "Aha!" moment of the paper is the adaptive relaxation. By making the constraints "soft" at the start and "hard" at the end, they avoid the pathological training behaviors (like diverging on unbounded objectives) that plague other end-to-end methods.
  • Handling "Too Many" Constraints: Traditional closed-form repair layers (like HardNet) are limited by the dimensionality of the output. SnareNet’s iterative LM approach allows it to handle cases where the number of constraints exceeds the number of output variables.

Key Results

  • Superior Optimality: On NCP and QCQP tasks, SnareNet achieved optimality gaps (how far the solution is from the true mathematical optimum) at least one order of magnitude smaller than baselines like DC3 and HardNet.
  • Reliable Feasibility: SnareNet consistently satisfied constraints within a $10^{-4}$ tolerance across all test instances. In contrast, the baseline DC3 only achieved feasibility on about 80% of test instances in high-constraint scenarios.
  • Robust Robotics: In the unicycle obstacle avoidance task, SnareNet successfully navigated complex environments with many obstacles where previous state-of-the-art methods (HardNet) were mathematically unable to operate due to rank constraints.

Limitations and Future Work

  • Computational Overhead: Because the repair layer is iterative, it is more computationally expensive than a simple forward pass of a standard NN (though still much faster than a traditional optimization solver like Gurobi).
  • Learnability: The authors note that it remains an open question how hard constraints fundamentally change the "learnability" of a network's weight landscape.
  • Future Directions: The team suggests exploring how these layers might be applied to even more complex domains, such as protein folding or large-scale power grid management, where physical constraints are non-negotiable.

Summary updated

Abstract

Neural networks are increasingly used as surrogate solvers and control policies, but unconstrained predictions can violate physical, operational, or safety requirements. We propose SnareNet, a feasibility-controlled architecture for learning mappings whose outputs must satisfy input-dependent nonlinear constraints. SnareNet appends a differentiable repair layer that navigates in the constraint map's range space, steering iterates toward feasibility and producing a repaired output that satisfies constraints to a user-specified tolerance. To stabilize end-to-end training, we introduce adaptive relaxation, which designs a relaxed feasible set that snares the neural network at initialization and shrinks it into the feasible set, enabling early exploration and strict feasibility later in training. On optimization-learning and trajectory planning benchmarks, SnareNet consistently attains improved objective quality while satisfying constraints more reliably than prior work.
BibTeX
@misc{chu2026snarenet,
  author = {Ya-Chi Chu and Alkiviades Boukas and Madeleine Udell},
  title = {{SnareNet: Flexible Repair Layers for Neural Networks with Hard Constraints}},
  year = {2026},
  eprint = {2602.09317},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.09317},
}
Figure