Skip to content

Add compute_memodel_properties_from_template to avoid parent-process Cell() - #107

Open
eleftherioszisis wants to merge 5 commits into
mainfrom
feat/compute-memodel-properties-from-template
Open

eleftherioszisis wants to merge 5 commits into
mainfrom
feat/compute-memodel-properties-from-template

Conversation

@eleftherioszisis

@eleftherioszisis eleftherioszisis commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add compute_memodel_properties_from_template so me-model properties can be computed from template paths without constructing a Cell in the caller.
  • Cell() is created only inside the isolated worker (pinned to CellId("", 0)), so callers (notably obi-one) can drop their spawn/subprocess wrapper that existed only to isolate Cell() initialization.
  • Keep compute_memodel_properties(cell, ...) and compute_memodel_properties_subprocess return contracts unchanged for backwards compatibility (bit-identical to main).

Differences vs compute_memodel_properties(cell)

  • cvode (deterministic) models: results can differ from the cell-based API. This is mainly a measurement artifact, not a difference in accuracy: _probe_rheobase_and_rin averages steady-state voltage over the few irregular cvode samples in (800, 1000] ms (4–5 points on slow cells), so small changes in cvode step placement (e.g. from the caller's Cell inherited by the fork) move Rin/RMP, and through them the rheobase search bound. With fixed-interval recording both APIs agree to within solver tolerance (~0.01%). Fixing the sampling is tracked separately in Measure steady-state voltage from fixed-interval samples in rheobase/Rin probes #108, since it will shift stored calibration values.
  • StochKv/StochKv3: noise is seeded with fixed gid 0. The cell-based API usually measures gid 1 because the caller's Cell already took gid 0 before the fork. Both are valid noise samples; they are not interchangeable. Pinning gid 0 makes the new path reproducible.

cSTUT_7 (fixed step, StochKv never seeded in this probe path) matches the cell-based API bit for bit.

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
bluecellulab/tools.py 99.12% <100.00%> (+0.07%) ⬆️
tests/test_tools.py 99.44% <100.00%> (+0.28%) ⬆️

... and 2 files with indirect coverage changes

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

@eleftherioszisis eleftherioszisis changed the title Add compute_memodel_properties_from_template without requiring a parent Cell Add compute_memodel_properties_from_template to avoid parent-process Cell() Nov 18, 2026
@eleftherioszisis

Copy link
Copy Markdown
Contributor Author

Follow-up on the review (divergences / seed / exact goldens)

Decisions

  • Document and accept value changes. from_template intentionally differs from compute_memodel_properties(cell) for cvode models: no parent Cell is forked into the worker, so there is no unused ghost cell affecting CVode step sizes. That alone-in-worker path is the more accurate one; callers switching will see changed rheobase/Rin.
  • Pin stochastic seed without a public cell_id arg. The worker always builds Cell(..., cell_id=CellId("", 0)). StochKv/StochKv3 noise is therefore fixed at gid 0 and does not depend on Cell.last_id / earlier Cell constructions. Exposing cell_id on the public API was not needed for this.
  • Leave the cell-based API’s ghost cell alone for this PR (back-compat / separate change if we ever want the old path to match from_template).
  • Tests use in-repo models under tests/examples (cADpyr, hippocampus bluepyopt, cSTUT). No external SSCx/bIR checkout.

What landed

  • Docstring + PR description updated for the cvode ghost-cell story and the fixed gid-0 seed policy.
  • Exact goldens for from_template (and, where they differ, for the cell-based path), plus asserts that the two APIs diverge on cvode cells.
  • Review matrix on cADpyr: alone ID 0 == alone ID 1 == from_template; ghost+ID 1 == compute_memodel_properties(cell).
  • Hippocampus: both APIs locked and asserted different.
  • cSTUT: both APIs bit-identical (fixed step; StochKv not seeded on this probe path).
  • Mock asserts the worker always receives CellId("", 0).
  • StochKv gid sensitivity on cSTUT via re_init_rng: gid 0 vs 1 voltage traces differ (same seeding principle as StochKv3 / bIR-style models).

…oldens.

The cvode gap between compute_memodel_properties(cell) and from_template is
mainly a steady-state sampling artifact (few irregular cvode samples in the
measurement window), not a difference in accuracy. Remove the != assertions
that locked it in, reword docstrings, and use rel=1e-4 for the hippocampus
goldens, which vary across platforms (macOS arm64).
@eleftherioszisis

Copy link
Copy Markdown
Contributor Author

Thanks for the correction and the detailed evidence. I reproduced the sampling table on Linux (1432.99 / 1472.04 with cvode steps vs 1417.94 / 1417.90 at fixed 0.1 ms, 1418.06 fixed-step reference), so I agree the gap is a measurement artifact.

Addressed in 79c3ca1:

  • Docstring and PR description: dropped the "more accurate" / ghost-cell rationale; they now say cvode results can differ mainly because of steady-state sampling (to be fixed separately), and that stochastic models are seeded with gid 0.
  • Tests: removed the != assertions between the two APIs in test_compute_memodel_properties_from_template, test_compute_memodel_properties_from_template_bluepyopt_hippocampus and test_probe_worker_setups_match_from_template_and_cell_api. Kept the exact goldens and the gid-0 test.
  • Hippocampus goldens now use rel=1e-4.
  • Opened Measure steady-state voltage from fixed-interval samples in rheobase/Rin probes #108 for fixed-interval steady-state sampling (including calculate_SS_voltage_subprocess, rheobase precision, and the still-drifting Rin protocol question).

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