Skip to content

fix(utils): saturate quantize output to avoid sign-flip wraparound - #50

Open
dlyongemallo wants to merge 1 commit into
moth-quantum:mainfrom
dlyongemallo:fix_mqsm_wraparound
Open

fix(utils): saturate quantize output to avoid sign-flip wraparound#50
dlyongemallo wants to merge 1 commit into
moth-quantum:mainfrom
dlyongemallo:fix_mqsm_wraparound

Conversation

@dlyongemallo

Copy link
Copy Markdown

Fixes #49.

Copilot AI review requested due to automatic review settings April 29, 2026 13:55

Copilot AI left a comment

Copy link
Copy Markdown

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 fixes a signed wraparound bug in utils.quantize that caused full-scale positive samples (e.g., +1.0) to overflow the representable signed integer range and decode with a sign flip (impacting QSM/MQSM), by saturating/clipping instead of wrapping.

Changes:

  • Add saturation (via clipping) to quantize to keep outputs within the signed integer range for the given qubit_depth.
  • Add input validation for qubit_depth (must be an integer ≥ 1; accepts NumPy integer scalars but rejects bools).
  • Add focused unit tests covering in-range behavior, positive/negative saturation, and qubit_depth validation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
quantumaudio/utils/convert.py Clamp quantization outputs to the representable signed range and validate qubit_depth to prevent overflow-induced sign flips.
tests/test_convert.py New unit tests validating saturation behavior and qubit_depth type/range handling.

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

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.

input +1.0 decodes to -1.0 due to signed-int overflow in utils.quantize (affects QSM/MQSM)

2 participants