fix(#61): SymmetryLossWarning points to user call site#97
Merged
Conversation
Replace the fixed `stacklevel=3` in `_warn_symmetry_loss` with a small frame-walking helper that finds the first frame outside `flopscope/`. The previous constant landed inside `_counted_wrapper.wrapped` in `_budget.py` instead of the user's `+`/`sum()`/`[...]` line, making symmetry-loss diagnostics hard to act on. The helper is robust to future changes in the number of decorator layers between user code and the warn site — no manual stacklevel bookkeeping at call sites.
Three cases covering the call paths that currently traverse different numbers of wrapper frames: - binary `A + B` with mismatched symmetries (5 frames deep) - reduction `A.sum(axis=...)` over a symmetric axis (5 frames) - slicing a `SymmetricTensor` that breaks the group (3 frames) Each test asserts `w.filename == __file__` and explicitly rejects any filename under the `flopscope` package directory, so a future wrapper addition that breaks the helper fails loudly here.
spMohanty
added a commit
that referenced
this pull request
May 23, 2026
spMohanty
added a commit
that referenced
this pull request
May 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SymmetryLossWarningpreviously pointed atsrc/flopscope/_budget.py:174(inside_counted_wrapper.wrapped) instead of the user's+/sum()/[...]line, making symmetry-loss diagnostics hard to act on.stacklevel=3in_warn_symmetry_losswith a small_user_stacklevel()helper that walks the call stack to the first frame outside theflopscope/package.Root cause
The eight call sites of
_warn_symmetry_losstraverse different numbers of wrapper frames before reachingwarnings.warn:_pointwise.py:475, 482)_pointwise.py:561, 568)_pointwise.py:951, 954)_symmetric.py:670, 677)No single constant works for all paths, and per-site stacklevels would be fragile to refactoring (adding/removing a decorator silently shifts the wrong number of frames).
Test plan
src/flopscope/_budget.py:174).tests/test_issue_61_symmetry_warning_location.pycovers binary add, reduction, and slicing — assertsw.filename == __file__and explicitly rejects paths underflopscope/.tests/test_issue_66_newaxis_symmetry.py tests/test_symmetric*.py): 418 reports, 0 failed.