Skip to content

Conversation

@chaoming0625
Copy link
Member

@chaoming0625 chaoming0625 commented Jan 21, 2026

Summary by Sourcery

Ensure the ODE integrator always passes a default time argument and perform minor formatting cleanups.

Bug Fixes:

  • Default the 't' keyword argument to 0.0 when invoking the integral function to avoid missing-time issues during compilation and execution.

Enhancements:

  • Apply minor code formatting adjustments in the explicit Runge–Kutta integrator build method for consistency.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 21, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures the ODE integrator’s internal _call_integral method always passes a default t=0 keyword argument when none is provided, and applies minor formatting cleanups in the explicit Runge-Kutta integrator implementation.

Sequence diagram for _call_integral with default t keyword argument

sequenceDiagram
    participant Caller
    participant IntegratorBase
    participant JAX as jax
    participant JAXCore as jax_core

    Caller->>IntegratorBase: _call_integral(args, kwargs)
    IntegratorBase->>IntegratorBase: copy kwargs to new dict
    IntegratorBase->>IntegratorBase: t = kwargs.get(t, None)
    alt t is None
        IntegratorBase->>IntegratorBase: kwargs[t] = 0.0
    else t is provided
        IntegratorBase->>IntegratorBase: kwargs[t] = t
    end
    alt _during_compile is True
        IntegratorBase->>JAX: make_jaxpr(integral, return_shape=True)(**kwargs)
        JAX-->>IntegratorBase: jaxpr, out_shapes
        IntegratorBase->>JAXCore: eval_jaxpr(jaxpr.jaxpr, jaxpr.consts, *leaves(kwargs))
        JAXCore-->>IntegratorBase: outs
    else _during_compile is False
        IntegratorBase->>IntegratorBase: integral(**kwargs)
        IntegratorBase-->>Caller: result
    end
Loading

Updated class diagram for IntegratorBase and ExplicitRKIntegrator

classDiagram
    class IntegratorBase {
        <<abstract>>
        +integral
        +_call_integral(*args, **kwargs)
    }

    class ExplicitRKIntegrator {
        +variables
        +A
        +B
        +C
        +code_lines
        +parameters
        +code_scope
        +show_code
        +func_name
        +build()
    }

    IntegratorBase <|-- ExplicitRKIntegrator

    class CommonModule {
        +step(variables, dt, A, C, code_lines, parameters)
        +update(variables, dt, B, code_lines)
    }

    class CodeGenerator {
        +compile(var_dict, arg_names, return_args, fun_name, code_scope, code_lines, show_code, func_name)
    }

    ExplicitRKIntegrator ..> CommonModule : uses
    ExplicitRKIntegrator ..> CodeGenerator : uses
Loading

File-Level Changes

Change Details Files
Guarantee that integral calls receive a default time argument t=0 when not explicitly supplied.
  • Copy kwargs to a new dict at the start of _call_integral to avoid mutating the caller’s dictionary.
  • Read any existing 't' value from kwargs and, if missing or None, set it to 0.0 before calling the JAX-based integral implementation.
  • Keep the rest of the _call_integral logic (jax.make_jaxpr, eval_jaxpr, etc.) unchanged so behavior only differs in the presence of a default t.
brainpy/integrators/base.py
Apply small code-style/formatting adjustments in the ExplicitRKIntegrator implementation without changing behavior.
  • Reformat the common.step(...) call into a single line argument list.
  • Adjust the CodeGenerator creation call to put the closing parenthesis on its own line and include a trailing comma for the last keyword argument.
brainpy/integrators/ode/explicit_rk.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

Copy link

@sourcery-ai sourcery-ai bot left a comment

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 _call_integral, consider defaulting t at the call sites (or only when the target integral actually expects a t kwarg) rather than unconditionally injecting t into kwargs, to avoid surprising failures for integrals that don’t accept a t parameter.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `_call_integral`, consider defaulting `t` at the call sites (or only when the target integral actually expects a `t` kwarg) rather than unconditionally injecting `t` into `kwargs`, to avoid surprising failures for integrals that don’t accept a `t` parameter.

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.

@chaoming0625
Copy link
Member Author

@sourcery-ai title

@sourcery-ai sourcery-ai bot changed the title fix: ensure 't' keyword argument defaults to 0 in _call_integral and … Fix ODE integrator default time and JAX backend import compatibility Jan 21, 2026
@chaoming0625 chaoming0625 changed the title Fix ODE integrator default time and JAX backend import compatibility Fix ODE integrator default time and compatibility with jax>=0.9.0 Jan 21, 2026
@chaoming0625 chaoming0625 merged commit a66c0b2 into master Jan 21, 2026
18 checks passed
@chaoming0625 chaoming0625 deleted the fix-ode branch January 21, 2026 09:29
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.

2 participants