Skip to content

fix(integrators/fde): CaputoEuler.reset state desync + set_default_fdeint#846

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

fix(integrators/fde): CaputoEuler.reset state desync + set_default_fdeint#846
chaoming0625 merged 1 commit into
masterfrom
fix/audit-20260619-integrators-fde-pde

Conversation

@chaoming0625

@chaoming0625 chaoming0625 commented Jun 18, 2026

Copy link
Copy Markdown
Member

Fresh review of brainpy/integrators fractional/partial integrators.

  • HighCaputoEuler.reset replaced its f_states Variables with plain Arrays → state desync → wrong results after reset under IntegratorRunner (0.911 vs correct 0.380). Now stored in a bm.VarDict so reset updates in place.
  • Mediumfdeint(method='l1') literal default made set_default_fdeint a no-op for default-method calls; default method=None so the global fallback applies.

Core solver numerics (CaputoEuler/L1/GL) validated against reference recurrences; prior-audit FDE bugs (C-08, H-30/31/32) verified already-fixed. In-scope: 5 passed. Findings: docs/issues-found-20260619-integrators-fde-pde.md.

Summary by Sourcery

Fix fractional integrator state handling and default method selection for FDE solvers.

Bug Fixes:

  • Preserve CaputoEuler memory state variables across reset calls to avoid desynchronization when used with IntegratorRunner.
  • Ensure fdeint honors the globally configured default FDE method by changing the method parameter’s default to use the global fallback.

Documentation:

  • Document the FDE/PDE integrator review, including validated numerics and previously reported issues, in a new issues-found report.

Tests:

  • Add regression tests verifying CaputoEuler.reset keeps memory buffers as Variables and produces the same results as a fresh integrator run.
  • Add a generic-level test confirming fdeint respects set_default_fdeint when the method argument is omitted.

…lt_fdeint

- CaputoEuler.reset replaced its f_states Variables with plain Arrays, causing
  state desync and wrong results after reset under IntegratorRunner; store
  f_states in a bm.VarDict so reset does in-place .value updates (High)
- fdeint(method='l1') literal default made set_default_fdeint a no-op for
  default-method calls; default to method=None so the fallback runs (Medium)

Findings recorded in docs/issues-found-20260619-integrators-fde-pde.md
@chaoming0625 chaoming0625 merged commit b4462f0 into master Jun 18, 2026
6 of 9 checks passed
@sourcery-ai

sourcery-ai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes a state desynchronization bug in the CaputoEuler fractional integrator reset path and restores correct honoring of the global default FDE method in fdeint, with regression tests and an audit report documenting FDE/PDE integrator issues and prior fixes.

Sequence diagram for CaputoEuler.reset state synchronization

sequenceDiagram
  actor User
  participant CaputoEuler
  participant VarDict as bm.VarDict
  participant Variable as bm.Variable
  participant IntegratorRunner

  User->>CaputoEuler: __init__(alpha, num_memory, inits)
  CaputoEuler->>VarDict: create VarDict({v: Variable(zeros)})
  VarDict-->>CaputoEuler: f_states (VarDict of Variable)

  User->>CaputoEuler: reset(inits)
  CaputoEuler->>VarDict: f_states[key] = bm.zeros(...)
  VarDict->>Variable: update .value in place

  User->>IntegratorRunner: IntegratorRunner(CaputoEuler, dt, inits)
  User->>IntegratorRunner: run(t_end)
  IntegratorRunner->>CaputoEuler: _integral_func(...)
  CaputoEuler->>Variable: read/write memory buffer
Loading

Sequence diagram for fdeint default method selection via set_default_fdeint

sequenceDiagram
  actor User
  participant Generic as generic_module
  participant Global as _DEFAULT_FDE_METHOD
  participant FDEInt as fdeint
  participant CaputoEuler
  participant CaputoL1Schema

  User->>Generic: set_default_fdeint("euler")
  Generic->>Global: set _DEFAULT_FDE_METHOD = "euler"

  User->>FDEInt: fdeint(alpha, num_memory, inits, method=None)
  FDEInt->>Global: read _DEFAULT_FDE_METHOD
  FDEInt-->>FDEInt: method = _DEFAULT_FDE_METHOD
  alt method == "euler"
    FDEInt->>CaputoEuler: construct CaputoEuler(...)
  else method == "l1"
    FDEInt->>CaputoL1Schema: construct CaputoL1Schema(...)
  end
  FDEInt-->>User: return chosen integrator
Loading

File-Level Changes

Change Details Files
Ensure CaputoEuler.f_states remains composed of registered bm.Variable entries across resets so IntegratorRunner and JAX state tracking stay consistent.
  • Initialize f_states as a bm.VarDict of bm.Variable buffers instead of a plain dict, removing the need for register_implicit_vars on the mapping itself.
  • Update reset() to assign new zeroed buffers through the VarDict so underlying Variable values are updated in place while preserving Variable identity.
  • Document the VarDict semantics in a reset() comment to clarify why in-place updates are required for JAX/stateful usage.
brainpy/integrators/fde/Caputo.py
Make fdeint correctly use the globally configured default FDE method when the method argument is omitted and add coverage for both the reset bug and default-method behavior.
  • Change fdeint signature so method defaults to None and dt is typed as an optional float, allowing the internal _DEFAULT_FDE_METHOD fallback to take effect.
  • Add tests verifying that CaputoEuler.reset preserves Variable-typed memory and that a reset-and-run trajectory matches a fresh integrator run under IntegratorRunner.
  • Add a generic-level test confirming that set_default_fdeint is respected when method is omitted and that different defaults select CaputoEuler vs CaputoL1Schema.
  • Add an issues-found markdown report documenting validated numerics, fixed historical bugs, and remaining style-level findings for FDE/PDE integrators.
brainpy/integrators/fde/generic.py
brainpy/integrators/fde/Caputo_test.py
docs/issues-found-20260619-integrators-fde-pde.md

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

@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 reviewed your changes and they look great!


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 documentation Improvements or additions to documentation tests labels Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant