Skip to content

Sampler does not enforce expression constraints; violations are only recorded #120

@RandomOscillations

Description

@RandomOscillations

Summary

Agent-level expression constraints are currently evaluated post hoc and counted in stats, but not enforced during sampling. Invalid agent combinations can pass through to the final sample.

Why This Matters

This creates silent quality failures (e.g., age/education/employment inconsistencies) despite constraints being present in spec.

Current Behavior (Code)

In /Users/adithyasrinivasan/Projects/extropy/extropy/population/sampler/core.py:

  • _check_expression_constraints(...) computes violation counts (line ~870+)
  • violations stored in stats.constraint_violations
  • no repair, no resample, no fail-fast

Expected Behavior

Expression constraints should be enforceable runtime gates, not telemetry-only.

Proposed Fix

Implement deterministic enforcement policy for expression constraints:

  1. During sampling (or per-agent finalize), evaluate expression constraints.
  2. On violation, apply bounded repair strategy:
  • resample violating attribute(s) with max attempts, OR
  • deterministic repair hooks where defined.
  1. If unresolved after max attempts, raise SamplingError (strict failure).
  2. Keep violation stats for diagnostics.

Optional: configurable policy (warn|repair|fail) with fail available for production-quality runs.

Tests

Add tests showing:

  • violating samples are corrected or rejected
  • unresolved violations fail with clear error context
  • valid constraints remain unaffected

Acceptance Criteria

  • No final sampled agent violates declared expression constraints in strict mode.
  • Failure paths are explicit and actionable (attribute + constraint + agent context).

Pipeline Impact

Directly improves step 3 sample correctness and reduces downstream contradiction cleanup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions