NuCS vs Choco: A Pure-Python Constraint Solver Meets a JVM Veteran
Summary
NuCS, a pure-Python constraint solver (v11.2.0) accelerated by NumPy and Numba, demonstrates competitive performance against Choco (v6.0.1), a mature JVM-based solver. On identical bound-consistent models, NuCS matches Choco's speed through mid-range instances and surpasses it on larger ones, achieving 1.41x faster results on all-interval series (n=16000) and 1.22x on Schur's lemma (n=1600). This is attributed to Numba compiling inner loops to native code, eliminating Python's performance overhead. While Choco's arc consistency (AC) and enumerated domains excel on small instances or problems requiring hole-pruning (e.g., Golomb ruler), NuCS leverages cheap bound consistency (BC) with redundant constraints or custom propagators to achieve comparable or superior performance at scale, even solving instances like Latin square order 50 that plain BC models cannot.
Key takeaway
For AI Engineers evaluating constraint solvers, if your problem benefits from flexible modeling and scales to large instances, NuCS offers native-code speed in Python. You can achieve competitive performance by implementing redundant constraints or custom propagators, often surpassing traditional arc-consistent solvers on larger problems. This approach allows rapid experimentation and problem-specific optimizations directly within Python, without needing a native toolchain or JVM.
Key insights
Numba-accelerated Python solver NuCS matches or beats JVM veteran Choco by leveraging cheap bound consistency and flexible modeling.
Principles
- Numba can eliminate Python's performance penalty for core loops.
- Bound consistency with redundant constraints can outperform arc consistency at scale.
- Ease of modeling can be more critical than raw engine speed.
Method
NuCS uses NumPy arrays for `min..max` domains and Numba-jitted propagators for filtering. It interleaves propagation with branching decisions via variable and domain heuristics.
In practice
- Use redundant constraints or channeling to enhance bound consistency.
- Develop custom propagators in Python for problem-specific pruning.
- Consider solver domain representation for problem suitability.
Topics
- Constraint Programming
- NuCS
- Choco
- Python
- Numba
- Bound Consistency
- Arc Consistency
Code references
Best for: AI Scientist, AI Engineer, Machine Learning Engineer, Research Scientist
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Towards Data Science.