Skip to content

[python] Print the diagnostic in emitWarning (warnings were silently dropped) - #5529

Open
udsy19 wants to merge 1 commit into
NVIDIA:mainfrom
udsy19:fix/emit-warning-drops-message
Open

udsy19 wants to merge 1 commit into
NVIDIA:mainfrom
udsy19:fix/emit-warning-drops-message

Conversation

@udsy19

@udsy19 udsy19 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Summary

cudaq.kernel.utils.emitWarning never shows the warning. It formats the diagnostic into a local msg and then the function ends without printing it, so the only visible effect is a stray bold escape with no text. It also labels the diagnostic error: even though it is a warning.

Root cause

def emitWarning(msg):
    print(Color.BOLD, end='')
    try:
        raise RuntimeError(msg)
    except RuntimeError:
        with set_tracebacklimit(None):
            offendingSrc = traceback.format_stack()
        if len(offendingSrc):
            msg = (Color.YELLOW + "error: " + ... + msg + ...)   # reassigned, never printed

The sibling PyASTBridge.emitWarning in ast_bridge.py ends with print(msg) and uses a warning: label. This copy dropped the print. The real caller is the non-slots=True dataclass advisory in utils.py (mlirTypeFromPyType), which users never actually saw.

Fix

Print the formatted message, and label it warning: to match the sibling and the function's purpose.

Tests

Added python/tests/kernel/test_emit_warning.py (capsys): asserts the warning body reaches the user and that the label is warning:, not error:.

cudaq.kernel.utils.emitWarning assembled a formatted warning string into a
local `msg` and then fell off the end of the function, discarding it. The
only observable effect of a warning was a stray bold-escape sequence with no
text, so every advisory routed through this helper (e.g. the
non-`slots=True` dataclass notice in mlirTypeFromAnnotation) was silently
lost. Its sibling emitWarning in ast_bridge.py ends with `print(msg)`.

Print the assembled message so the warning actually reaches the user, and
label it "warning:" instead of "error:" to match the function's purpose
and the ast_bridge sibling.

Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added python-lang Anything related to the Python CUDA Quantum language implementation python bridge Involves the python bridge to quake labels Oct 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python bridge Involves the python bridge to quake python-lang Anything related to the Python CUDA Quantum language implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant