Skip to content

Restore the resource-constraint check on interior periods - #75

Open
vahid-ahmadi wants to merge 1 commit into
PSLmodels:mainfrom
vahid-ahmadi:fix/interior-resource-constraint-check
Open

Restore the resource-constraint check on interior periods#75
vahid-ahmadi wants to merge 1 commit into
PSLmodels:mainfrom
vahid-ahmadi:fix/interior-resource-constraint-check

Conversation

@vahid-ahmadi

@vahid-ahmadi vahid-ahmadi commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Why

_build_specs sets RC_TPI = 0.2 so TPI can finish despite a known boundary discontinuity at the final period. But OG-Core compares RC_TPI against every period at once (np.any, TPI.py:1839), so that also waives interior violations up to 0.2 — the same order as the ~0.109 terminal error it was written for. A transition path that goes wrong mid-path returns numbers instead of raising.

RC_TPI also has a paramtools validator of range: [1e-13, 0.01]. 0.2 is 20x the schema maximum and only takes effect because it's assigned directly after update_specifications. There is no in-contract value that accommodates the terminal artifact, which is why this is handled after the solve rather than by tuning the parameter.

What changes after merging

A resource-constraint violation anywhere except the final period raises instead of passing silently, naming the magnitude and the period. Runs that are actually fine are unaffected — the terminal period stays exempt and RC_TPI = 0.2 is unchanged. In practice: bad transition paths stop reaching your results.

Change

_check_interior_resource_constraint, called after both the baseline and reform TPI solves. Checks RC_error[:-1] against 1e-4. resource_constraint_error is (T, M), so trailing axes are collapsed and the reported index is a period. Missing key, None, and single-period inputs are no-ops.

Evidence

9 tests, 7s: terminal-only violation passes; an interior violation of the same magnitude raises and names the right period; sign ignored; interior within tolerance passes; trailing axes collapse correctly; label appears; no-op cases.

Full suite 18 passed, 3 skipped. ruff clean. CI green.

Fixes #72. This is the interim option — if PSLmodels/OG-Core#1210 adds a separate terminal tolerance upstream, this can be replaced by setting it and restoring a tight RC_TPI.

_build_specs sets RC_TPI = 0.2 so TPI can complete despite a known
boundary discontinuity at t = T-1. OG-Core compares RC_TPI against every
period at once (np.any, TPI.py:1839), so that also waives interior
violations up to 0.2 -- the same order as the terminal error the setting
was written to accommodate. A transition path that goes wrong mid-path
returns numbers instead of raising.

RC_TPI also carries a paramtools validator of range [1e-13, 0.01], so
0.2 is 20x the schema maximum and only takes effect because it is set by
attribute assignment after update_specifications. There is no in-contract
value that accommodates the terminal artifact.

Adds _check_interior_resource_constraint, run after both the baseline and
reform TPI solves, which checks RC_error[:-1] against 1e-4 and leaves the
terminal period exempt. Trailing axes are collapsed so the reported index
is a period.

Refs PSLmodels#72, PSLmodels/OG-Core#1210

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XCKMb1aicxYaeUC1us2nvF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RC_TPI = 0.2 waives the resource-constraint check at every period, not just the terminal one

1 participant