Skip to content

Check normalization and raise error when not 1#87

Merged
rafaelha merged 5 commits intomainfrom
rafaelha/underflow_bug
Apr 1, 2026
Merged

Check normalization and raise error when not 1#87
rafaelha merged 5 commits intomainfrom
rafaelha/underflow_bug

Conversation

@rafaelha
Copy link
Copy Markdown
Collaborator

@rafaelha rafaelha commented Apr 1, 2026

Due to underflows or overflows in the evaluation routine, it is possible that marginal probabilities are not normalized.

Previously, normalization was not checked, and inconsistent sampling results could silently be returned. With this PR, the batch size is now increased to one by one, and that extra sample is used to verify normalization.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2095 2030 97% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/tsim/core/exact_scalar.py 100% 🟢
src/tsim/sampler.py 96% 🟢
TOTAL 98% 🟢

updated for commit: e3fae12 by action🐍

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-04-01 14:47 UTC

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a runtime normalization check during autoregressive sampling to detect numerical underflow/overflow cases that can produce non-normalized marginals, and raises an error instead of silently returning inconsistent samples.

Changes:

  • Extend component sampling to track a maximum normalization deviation during autoregressive evaluation.
  • Raise an error from sample_program when deviation exceeds a threshold, and add an integration test covering the failure path.
  • Minor comment/TODO wording update in exact scalar summation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/tsim/sampler.py Adds per-component normalization deviation tracking and raises an error when deviation is too large.
test/integration/test_sampler.py Adds a regression test for the raised error; also introduces a sys.path mutation and updates a __main__ debug snippet.
src/tsim/core/exact_scalar.py Adjusts TODO comment wording related to overflow prevention in summation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rafaelha and others added 3 commits April 1, 2026 10:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rafaelha rafaelha merged commit 8c21020 into main Apr 1, 2026
10 checks passed
@rafaelha rafaelha deleted the rafaelha/underflow_bug branch April 1, 2026 14:40
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.

2 participants