Skip to content

Conversation

@chaoming0625
Copy link
Member

@chaoming0625 chaoming0625 commented Jan 19, 2026

Summary by Sourcery

Refactor the package structure by extracting morphology and integrator functionality into dedicated sub-packages, update dependencies for the latest BrainPy ecosystem, and refresh documentation and examples to match the new APIs and branding.

Enhancements:

  • Group all morphology-related code under the new braincell.morph sub-package and update imports accordingly.
  • Group all integrator and solver code under the new braincell.quad sub-package and adapt neuron, channel, synapse, and compartment modules to use it.
  • Tighten core dependencies (brainstate and brainpy) to newer minimum versions for improved compatibility.
  • Align project branding and copyright headers with the BrainX Ecosystem across the codebase.

Build:

  • Update dependency version pins in requirements.txt and pyproject.toml to require newer brainstate and brainpy releases.

CI:

  • Refresh GitHub Actions workflow versions for checkout and artifact actions, and improve the publishing workflow configuration.

Documentation:

  • Extend and reorganize release notes to document versions 0.0.5–0.0.7, including new features and refactors.
  • Update API and index documentation to reflect the new module layout, integration/morphology namespaces, and ecosystem messaging.
  • Adjust auto-generated docs configuration and author metadata to match the new BrainX Ecosystem branding.

Tests:

  • Relocate morphology and integrator-related tests into their new sub-packages without changing behavior.

Chores:

  • Normalize copyright headers across source, examples, and tests and update README wording about the broader ecosystem.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 19, 2026

Reviewer's Guide

Refactors the project structure by moving morphology code into a new braincell.morph package and all integrators/solvers into a new braincell.quad package, updates imports and public API to match, refreshes documentation and changelogs for versions 0.0.5–0.0.7, bumps core BrainPy ecosystem dependencies, and standardizes copyright/branding to BrainX Ecosystem.

Class diagram for refactored integrator and morphology core types

classDiagram
  class HHTypedNeuron {
  }

  class IonChannel {
  }

  class Channel {
  }

  class Ion {
  }

  class SingleCompartment {
  }

  class MultiCompartment {
  }

  class Morphology {
    +from_swc(filename)
    +from_asc(filename)
    +visualize()
  }

  class Segment {
  }

  class Section {
  }

  class CylinderSection {
  }

  class PointSection {
  }

  class BranchingTree {
  }

  class DiffEqModule {
  }

  class DiffEqState {
  }

  class IndependentIntegration {
  }

  class quad_integrators {
    +euler_step(target, args)
    +rk4_step(target, args)
    +exp_euler_step(target, args)
    +ind_exp_euler_step(target, args, excluded_paths)
    +backward_euler_step(target, args)
    +implicit_euler_step(target, args)
    +crank_nicolson_step(target, args)
    +staggered_step(target, args)
  }

  class VoltageSolver {
  }

  class SodiumChannel {
  }

  class PotassiumChannel {
  }

  class CalciumChannel {
  }

  class HyperpolarizationActivatedChannel {
  }

  %% Inheritance and implementation
  SingleCompartment --|> HHTypedNeuron
  MultiCompartment --|> HHTypedNeuron

  IonChannel --|> Channel
  SodiumChannel --|> Channel
  PotassiumChannel --|> Channel
  CalciumChannel --|> Channel
  HyperpolarizationActivatedChannel --|> Channel

  %% Morphology composition
  Morphology o-- Section
  Section o-- Segment
  CylinderSection --|> Section
  PointSection --|> Section
  Morphology --> BranchingTree

  %% Integration protocol relations
  HHTypedNeuron ..> DiffEqModule
  HHTypedNeuron ..> DiffEqState
  HHTypedNeuron ..> IndependentIntegration

  quad_integrators ..> DiffEqModule
  quad_integrators ..> DiffEqState
  quad_integrators ..> IndependentIntegration

  VoltageSolver ..> DiffEqState
  MultiCompartment ..> VoltageSolver

  Channel ..> DiffEqState
  SodiumChannel ..> IndependentIntegration
Loading

File-Level Changes

Change Details Files
Introduce dedicated sub-packages for morphology and integrators and wire them into the public API.
  • Moved morphology modules and tests into braincell/morph/ (including _morphology, branch tree, ASC/SWC loaders, and utilities) and updated their internal imports accordingly.
  • Moved all integrator/solver modules and tests into braincell/quad/ (backward/implicit/exp Euler, RK, staggered, voltage solver, diffrax, protocol, util, and integrator registry) and fixed imports to use braincell._misc and braincell._typing where appropriate.
  • Updated braincell.init to re-export from braincell.morph and braincell.quad instead of importing morphology/integrator symbols directly, simplifying the top-level namespace.
  • Adjusted SingleCompartment and MultiCompartment to import get_integrator, DiffEqState, and IndependentIntegration from braincell.quad.
  • Updated ion and channel modules to import DiffEqState (and IndependentIntegration) from braincell.quad instead of the old _integrator_protocol module.
braincell/__init__.py
braincell/_multi_compartment.py
braincell/_single_compartment.py
braincell/_base.py
braincell/morph/_morphology.py
braincell/morph/_branch_tree.py
braincell/morph/_from_asc.py
braincell/morph/_from_swc.py
braincell/morph/_utils.py
braincell/morph/_morphology_test.py
braincell/morph/_utils_test.py
braincell/quad/_integrator.py
braincell/quad/_integrator_protocol.py
braincell/quad/_integrator_util.py
braincell/quad/_integrator_exp_euler.py
braincell/quad/_integrator_backward_euler.py
braincell/quad/_integrator_implicit.py
braincell/quad/_integrator_runge_kutta.py
braincell/quad/_integrator_voltage_solver.py
braincell/quad/_integrator_staggered.py
braincell/quad/_integrator_diffrax.py
braincell/quad/_integrator_exp_euler_test.py
braincell/quad/_integrator_runge_kutta_test.py
braincell/ion/calcium.py
braincell/channel/calcium.py
braincell/channel/hyperpolarization_activated.py
braincell/channel/potassium.py
braincell/channel/potassium_calcium.py
braincell/channel/sodium.py
braincell/morph/__init__.py
braincell/quad/__init__.py
Update documentation and changelogs to describe new structure and recent releases.
  • Added detailed release notes for versions 0.0.5 and 0.0.6 to docs/apis/changelog.md and added 0.0.7 release notes to the top-level changelog.md, including structural refactor description.
  • Updated API docs to reflect the new braincell.morph and braincell.quad module layout, simplifying the index and removing the old structure page.
  • Adjusted docs/auto_generater.py to reference braincell.quad in the commented integration module generation section.
  • Tweaked README wording for the ecosystem section to clarify BrainCell’s role.
docs/apis/changelog.md
changelog.md
docs/apis/braincell.rst
docs/apis/braincell.channel.rst
docs/apis/integration.rst
docs/apis/morphology.rst
docs/index.rst
docs/auto_generater.py
README.md
Align metadata, copyrights, and dependencies with the BrainX ecosystem.
  • Rebranded copyright headers across core modules, tests, examples, dev scripts, and docs from "BDP Ecosystem" to "BrainX Ecosystem".
  • Updated docs/conf.py author to "BrainX Ecosystem".
  • Bumped brainstate and brainpy versions in requirements.txt and synchronized brainpy version in pyproject.toml dependencies to >=2.7.5.
  • Updated references to braincell._integrator in docs/comments to braincell.quad where relevant.
braincell/_base.py
braincell/_base_test.py
braincell/_misc.py
braincell/_typing.py
braincell/_multi_compartment.py
braincell/_single_compartment.py
braincell/ion/__init__.py
braincell/ion/calcium.py
braincell/ion/potassium.py
braincell/ion/sodium.py
braincell/channel/calcium.py
braincell/channel/hyperpolarization_activated.py
braincell/channel/potassium.py
braincell/channel/potassium_calcium.py
braincell/channel/sodium.py
braincell/neuron/__init__.py
braincell/neuron/deprecation_test.py
braincell/synapse/__init__.py
braincell/synapse/markov.py
braincell/morph/_morphology.py
braincell/morph/_branch_tree.py
braincell/morph/_from_asc.py
braincell/morph/_from_swc.py
braincell/morph/_utils.py
braincell/morph/_morphology_test.py
braincell/morph/_utils_test.py
braincell/quad/_integrator.py
braincell/quad/_integrator_backward_euler.py
braincell/quad/_integrator_diffrax.py
braincell/quad/_integrator_exp_euler.py
braincell/quad/_integrator_implicit.py
braincell/quad/_integrator_protocol.py
braincell/quad/_integrator_runge_kutta.py
braincell/quad/_integrator_staggered.py
braincell/quad/_integrator_util.py
braincell/quad/_integrator_voltage_solver.py
dev/benchmark_sparse_solver.py
examples/MC11_simple_dendrite_model.py
examples/MC11_simple_dendrite_model_fitting_by_adam.py
examples/MC11_simple_dendrite_model_simulation.py
examples/MC13_golgi_model/braincell_simulation.py
examples/SC01_fitting_a_hh_neuron.py
examples/SC02_calcium_activation_functions.py
examples/SC03_COBA_HH_2007_braincell.py
examples/SC04_hh_neuron.py
examples/SC05_thalamus_single_compartment_neurons.py
examples/SC06_unified_thalamus_model.py
examples/SC07_Straital_beta_oscillation_2011.py
docs/conf.py
requirements.txt
pyproject.toml
README.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

@chaoming0625
Copy link
Member Author

@sourcery-ai title

@sourcery-ai sourcery-ai bot changed the title Morph Refactor morphology and integrators into morph/quad subpackages Jan 19, 2026
Copy link
Contributor

@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 found 3 issues, and left some high level feedback:

  • In quad/_integrator_exp_euler.py the @set_module_as('braincell') decorator is still used but the import of set_module_as was removed, which will raise a NameError at import time—either reintroduce the import (from braincell._misc) or drop the decorator.
  • The new braincell.morph and braincell.quad packages have empty __init__.py files while braincell/__init__.py now does from .morph import * and from .quad import *; if you intend to preserve the previous public API, you should re-export the key symbols (e.g. Morphology, Segment, integrator functions, protocols) from those package __init__ modules.
  • There are now several places importing from the new sub-packages (e.g. from .quad import DiffEqState, IndependentIntegration), but any remaining external code or docs that reference the old private modules (like braincell._integrator_protocol, braincell._morphology) will break; consider adding thin shims or explicit deprecation paths if backward compatibility is desired.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `quad/_integrator_exp_euler.py` the `@set_module_as('braincell')` decorator is still used but the import of `set_module_as` was removed, which will raise a NameError at import time—either reintroduce the import (from `braincell._misc`) or drop the decorator.
- The new `braincell.morph` and `braincell.quad` packages have empty `__init__.py` files while `braincell/__init__.py` now does `from .morph import *` and `from .quad import *`; if you intend to preserve the previous public API, you should re-export the key symbols (e.g. `Morphology`, `Segment`, integrator functions, protocols) from those package `__init__` modules.
- There are now several places importing from the new sub-packages (e.g. `from .quad import DiffEqState, IndependentIntegration`), but any remaining external code or docs that reference the old private modules (like `braincell._integrator_protocol`, `braincell._morphology`) will break; consider adding thin shims or explicit deprecation paths if backward compatibility is desired.

## Individual Comments

### Comment 1
<location> `braincell/quad/_integrator_exp_euler.py:179` </location>
<code_context>


 @set_module_as('braincell')
-def ind_exp_euler_step(target: DiffEqModule,  *args, excluded_paths=()):
+def ind_exp_euler_step(target: DiffEqModule, *args, excluded_paths=()):
</code_context>

<issue_to_address>
**issue (bug_risk):** set_module_as is still used here but its import was removed, which will cause a NameError at runtime.

Please reintroduce the missing import for this decorator, e.g. `from braincell._misc import set_module_as` or an equivalent relative import that matches the new package layout, so the module can be imported without error.
</issue_to_address>

### Comment 2
<location> `docs/apis/braincell.rst:9-18` </location>
<code_context>
-   structure.rst
-   integration.rst
-   morphology.rst
+Base Class for Cell Modeling
+----------------------------
+
+.. autosummary::
+   :toctree: generated/
+   :nosignatures:
+   :template: classtemplate.rst
+
+    HHTypedNeuron
+    SingleCompartment
+    MultiCompartment
+
+
+
+Base Class for Ion Channels
+---------------------------
+
</code_context>

<issue_to_address>
**suggestion (typo):** Consider using plural "Base Classes" in these section headings to match the multiple classes listed.

Since each section lists multiple classes (e.g., `HHTypedNeuron`, `SingleCompartment`, `MultiCompartment`), updating the headings to "Base Classes for Cell Modeling" and "Base Classes for Ion Channels" would be more natural and grammatically accurate.

Suggested implementation:

```
Base Classes for Cell Modeling
------------------------------

```

There is likely a similar section later in the same file that currently reads:

`Base Class for Ion Channels`
with an underline of dashes.  
That heading should be updated analogously to:

`Base Classes for Ion Channels`

and the underline length should be adjusted (or simply extended) to at least match the new title length.
</issue_to_address>

### Comment 3
<location> `docs/apis/changelog.md:52` </location>
<code_context>
+    - `SC03_COBA_HH_2007_braincell.py`
+    - `SC05_thalamus_single_compartment_neurons.py`
+    - `SC06_unified_thalamus_model.py`
+    - `SC07_Straital_beta_oscillation_2011.py`
+    - `MC11_simple_dendrite_model.py`
+    - `MC13_golgi_model/` simulations
</code_context>

<issue_to_address>
**question (typo):** Check spelling of "Straital" in the example script name.

"Straital" in `SC07_Straital_beta_oscillation_2011.py` is likely a misspelling of the anatomical term "Striatal". If so, please update the filename and this reference accordingly, or add a brief note if the current name is intentional.

```suggestion
    - `SC07_Striatal_beta_oscillation_2011.py`
```
</issue_to_address>

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.

Comment on lines +9 to +18
Base Class for Cell Modeling
----------------------------

.. autosummary::
:toctree: generated/
:nosignatures:
:template: classtemplate.rst

HHTypedNeuron
SingleCompartment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (typo): Consider using plural "Base Classes" in these section headings to match the multiple classes listed.

Since each section lists multiple classes (e.g., HHTypedNeuron, SingleCompartment, MultiCompartment), updating the headings to "Base Classes for Cell Modeling" and "Base Classes for Ion Channels" would be more natural and grammatically accurate.

Suggested implementation:

Base Classes for Cell Modeling
------------------------------

There is likely a similar section later in the same file that currently reads:

Base Class for Ion Channels
with an underline of dashes.
That heading should be updated analogously to:

Base Classes for Ion Channels

and the underline length should be adjusted (or simply extended) to at least match the new title length.

- `SC03_COBA_HH_2007_braincell.py`
- `SC05_thalamus_single_compartment_neurons.py`
- `SC06_unified_thalamus_model.py`
- `SC07_Straital_beta_oscillation_2011.py`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (typo): Check spelling of "Straital" in the example script name.

"Straital" in SC07_Straital_beta_oscillation_2011.py is likely a misspelling of the anatomical term "Striatal". If so, please update the filename and this reference accordingly, or add a brief note if the current name is intentional.

Suggested change
- `SC07_Straital_beta_oscillation_2011.py`
- `SC07_Striatal_beta_oscillation_2011.py`

@chaoming0625 chaoming0625 merged commit bdf7eb8 into main Jan 19, 2026
9 checks passed
@chaoming0625 chaoming0625 deleted the morph branch January 19, 2026 04:36
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