Skip to content

Expand Chinese documentation; add advanced examples & API refs#45

Merged
chaoming0625 merged 6 commits intomainfrom
my-feature-branch
Aug 7, 2025
Merged

Expand Chinese documentation; add advanced examples & API refs#45
chaoming0625 merged 6 commits intomainfrom
my-feature-branch

Conversation

@chaoming0625
Copy link
Copy Markdown
Collaborator

@chaoming0625 chaoming0625 commented Aug 7, 2025

Summary by Sourcery

Revise and enrich Chinese documentation across tutorials and examples, translating headings, expanding content for Channel, Ion, and Cell modules, and adding new advanced example notebooks and API reference stubs.

Documentation:

  • Translate and expand Chinese tutorials for Channel, Ion, and Cell modules with detailed modeling explanations, code examples, and images
  • Add advanced tutorial notebooks under docs/advanced_tutorial/examples for thalamic neuron models (sc05) and E-I network simulations (sc03)
  • Introduce API reference stubs for braincell.channel, braincell.ion, and braincell.synapse modules
  • Update Chinese section titles and content in microtutorials (differential_equation-zh, more-zh, rationale-zh) for consistency
  • Revise docs/index.rst and tutorials’ table of contents to integrate new examples and maintain navigation coherence

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 7, 2025

Reviewer's Guide

This PR overhauls the documentation by fully translating and expanding the Chinese tutorial notebooks for Channel, Ion, and Cell. It reorganizes each tutorial into clear “usage” and “custom modeling” sections, injects numerous code examples (including HTC neuron construction, detailed channel/ion definitions, dynamic simulations), and adds two advanced example notebooks (thalamic neuron and E-I network simulations). The advanced tutorials and API stubs are also renamed/localized, with new images and consistency updates across docs.

Class diagram for SingleCompartment and MultiCompartment neuron models

classDiagram
    class Cell {
      <<abstract>>
    }
    class SingleCompartment {
      +channels
      +add_channel()
      +simulate()
    }
    class MultiCompartment {
      +morphology
      +channels
      +add_compartment()
      +add_channel()
      +simulate()
    }
    Cell <|-- SingleCompartment
    Cell <|-- MultiCompartment
    SingleCompartment o-- Channel
    MultiCompartment o-- Channel
    MultiCompartment o-- morphology : has
    class Channel
Loading

File-Level Changes

Change Details Files
Comprehensive rewrite of docs/tutorial/channel-zh.ipynb
  • Translate headings and sections into Chinese
  • Add “现有通道调用” with simple usage examples
  • Add “自定义通道建模” covering base classes and a full ICaT_HP1992 implementation
  • Insert the HTC neuron code example using channels and MixIons
  • Embed images and links to API reference
docs/tutorial/channel-zh.ipynb
Expansion of docs/tutorial/ion-zh.ipynb
  • Translate core content to Chinese
  • Add sections “现有离子调用” and “MixIons 调用” with HH model and calcium dynamics examples
  • Demonstrate custom Ion modeling with CalciumFixed and CalciumDetailed
  • Show dynamic reversal potential simulation code
docs/tutorial/ion-zh.ipynb
Update docs/tutorial/cell-zh.ipynb
  • Translate title and add Chinese morphological overview
  • Insert Hodgkin–Huxley circuit diagram
  • Clarify Single vs MultiCompartment via morphology discussion
docs/tutorial/cell-zh.ipynb
Localize advanced tutorials and rename headings
  • Rename “Differential Equation”→“微分方程” and “More”→“更多”
  • Change “Concepts”→“补充说明”
  • Insert blank code cells placeholders
docs/advanced_tutorial/differential equation-zh.ipynb
docs/advanced_tutorial/more-zh.ipynb
docs/advanced_tutorial/rationale-zh.ipynb
Add advanced example notebooks under advanced_tutorial/examples
  • Create sc05.ipynb for thalamic neuron modeling and simulation
  • Create sc03.ipynb for E-I network construction and raster plot
  • Add supporting .rst stubs for example directories
docs/advanced_tutorial/examples/sc05.ipynb
docs/advanced_tutorial/examples/sc03.ipynb
docs/apis/braincell.channel.rst
docs/apis/braincell.ion.rst
docs/apis/braincell.synapse.rst

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
Copy Markdown
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 @chaoming0625 - I've reviewed your changes - here's some feedback:

  • This PR is extremely large and covers multiple tutorials, APIs, and example notebooks—consider splitting it into smaller, focused PRs (e.g., one per tutorial or section) to simplify review and integration.
  • There are many inline base64‐encoded images in the notebooks that bloat the diff; please move those images to external static files and reference them instead to keep diffs manageable.
  • The notebooks include extensive execution outputs and warnings—please clear outputs (or use nbstripout) before committing to reduce noise in the diff.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- This PR is extremely large and covers multiple tutorials, APIs, and example notebooks—consider splitting it into smaller, focused PRs (e.g., one per tutorial or section) to simplify review and integration.
- There are many inline base64‐encoded images in the notebooks that bloat the diff; please move those images to external static files and reference them instead to keep diffs manageable.
- The notebooks include extensive execution outputs and warnings—please clear outputs (or use nbstripout) before committing to reduce noise in the diff.

## Individual Comments

### Comment 1
<location> `docs/tutorial/ion-zh.ipynb:327` </location>
<code_context>
+    "\n",
+    "    def reset_state(self, V, batch_size=None):\n",
+    "        ca_info = self.pack_info()\n",
+    "        nodes = brainstate.graph.nodes(self, Channel, allowed_hierarchy=(1, 1)).values()\n",
+    "        self.check_hierarchies(type(self), *tuple(nodes))\n",
+    "        for node in nodes:\n",
+    "            node.reset_state(V, ca_info, batch_size=batch_size)"
+   ],
</code_context>

<issue_to_address>
Type Channel is referenced but not defined in this code cell.

'Channel' is used but not defined or imported in this cell, which may cause a NameError. Please ensure it is available in the current context.
</issue_to_address>

### Comment 2
<location> `docs/tutorial/ion-zh.ipynb:455` </location>
<code_context>
+    "    def derivative(self, C, V):\n",
+    "        ICa = self.current(V, include_external=True)\n",
+    "        drive = ICa / (2 * u.faraday_constant * self.d)\n",
+    "        drive = u.math.maximum(drive, u.math.zeros_like(drive))\n",
+    "        return drive + (self.C_rest - C) / self.tau"
+   ],
</code_context>

<issue_to_address>
The use of maximum() may mask negative calcium influx.

Setting the drive term to maximum(drive, 0) prevents modeling calcium efflux. Confirm if only inward flow is intended; otherwise, this may be too restrictive.
</issue_to_address>

### Comment 3
<location> `docs/advanced_tutorial/examples/sc05.ipynb:106` </location>
<code_context>
-    "        super().__init__(size, V_initializer=V_initializer, V_th=20. * u.mV, solver=solver)\n",
-    "\n",
-    "        # 膜面积参数\n",
-    "        self.area = 1e-3 / (2.9e-4 * u.cm** 2)\n",
-    "\n",
-    "        # 钠离子通道\n",
</code_context>

<issue_to_address>
Area calculation uses a hardcoded value that may reduce flexibility.

Parameterize the membrane area or add clear documentation explaining the chosen formula to improve code flexibility and maintainability.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    "    def __init__(\n",
    "        self,\n",
    "        size,\n",
    "        gKL=0.01 * (u.mS / u.cm **2),  # 钾漏通道电导\n",
    "        V_initializer=brainstate.init.Constant(-65. * u.mV),  # 初始膜电位\n",
    "        solver: str = 'ind_exp_euler'  # 积分方法\n",
    "    ):\n",
    "        super().__init__(size, V_initializer=V_initializer, V_th=20. * u.mV, solver=solver)\n",
    "\n",
    "        # 膜面积参数\n",
    "        self.area = 1e-3 / (2.9e-4 * u.cm** 2)\n",
=======
    "    def __init__(\n",
    "        self,\n",
    "        size,\n",
    "        gKL=0.01 * (u.mS / u.cm **2),  # 钾漏通道电导\n",
    "        V_initializer=brainstate.init.Constant(-65. * u.mV),  # 初始膜电位\n",
    "        solver: str = 'ind_exp_euler',  # 积分方法\n",
    "        membrane_area=None  # 膜面积参数,可选,默认为1e-3/(2.9e-4 cm^2)\n",
    "    ):\n",
    "        super().__init__(size, V_initializer=V_initializer, V_th=20. * u.mV, solver=solver)\n",
    "\n",
    "        # 膜面积参数\n",
    "        # 默认面积计算: 1e-3 / (2.9e-4 * u.cm**2) 来源于文献/实验数据,1e-3为细胞体积(单位L),2.9e-4为单位体积的面积(cm^2/L)\n",
    "        if membrane_area is None:\n",
    "            self.area = 1e-3 / (2.9e-4 * u.cm**2)\n",
    "        else:\n",
    "            self.area = membrane_area\n",
>>>>>>> REPLACE

</suggested_fix>

### Comment 4
<location> `docs/advanced_tutorial/examples/sc03.ipynb:98` </location>
<code_context>
-    "        self.na = braincell.ion.SodiumFixed(in_size, E=50. * u.mV)\n",
-    "        self.na.add_elem(\n",
-    "            # 最大电导\n",
-    "            INa=braincell.channel.INa_TM1991(in_size, g_max=(100. * u.mS * u.cm **-2) * area, V_sh=-63. * u.mV)\n",
-    "        )\n",
-    "\n",
</code_context>

<issue_to_address>
Multiplying g_max by area may lead to unit inconsistencies.

Since g_max is already in mS/cm^2, multiplying by area changes it to total conductance, which may not be appropriate. Please verify that INa_TM1991 expects conductance density and that this calculation does not cause a unit mismatch.
</issue_to_address>

### Comment 5
<location> `docs/advanced_tutorial/examples/sc03.ipynb:105` </location>
<code_context>
-    "        self.k = braincell.ion.PotassiumFixed(in_size, E=-90 * u.mV)\n",
-    "        self.k.add_elem(\n",
-    "            # 最大电导\n",
-    "            IK=braincell.channel.IK_TM1991(in_size, g_max=(30. * u.mS * u.cm** -2) * area, V_sh=-63. * u.mV)\n",
-    "        )\n",
-    "\n",
</code_context>

<issue_to_address>
Potential unit mismatch in g_max for potassium channel as well.

Verify whether g_max should be a conductance density or total conductance for the potassium channel to avoid incorrect simulation behavior.
</issue_to_address>

### Comment 6
<location> `docs/advanced_tutorial/examples/sc02.ipynb:88` </location>
<code_context>
+   "cell_type": "code",
+   "source": [
+    "# 生成电压序列\n",
+    "vs = u.math.arange(-100 * u.mV, 0 * u.mV, 0.1 * u.mV)"
+   ],
+   "id": "43f7945b1fe9233f",
</code_context>

<issue_to_address>
Consider including the endpoint in the voltage range.

arange excludes the stop value, so 0 mV will not be part of the sequence. Use linspace or adjust the stop value if you want to include 0 mV.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    "# 生成电压序列\n",
    "vs = u.math.arange(-100 * u.mV, 0 * u.mV, 0.1 * u.mV)"
=======
    "# 生成电压序列\n",
    "vs = u.math.arange(-100 * u.mV, 0.1 * u.mV, 0.1 * u.mV)"
>>>>>>> REPLACE

</suggested_fix>

### Comment 7
<location> `docs/apis/braincell.channel.rst:29` </location>
<code_context>
+   ICaGrc_Ma2020
+
+
+Hypterpolarization-Activated Channels
+-------------------------------------
+
</code_context>

<issue_to_address>
Typo: 'Hypterpolarization' should be 'Hyperpolarization'.

The section header contains a typo; please correct it to 'Hyperpolarization-Activated Channels'.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
Hypterpolarization-Activated Channels
-------------------------------------
=======
Hyperpolarization-Activated Channels
------------------------------------
>>>>>>> REPLACE

</suggested_fix>

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 +327 to +329
" nodes = brainstate.graph.nodes(self, Channel, allowed_hierarchy=(1, 1)).values()\n",
" self.check_hierarchies(type(self), *tuple(nodes))\n",
" for node in nodes:\n",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Type Channel is referenced but not defined in this code cell.

'Channel' is used but not defined or imported in this cell, which may cause a NameError. Please ensure it is available in the current context.

" def derivative(self, C, V):\n",
" ICa = self.current(V, include_external=True)\n",
" drive = ICa / (2 * u.faraday_constant * self.d)\n",
" drive = u.math.maximum(drive, u.math.zeros_like(drive))\n",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: The use of maximum() may mask negative calcium influx.

Setting the drive term to maximum(drive, 0) prevents modeling calcium efflux. Confirm if only inward flow is intended; otherwise, this may be too restrictive.

Comment on lines +96 to +106
" def __init__(\n",
" self,\n",
" size,\n",
" gKL=0.01 * (u.mS / u.cm **2), # 钾漏通道电导\n",
" V_initializer=brainstate.init.Constant(-65. * u.mV), # 初始膜电位\n",
" solver: str = 'ind_exp_euler' # 积分方法\n",
" ):\n",
" super().__init__(size, V_initializer=V_initializer, V_th=20. * u.mV, solver=solver)\n",
"\n",
" # 膜面积参数\n",
" self.area = 1e-3 / (2.9e-4 * u.cm** 2)\n",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Area calculation uses a hardcoded value that may reduce flexibility.

Parameterize the membrane area or add clear documentation explaining the chosen formula to improve code flexibility and maintainability.

Suggested change
" def __init__(\n",
" self,\n",
" size,\n",
" gKL=0.01 * (u.mS / u.cm **2), # 钾漏通道电导\n",
" V_initializer=brainstate.init.Constant(-65. * u.mV), # 初始膜电位\n",
" solver: str = 'ind_exp_euler' # 积分方法\n",
" ):\n",
" super().__init__(size, V_initializer=V_initializer, V_th=20. * u.mV, solver=solver)\n",
"\n",
" # 膜面积参数\n",
" self.area = 1e-3 / (2.9e-4 * u.cm** 2)\n",
" def __init__(\n",
" self,\n",
" size,\n",
" gKL=0.01 * (u.mS / u.cm **2), # 钾漏通道电导\n",
" V_initializer=brainstate.init.Constant(-65. * u.mV), # 初始膜电位\n",
" solver: str = 'ind_exp_euler', # 积分方法\n",
" membrane_area=None # 膜面积参数,可选,默认为1e-3/(2.9e-4 cm^2)\n",
" ):\n",
" super().__init__(size, V_initializer=V_initializer, V_th=20. * u.mV, solver=solver)\n",
"\n",
" # 膜面积参数\n",
" # 默认面积计算: 1e-3 / (2.9e-4 * u.cm**2) 来源于文献/实验数据,1e-3为细胞体积(单位L),2.9e-4为单位体积的面积(cm^2/L)\n",
" if membrane_area is None:\n",
" self.area = 1e-3 / (2.9e-4 * u.cm**2)\n",
" else:\n",
" self.area = membrane_area\n",

" self.na = braincell.ion.SodiumFixed(in_size, E=50. * u.mV)\n",
" self.na.add_elem(\n",
" # 最大电导\n",
" INa=braincell.channel.INa_TM1991(in_size, g_max=(100. * u.mS * u.cm **-2) * area, V_sh=-63. * u.mV)\n",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Multiplying g_max by area may lead to unit inconsistencies.

Since g_max is already in mS/cm^2, multiplying by area changes it to total conductance, which may not be appropriate. Please verify that INa_TM1991 expects conductance density and that this calculation does not cause a unit mismatch.

" self.k = braincell.ion.PotassiumFixed(in_size, E=-90 * u.mV)\n",
" self.k.add_elem(\n",
" # 最大电导\n",
" IK=braincell.channel.IK_TM1991(in_size, g_max=(30. * u.mS * u.cm** -2) * area, V_sh=-63. * u.mV)\n",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Potential unit mismatch in g_max for potassium channel as well.

Verify whether g_max should be a conductance density or total conductance for the potassium channel to avoid incorrect simulation behavior.

Comment on lines +87 to +88
"# 生成电压序列\n",
"vs = u.math.arange(-100 * u.mV, 0 * u.mV, 0.1 * u.mV)"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider including the endpoint in the voltage range.

arange excludes the stop value, so 0 mV will not be part of the sequence. Use linspace or adjust the stop value if you want to include 0 mV.

Suggested change
"# 生成电压序列\n",
"vs = u.math.arange(-100 * u.mV, 0 * u.mV, 0.1 * u.mV)"
"# 生成电压序列\n",
"vs = u.math.arange(-100 * u.mV, 0.1 * u.mV, 0.1 * u.mV)"

Comment on lines +29 to +30
Hypterpolarization-Activated Channels
-------------------------------------
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (typo): Typo: 'Hypterpolarization' should be 'Hyperpolarization'.

The section header contains a typo; please correct it to 'Hyperpolarization-Activated Channels'.

Suggested change
Hypterpolarization-Activated Channels
-------------------------------------
Hyperpolarization-Activated Channels
------------------------------------

@chaoming0625
Copy link
Copy Markdown
Collaborator Author

@sourcery-ai title

@sourcery-ai sourcery-ai Bot changed the title My feature branch Expand Chinese documentation; add advanced examples & API refs Aug 7, 2025
@chaoming0625 chaoming0625 merged commit ac9c242 into main Aug 7, 2025
24 checks passed
@chaoming0625 chaoming0625 deleted the my-feature-branch branch August 7, 2025 05:04
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