Skip to content

Add closed_world predicates#137

Merged
ColtonPayne merged 13 commits intomainfrom
add-circumscription-2
Apr 6, 2026
Merged

Add closed_world predicates#137
ColtonPayne merged 13 commits intomainfrom
add-circumscription-2

Conversation

@ColtonPayne
Copy link
Copy Markdown
Collaborator

@ColtonPayne ColtonPayne commented Apr 5, 2026

Summary

Adds support for closed world predicates to PyReason. Predicates registered as closed-world have their unknown [0,1] bounds treated as [0,0] (false) during rule body satisfaction checks, enabling negation-as-failure style reasoning for a user-specified subset of predicates.

Public API

pr.add_closed_world_predicate('hackerControl')

Any clause in a rule body that references hackerControl will, at satisfaction-check time, treat unknown [0,1] bounds — or absence of the label entirely — as [0,0]. Known bounds are left untouched, so setting hackerControl(A) explicitly still behaves normally. pr.reset() clears the registered set; pr.reset_rules() and pr.reset_settings() leave it intact.

Implementation

  • New module-level __closed_world_predicates set in pyreason/pyreason.py, plumbed into each Interpretation* class via Program.reason() as a numba.typed.List[Label].
  • is_satisfied_node / is_satisfied_edge in interpretation.py, interpretation_fp.py, and interpretation_parallel.py gained a short-circuit branch: if the clause label is closed-world and the world bound is missing or [0,1], it's coerced to [0,0] before the containment check.
  • Fixed a bug where Program.reason() assigned closed_world_predicates to Interpretation and InterpretationFP but not InterpretationParallel, causing parallel mode to silently run with an empty closed-world set. Assignment added in pyreason/scripts/program/program.py.

Tests

  • Unittests/unit/disable_jit/interpretations/test_minimized_predicates.py: JIT-disabled tests covering is_satisfied_node / is_satisfied_edge directly for both interpretation and interpretation_fp modules. Exercises in-world [0,1], missing label, known bounds bypass, negative-query case, multiple closed-world predicates, and non-closed-world contrast.
  • APItests/api_tests/test_pyreason_state_management.py adds TestMinimizedPredicateApi: registration, idempotence, multi-predicate, and interactions with reset() / reset_rules() / reset_settings().
  • Functionaltests/functional/test_circumscription.py: 8 scenarios × 3 modes (regular, fp, parallel). Every test depends on a ~closed_world_pred(Y) clause actually firing, so circumscription must be working for the test to pass (not just present). Covers:
    • Known [1,1] bypass
    • Closed-world vs non-closed-world contrast
    • Multi-timestep cascade (A → B → C, [0,1] at each step)
    • inconsistency_check, persistent, atom_trace settings
    • Two closed-world predicates exercising both branches (explicit [0,1] and missing-from-world) in the same reasoning pass
    • End-to-end example scenario

Test plan

  • pytest tests/unit/disable_jit/interpretations/test_minimized_predicates.py -v
  • pytest tests/api_tests/test_pyreason_state_management.py -v
  • pytest tests/functional/test_circumscription.py -v (all cases green on regular + fp + parallel)
  • python examples/circumscription_ex.py runs without error

🤖 Generated with Claude Code

@ColtonPayne ColtonPayne changed the title Add circumscription Add closed_world predicates Apr 6, 2026
@ColtonPayne ColtonPayne requested a review from kmukherji April 6, 2026 18:22
@ColtonPayne ColtonPayne added the Ready for Review Awaiting PR Review label Apr 6, 2026
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there's documentation on another file, this script needs some comments for an user to understand what's going on.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated example with comments

@ColtonPayne ColtonPayne merged commit cecfd97 into main Apr 6, 2026
3 checks passed
@ColtonPayne ColtonPayne deleted the add-circumscription-2 branch April 8, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Review Awaiting PR Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants