Simplify cnf_manager.py: remove dead code, deduplicate, fix types#4
Merged
Conversation
Remove 10 unused/obsolete methods (minimize_qm, _rebuild_from_solutions, minimize_espresso, get_variable, add_var_clause, remove_clause, merge, create_with_state_constraints, add_unit_constraint, add_constraint_from_unsatisfied) reducing the file from 838 to 582 lines. Extract _literals_to_var_clause helper to consolidate 4 duplicated literal-to-variable conversion sites, and _enumerate_models to deduplicate the SAT model counting loop. Modernize all type hints to Python 3.10+ style, fix all 5 mypy errors, and fix __repr__ to not trigger SAT solve on print. Replace removed-method tests with production API tests (state_constraints_to_assumptions, count_models_with_temporary_clause). All 211 tests pass, experiments produce identical results.
mypy was missing from the dependency group, causing CI type checking to fail with "No such file or directory".
2. _invalidate_cache() moved after loop — called once instead of per-iteration 3. assumptions is not None — correct empty-list handling
Fix real bugs in model_metrics.py (wrong class name, missing constructor args, wrong attribute access), add null guards in information_gain.py and active_environment.py, fix forward references in parallel_gain.py, and add missing type annotations across 11 files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cnf_manager.py, reducing 838 → 582 lines (-30%)_literals_to_var_clauseand_enumerate_modelshelpers to eliminate code duplicationTest plan
uv run pytest tests/ -v)cnf_manager.py