PolyFlow: Safe and Efficient Polytope-Constrained Flow Matching with Constraint Embedding and Projection-free Update

jianming ma, Qiyue Yang, Yang Zhang, Liyun Yan, Zhanxiang Cao, Yazhou Zhang, Yue Gao

TL;DR

This paper introduces PolyFlow, a novel framework for safe and efficient generative modeling in safety-critical physical systems. By embedding polytope constraints directly into a discrete-time flow matching model and employing a projection-free architecture, PolyFlow guarantees strict constraint satisfaction without sacrificing generative quality or incurring high computational costs.

What Problem Does This Paper Address?

Flow-based generative models have shown great promise in various domains, but their application in safety-critical physical systems (like robotics) is hindered by strict constraint requirements. Existing methods often rely on "post-hoc" corrections (e.g., projecting trajectories back into a safe region) after generation. These methods are computationally expensive, can distort the learned data distribution, and may still fail to guarantee safety due to numerical integration errors. The core challenge is to develop generative models that are inherently safe and efficient, directly satisfying arbitrary constraints without compromising their ability to learn complex data distributions.

Methods

PolyFlow tackles this challenge with two main innovations:

  • Discrete-Time Flow Formulation: Instead of relying on continuous-time Ordinary Differential Equations (ODEs) which are prone to numerical integration errors, PolyFlow reformulates flow matching in a discrete-time setting. This eliminates discretization errors as a source of constraint violation.
  • Projection-Free Architecture: PolyFlow avoids costly projection operations during sampling. It achieves this by embedding constraints directly into the model architecture. This involves a "Ray Shooting" operator that finds the intersection of a predicted direction with the boundary of the safety polytope, and a learned gating factor that controls the step size. This ensures that every update step remains within the feasible set by construction. The model also uses a constraint encoding block to process the linear inequality constraints that define the polytope.

Datasets

The paper evaluates PolyFlow on several benchmarks:

  • 2D Maze Navigation: A standard benchmark for testing constraint satisfaction in trajectory generation, requiring collision-free paths.
  • Gym Locomotion: Five constrained closed-loop control tasks from the Gymnasium library, including Hopper, Walker2d, and HalfCheetah environments, with varying complexities of state and action space constraints.
  • Quadrupedal Locomotion (Unitree Go2): A more challenging scenario involving dynamic and time-varying friction cone constraints on the action space.

The training datasets for the locomotion tasks are sourced from the Minari library. For the Maze task, a demonstration policy was trained using Q-Iteration and a PD controller.

Key Insights and Ideas

  • Discrete-time is key for safety: By moving away from continuous ODEs, PolyFlow sidesteps the inherent numerical integration errors that plague existing methods, providing a more robust safety guarantee.
  • Embedding constraints is more efficient than correcting them: Directly building safety into the model architecture, rather than relying on post-hoc projections, significantly reduces computational overhead and avoids distorting the learned distribution.
  • Ray shooting offers a differentiable path to safety: The use of ray shooting for constraint intersection, combined with a learned gating mechanism, provides a differentiable way to guide the flow towards safe regions, enabling end-to-end training.
  • Even "clean" data isn't enough: Experiments show that even when trained on data that strictly adheres to safety boundaries, standard flow matching models still fail to guarantee safety due to fitting and discretization errors. This highlights the necessity of an explicit constraint embedding mechanism.

Key Results

  • Zero Constraint Violation: PolyFlow consistently achieves 100% safety rate across various tasks, including complex dynamic environments, outperforming baselines that often fail to guarantee absolute safety.
  • Significant Inference Speedup: PolyFlow demonstrates a substantial reduction in inference latency, being orders of magnitude faster than some constrained baselines, making it suitable for real-time applications. For example, in the 2D Maze task with equal sampling steps, PolyFlow-mlp is significantly faster than SafeFlow.
  • Competitive Generative Quality: Despite its focus on safety, PolyFlow maintains high distributional fidelity, often outperforming even unconstrained baselines in metrics like MMD and Wasserstein distance.
  • Favorable Safety-Return Trade-off: In locomotion tasks, PolyFlow achieves a superior trade-off between safety and task performance (rollout return), often steering towards safer modes that yield higher rewards.

Limitations and Future Work

  • Convex Polytopes: Currently, PolyFlow requires constraints to be formulated as convex polytopes. The authors suggest generalizing to non-convex constraint geometries through convex decomposition as a future direction.
  • Initial Distribution: PolyFlow requires the initial distribution to reside within the feasible region, which can incur additional computational overhead during sampling.
  • Equality Constraints: The paper discusses extending PolyFlow to handle equality constraints using null space projection or dimensionality reduction, but this is presented as future work.

Summary updated

BibTeX
@inproceedings{ma2026polyflow,
  author = {jianming ma and Qiyue Yang and Yang Zhang and Liyun Yan and Zhanxiang Cao and Yazhou Zhang and Yue Gao},
  title = {{PolyFlow: Safe and Efficient Polytope-Constrained Flow Matching with Constraint Embedding and Projection-free Update}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=OXLYBkYs4X},
}
Figure