Skip to content

docs: auto-generated symbol → parameter-string reference page#5508

Draft
rtimms wants to merge 4 commits into
pybamm-team:mainfrom
rtimms:docs/parameter-symbol-reference
Draft

docs: auto-generated symbol → parameter-string reference page#5508
rtimms wants to merge 4 commits into
pybamm-team:mainfrom
rtimms:docs/parameter-symbol-reference

Conversation

@rtimms
Copy link
Copy Markdown
Contributor

@rtimms rtimms commented May 11, 2026

Summary

Adds a single page that maps every Python-side parameter shorthand (e.g. param.kappa_e, param.n.prim.D, param.j0_Li_metal) to the underlying string used in pybamm.ParameterValues (e.g. \"Electrolyte conductivity [S.m-1]\"). Currently this mapping is only discoverable by reading src/pybamm/parameters/lithium_ion_parameters.py (and friends) directly, which is awkward when reading model code or implementing a new submodel.

The page is regenerated on every Sphinx build by a new extension at docs/sphinxext/generate_symbol_reference.py, so renaming a shorthand or adding a new FunctionParameter automatically updates the docs — no manual step, no checked-in artefact.

Covers:

  • LithiumIonParameters, LeadAcidParameters, GeometricParameters, ElectricalParameters, ThermalParameters, EcmParameters
  • Nested domain (.n / .s / .p) and phase (.prim / .sec) sub-objects
  • Methods returning FunctionParameter (called with placeholder Variables to discover the underlying string)
  • Derived shorthands (e.g. param.A_cc, param.chi) — listed with the constituent parameter strings they depend on

How it works

generate_symbol_reference.py is a Sphinx extension wired into docs/conf.py. On the builder-inited event it walks each parameter class's attribute graph, calls any FunctionParameter-returning methods with pybamm.Variable placeholders, and writes docs/source/api/parameters/symbol_reference.rst. The output is added to .gitignore and the existing docs/source/api/parameters/index.rst toctree.

Test plan

  • cd docs && make html builds without warnings
  • docs/_build/html/api/parameters/symbol_reference.html renders one section per parameter class with grouped tables
  • Spot-check entries: param.kappa_e(c_e, T)\"Electrolyte conductivity [S.m-1]\", param.n.prim.D(c_s, T)\"Negative particle diffusivity [m2.s-1]\", etc.
  • After renaming or adding a shorthand in src/pybamm/parameters/*.py, the next docs build picks it up automatically.

🤖 Generated with Claude Code

Adds a Sphinx extension that walks each parameter class in
src/pybamm/parameters/ on every docs build and writes
docs/source/api/parameters/symbol_reference.rst — a single page mapping
every Python-side shorthand (e.g. param.kappa_e, param.n.prim.D) to its
underlying ParameterValues string (e.g. "Electrolyte conductivity
[S.m-1]"). The output is regenerated each build and gitignored, so new
parameters and renames are picked up automatically with no manual step.

Covers LithiumIonParameters, LeadAcidParameters, GeometricParameters,
ElectricalParameters, ThermalParameters and EcmParameters, including
nested domain (.n/.s/.p) and phase (.prim/.sec) sub-objects, plus
FunctionParameter-returning methods called with placeholder Variables.
@rtimms rtimms requested a review from a team as a code owner May 11, 2026 14:21
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.18%. Comparing base (ce1a240) to head (175c7d1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5508      +/-   ##
==========================================
+ Coverage   98.09%   98.18%   +0.09%     
==========================================
  Files         338      338              
  Lines       31246    31246              
==========================================
+ Hits        30650    30679      +29     
+ Misses        596      567      -29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rtimms rtimms marked this pull request as draft May 12, 2026 07:00
rtimms and others added 2 commits May 12, 2026 09:34
Three follow-ups to the symbol-reference page:

- Derived rows now render the actual expression (e.g.
  `param.A_cc → "Electrode width [m] * Electrode height [m] * Number of
  electrodes connected in parallel to make a cell"`) instead of a flat
  list of constituent parameter strings, which was useless on its own.
  Long expressions (e.g. ocv_init) are shown in full since they are
  still grep-able and the cells scroll.

- Float literals that are exact reciprocals of small integers are
  rewritten symbolically (e.g. `0.0002777777777777778` →
  `(1/3600)`), so seconds-to-hours conversions and similar unit
  factors print as fractions rather than precomputed floats.

- The brittle placeholder dictionary mapping arg names to
  pybamm.Variable instances is gone. `_call_method` now passes
  `pybamm.Variable(arg_name)` for every positional arg and falls back
  to defaults or 0 only if the call raises. New methods need no
  maintenance.

- Added a "Domain and phase sub-objects" section explaining that
  `.n` / `.s` / `.p` are electrode/separator sub-objects, `.prim` /
  `.sec` are particle-phase sub-objects, and the underlying
  parameter string gains a "Primary:" / "Secondary:" prefix when
  used with a composite ("particle phases": "2") electrode.
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.

1 participant