Skip to content

fix: IntegratorRunner dict-monitor regression + stale post-audit test updates#854

Merged
chaoming0625 merged 1 commit into
masterfrom
fix/audit-20260619-followup
Jun 18, 2026
Merged

fix: IntegratorRunner dict-monitor regression + stale post-audit test updates#854
chaoming0625 merged 1 commit into
masterfrom
fix/audit-20260619-followup

Conversation

@chaoming0625

@chaoming0625 chaoming0625 commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

Post-integration follow-up to the 16-part audit (PRs #838#853). Fixes one
real regression surfaced by the full-suite run and re-points five stale
bug-pinning tests at the now-corrected behaviour.

Source fix

  • brainpy/integrators/runner.pyIntegratorRunner dict monitors
    regressed: after _format_dict_monitors each value is a
    (var_name_or_Variable, index) tuple, but resolution tested
    isinstance(i, str) on the whole tuple (always False), so a string
    variable-name leaked through to the base runner, which then looked it up
    as an attribute of self.target and raised. Integrator state variables
    live in self.variables; resolve string names there and pass the base
    runner an already-resolved (Variable, index) pair.

Test updates (behaviour now correct, tests re-pointed)

  • nvar_coverage_testorder < 2 now raises ValueError (not AssertionError).
  • dnn_toolbox_fixes_test — Adan now constructs and updates cleanly.
  • boost_misc_test — offline ElasticNet / Logistic regression now fit & predict.
  • train_analysis_glue_fixes_test — logistic regression now fits without error.

Test plan

  • 11 previously-flipped tests now pass (6 IntegratorRunner + 5 re-pointed).
  • Sanity: IntegratorRunner dict monitors and DSRunner dict monitors both run green.

Summary by Sourcery

Fix IntegratorRunner dictionary monitor handling and update tests to reflect corrected optimizer and offline regression behavior.

Bug Fixes:

  • Resolve IntegratorRunner dict monitor regression by correctly mapping string variable names to integrator state variables before passing them to the base runner.
  • Update NVAR error expectation to match the current ValueError raised for invalid order values.
  • Treat Adan optimizer update as working behavior instead of a known bug by exercising a full construct-and-update cycle without errors.
  • Treat offline ElasticNet regression predict as successful behavior instead of a broken path by asserting valid predictions.
  • Treat offline LogisticRegression fit as successful behavior instead of an IndexError in both general and glue tests, asserting finite fitted parameters.

Tests:

  • Refresh existing tests to assert successful Adan updates, ElasticNet prediction, and LogisticRegression fitting, ensuring outputs are finite and shapes are correct.
  • Adjust NVAR error tests to expect ValueError for invalid order rather than AssertionError.

…ug-pinning tests

Source fix
----------
`IntegratorRunner` dict monitors regressed: after `_format_dict_monitors`
each value is a ``(var_name_or_Variable, index)`` tuple, but the resolution
code tested ``isinstance(i, str)`` on that tuple (always False), so a string
variable-name was passed through to the base runner, which then looked it up
as an attribute of ``self.target`` and failed. Integrator state variables
live in ``self.variables``, so resolve string names there before handing the
base runner an already-resolved ``(Variable, index)`` pair.

Test updates
------------
Several post-audit tests pinned now-fixed behaviour. Re-pointed them at the
corrected contract:
- nvar_coverage_test: order < 2 now raises ValueError (not AssertionError).
- dnn_toolbox_fixes_test: Adan now constructs and updates cleanly.
- boost_misc_test: offline ElasticNet / Logistic regression now fit & predict.
- train_analysis_glue_fixes_test: logistic regression now fits without error.
@sourcery-ai

sourcery-ai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes an IntegratorRunner dict-monitor regression by correctly resolving string variable names to integrator state variables, and updates several tests that previously pinned buggy behavior so they now assert on the corrected, successful paths for ElasticNet/Logistic regression, Adan optimizer updates, and NVAR error typing.

Sequence diagram for IntegratorRunner dict monitor resolution fix

sequenceDiagram
  actor User
  participant IntegratorRunner
  participant Variables
  participant BaseRunner

  User->>IntegratorRunner: __init__(target, monitors)
  alt monitors is dict
    IntegratorRunner->>IntegratorRunner: _format_dict_monitors(monitors)
    loop each_monitor_entry
      IntegratorRunner->>Variables: variables[var_name]
      Variables-->>IntegratorRunner: Variable
      IntegratorRunner->>IntegratorRunner: build (Variable, index) pair
    end
  end
  IntegratorRunner->>BaseRunner: __init__(target, resolved_monitors)
Loading

File-Level Changes

Change Details Files
Fix IntegratorRunner dict-monitor handling so string-based monitor specs resolve to integrator state variables instead of leaking to the base runner and crashing.
  • Adjust dict-monitor normalization to treat values as (var_name_or_Variable, index) tuples rather than single objects.
  • Resolve string variable names against self.variables before passing monitors to the base runner.
  • Preserve already-resolved (Variable, index) pairs by leaving non-string-first elements untouched.
brainpy/integrators/runner.py
Update error expectation for invalid NVAR order to match new ValueError-based validation.
  • Change test to expect ValueError instead of AssertionError when NVAR(order<2) is constructed.
  • Document that NVAR.init now uses check.is_integer(min_bound=2) which raises ValueError on invalid order.
brainpy/dyn/rates/nvar_coverage_test.py
Repoint offline ElasticNet and Logistic regression tests from pinning known crashes to asserting successful fit/predict behavior.
  • Rename ElasticNet test and update its docstring to describe the now-consistent call/predict feature handling.
  • Replace expect-raises around ElasticNetRegression.predict with shape checks on successful predictions.
  • Rename LogisticRegression tests and update docstrings to describe the fixed 1-D target handling.
  • Replace expect-raises around LogisticRegression.call with assertions that fitting succeeds and parameters are finite.
brainpy/boost_misc_test.py
brainpy/train_analysis_glue_fixes_test.py
Update Adan optimizer test to assert that update runs successfully and keeps parameters finite instead of pinning a TypeError from lax.cond.
  • Rename Adan test and update its docstring to describe the fixed lax.cond operand handling.
  • Remove the TypeError expectation and instead perform a real update call.
  • Assert that the updated variable contains no NaNs after the optimizer step.
brainpy/dnn/dnn_toolbox_fixes_test.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chaoming0625 chaoming0625 merged commit 9984387 into master Jun 18, 2026
7 of 14 checks passed
@chaoming0625 chaoming0625 deleted the fix/audit-20260619-followup branch June 18, 2026 19:43

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • In IntegratorRunner.__init__, the dict-monitor normalization comprehension relies on tuple indexing (v[0], v[1]) and silently passes through non-tuple values; consider unpacking with pattern matching or explicit validation (e.g., for k, (var, idx) in monitors.items()) to make the expected structure clearer and fail fast on malformed monitor specs.
  • The updated test docstrings embed audit dates and process context (e.g., "Fixed in audit 2026-06-19"), which can quickly go stale; consider trimming these to describe only the expected behavior and failure mode so the tests remain accurate without historical context.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `IntegratorRunner.__init__`, the dict-monitor normalization comprehension relies on tuple indexing (`v[0], v[1]`) and silently passes through non-tuple values; consider unpacking with pattern matching or explicit validation (e.g., `for k, (var, idx) in monitors.items()`) to make the expected structure clearer and fail fast on malformed monitor specs.
- The updated test docstrings embed audit dates and process context (e.g., "Fixed in audit 2026-06-19"), which can quickly go stale; consider trimming these to describe only the expected behavior and failure mode so the tests remain accurate without historical context.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions github-actions Bot added the tests label Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant