Simplesat
Simplesat is a Python library providing a prototype for SAT-based dependency handling, designed for resolving package and software dependencies using satisfiability algorithms. It is currently at version 0.9.2. The release cadence is irregular, with recent updates primarily focusing on Python version compatibility and bug fixes rather than rapid feature additions. The API is explicitly stated as being subject to change.
Common errors
-
AttributeError: module 'simplesat.constraints' has no attribute 'EQ'
cause This usually means you are using an older version of simplesat where the `EQ` symbol, or other constraint symbols, were not directly exposed from `simplesat.constraints` or the module path changed due to API instability.fixUpgrade to the latest version of `simplesat` (`pip install --upgrade simplesat`) or consult the documentation for your specific version to find the correct import path for constraint symbols. -
simplesat.solver.SolverError: Unsatisfiable problem: detected cyclic dependencies
cause The set of constraints you've provided forms a circular dependency, making it impossible for the solver to find a valid solution.fixAnalyze your constraints for cycles. This error often indicates a logical flaw in how dependencies are defined (e.g., Package A requires B, B requires C, and C requires A). You must remove or modify the conflicting constraints to break the cycle. -
ImportError: cannot import name 'Solver' from 'simplesat.solver'
cause The `Solver` class was either renamed, moved to a different module, or does not exist in your installed version of `simplesat` due to an API change.fixVerify your `simplesat` version. If it's old, upgrade to the latest (`pip install --upgrade simplesat`). If the problem persists, check the official GitHub repository's `README.md` or source code for the correct module path for `Solver` in your specific version.
Warnings
- breaking The project summary explicitly states: 'This is a work in progress, do not expect any API not to change at this point.' This means breaking changes can occur between minor or even patch versions without a major version increment.
- gotcha Simplesat is specifically designed for 'SAT-based dependency handling' and might not behave as expected for general-purpose constraint satisfaction problems. Its focus is on package-like dependencies.
- gotcha If your set of constraints leads to a cyclic dependency, the solver will likely report an unsatisfiable problem. While version 0.9.2 improved the error message for this specific case, it remains a common pitfall in constraint definition.
Install
-
pip install simplesat
Imports
- Solver
from simplesat.solver import Solver
- Repository
from simplesat.repository import Repository
- Solvable
from simplesat.repository import Solvable
- EQ
from simplesat.core.constraints import EQ
from simplesat.constraints import EQ
Quickstart
from simplesat.constraints import EQ, GE
from simplesat.repository import Repository, Solvable
from simplesat.solver import Solver
# Define some solvables (e.g., packages and their versions)
foo_1_0 = Solvable("foo", "1.0")
foo_1_1 = Solvable("foo", "1.1")
bar_1_0 = Solvable("bar", "1.0")
# Create a repository of available solvables
repo = Repository([foo_1_0, foo_1_1, bar_1_0])
# Initialize the solver with the repository
solver = Solver(repo)
# Add constraints to the solver
solver.add_constraint(EQ("foo", "1.0")) # Require 'foo' version '1.0'
solver.add_constraint(GE("bar", "1.0")) # Require 'bar' version '1.0' or greater
# Solve the problem
try:
solution = solver.solve()
print(f"Solution found: {solution}")
except Exception as e:
print(f"Failed to find a solution: {e}")