Skip to content

Add flexible solver strategies, solution modes and result normalization to Modello#21

Draft
Code0x58 wants to merge 1 commit intomasterfrom
codex/refactor-solver-logic-in-modello
Draft

Add flexible solver strategies, solution modes and result normalization to Modello#21
Code0x58 wants to merge 1 commit intomasterfrom
codex/refactor-solver-logic-in-modello

Conversation

@Code0x58
Copy link
Copy Markdown
Owner

@Code0x58 Code0x58 commented May 8, 2026

Motivation

  • Provide more flexible constraint solving for Modello instances to handle legacy, set-based and parametric solver outputs.
  • Allow callers to control how non-unique solutions are handled via a solution_mode and a solution_selector to pick a solution when multiple exist.
  • Normalize solver outputs into a structured result to simplify downstream attribute assignment and edge-case handling.

Description

  • Introduce SolverStrategy, SolutionMode, and SolutionKind enums and a SolveResult dataclass to represent normalized solver outputs.
  • Extend Modello.__init__ with solver_strategy, solution_mode, and solution_selector parameters and replace inline solve logic with a dedicated _solve_constraints method.
  • Implement _solve_constraints which supports the legacy solve behavior and a set strategy that uses linsolve/nonlinsolve and falls back to per-symbol solveset for parametric results, and returns SolveResult objects.
  • Update imports and add logic to select solutions, raise on multiple solutions in strict mode, and expose parametric solution sets when appropriate.

Testing

  • Ran unit tests with pytest including new tests test_solver_unique_solution, test_solver_multiple_solution_permissive_and_selector, and test_solver_underdetermined_set_strategy, and all tests passed.
  • Existing tests such as test_no_constraints and test_multiple_inheritance_expr_conflict were executed and continued to pass.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant