Skip to content

Add validation workflow orchestration for MEModel - #957

Merged
ilkilic merged 45 commits into
mainfrom
feature/validation-workflow
Nov 9, 2026
Merged

ilkilic merged 45 commits into
mainfrom
feature/validation-workflow

Conversation

@ilkilic

@ilkilic ilkilic commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Introduces the validation workflow architecture in OBI-One, with MEModel validation as the first implementation. This provides entity-agnostic workflow orchestration, MEModel-specific validation profiles, and ValidationResult registration with persisted-result handling and asset upload.

Motivation

Validation execution was previously handled by BlueNaaS as a thin orchestration layer calling BlueCelluLab's hardcoded run_validations(). As we move away from BlueNaaS, OBI-One takes ownership of:

  • Validation workflow orchestration
  • Entity-specific validation policies and profiles
  • ValidationResult registration and asset upload
  • Execution from tasks, notebooks, and other callers

The workflow is decoupled from the execution backend and uses BlueCelluLab's composable validation framework for protocol, measurement, and criterion handling.

What's added

obi_one/scientific/validations/

├── base.py                   # Generic ValidationWorkflow + WorkflowContext
├── registration.py           # ValidationResult registration and asset handling
└── memodel/
    ├── config.py             # Simulator configuration
    ├── names.py              # Controlled validation-name vocabulary
    ├── presets.py            # Reusable MEModel validation presets
    ├── profiles.py           # Default and thalamic validation profiles
    ├── task.py               # MEModel validation task
    ├── tests.py              # Complex validation tests
    └── workflow.py           # MEModel workflow orchestration

Architecture

ValidationWorkflow
    │
    ├── MEModelValidationWorkflow
    │       ├── downloads and prepares the ME-Model
    │       ├── selects a validation profile
    │       ├── runs BlueCelluLab validation tests
    │       └── registers TestResult objects
    │
    ├── MorphologyValidationWorkflow (future)
    └── ... (other entity types)

Usage

From a standalone process or OBI-One Task

from obi_one.scientific.validations.memodel import MEModelValidationWorkflow

workflow = MEModelValidationWorkflow(
    output_dir="./output",
    validation_profile="thalamic",
    custom_tests=[...],
)

context = workflow.setup(
    entity_id=memodel_id,
    client=client,
)

results = workflow.run(context)

workflow.register(
    results,
    context,
    client,
)

From a notebook

from obi_one.scientific.validations.registration import register_outcomes

register_outcomes(
    client=client,
    outcomes=results,
    validated_entity_id=memodel_id,
    out_dir=fig_dir,
)

Profiles

  • The default profile runs spiking and depolarization-block validations.
  • The thalamic profile runs nine validations: tonic firing, depolarization block, rebound burst, BPAP, AIS spiking, hyperpolarization, input resistance, IV curve, and FI curve.
  • Custom validation tests can be appended to a workflow.
  • The thalamic profile holds at -60 mV and uses a 0.4 nA (400 pA) tonic-firing step, matching the source ephys protocol (Hartley et al., Cell Reports 2024, Fig. 2O-R).
  • The rebound protocol uses per-model calibrated BluePyOpt currents (holding + hyperpolarization increment in nA) with a 500 ms hyperpolarization phase.
  • The BPAP protocol uses an amplitude factor of 30.0 and supports model-specific holding-current overrides.

Key Behaviors

  • Persisted-result handling: existing results are matched by validation name and validated entity.
  • Deduplication: an existing matching result is skipped by default.
  • Overwrite support: existing results can be updated explicitly.
  • Duplicate detection: multiple matching persisted results raise an error.
  • Asset upload: PDF and PNG figures use AssetLabel.validation_result_figure; validation details are uploaded as text using AssetLabel.validation_result_details.
  • Failure handling: ordinary per-result registration failures are isolated so later results can still be processed.
  • Execution-backend agnostic: the workflow makes no assumptions about whether it is called from a task, notebook, or another execution system.

Dependencies

Requires BlueCelluLab with the composable parametric validation framework:

BlueCelluLab validation framework PR

…me to TestResult

- Strip WorkflowContext to generic fields, add MEModelWorkflowContext subclass
- Rename ValidationOutcome to TestResult for clarity alongside ValidationResult
- Rename outcomes parameter to test_results for consistency
- Add depolarization_block, rebound_burst, and tonic_firing presets
  (rebound_burst and tonic_firing compute Rin-based currents for thalamic cells)
- Add tests.py with ValidationTest subclasses that don't fit the composable
  pattern: Hyperpolarization, Rin, AIS spiking, BPAP, IV curve, FI curve
- tonic_firing_preset reuses the spiking validation name as the thalamic variant
@ilkilic ilkilic self-assigned this Sep 10, 2026
@ilkilic
ilkilic marked this pull request as ready for review September 10, 2026 15:30
Matches the renamed bluecellulab SequenceProtocol API (absolute_amplitudes
bool -> amplitude_mode Literal).

@darshanmandge darshanmandge left a comment

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.

The framework looks good and fits the BlueCelluLab framework. I have put some items to change/verify.

Also:

  • bluecellulab>=2.6.99 doesn't include the validation framework. The pin needs
    bumping to the release that ships PR #90, so this can't merge before that.
  • MEModelValidationTask isn't registered in TASK_MAP or the unions, so it can't be
    launched as a task yet. Is that a planned follow-up?
  • register_outcomes turns every failure into entity_id=None, and
    ValidationTask.execute doesn't surface that. A run where every registration
    fails still finishes without an error.
  • De-duplication matches on the validation name only. If the default profile and then the
    thalamic profile run on the same entity, the second "Spiking Validation" is silently skipped
    even though its protocol is different, unless overwrite_existing=True. Worth documenting.

Add TaskType.memodel_validation, its TASK_MAP entry, and include
MEModelValidationTask in TasksUnion so the validation workflow can be
launched as a task.
Raise ValidationRegistrationError from ValidationTask.execute when any
ValidationResult fails to register, so a run where every registration
fails no longer finishes silently. Log skipped (already-existing)
results explicitly, and document that de-duplication matches on
validation name and entity only (one verdict per model).
DownloadedMEModel exposes a single morphology_path (Path), not a
morphology_paths list. Read the field directly via a _select_morphology_path
helper that raises InvalidValidationContextError when the downloaded
morphology file is missing, instead of crashing with AttributeError.
….4 nA

Thalamic tonic firing and depolarization block pre-hold the cell at -60 mV,
then inject a 0.4 nA (400 pA) step, matching the source ephys protocol
(Hartley et al., Cell Reports 2024, Fig 2O-R). The holding current to reach
-60 mV is derived per model via bluecellulab's search_hyp_current. Rheobase is
recomputed at the HOC conditions for percentage-scaled step protocols. The
default (non-thalamic) presets are unchanged.

Adds tests for the morphology path, the derived holding current, the thalamic
depol-block preset, and the rheobase recomputation.
…on names

Shorten the ValidationName vocabulary (e.g. 'Spiking Validation' instead of
'Simulatable Neuron Spiking Validation'). ION_CHANNEL_MODEL_BUILD is unchanged.
entitysdk latest (0.19.34) renamed DownloadedMEModel.morphology_path to
morphology_paths (list[Path]); read the first entry. Requires bumping the
entitysdk lock to latest. Guard test asserts the field is morphology_paths.
…submodules

Bump the entitysdk and bluecellulab pins to the latest releases (which ship
the validation framework) and relock. Published bluecellulab no longer
re-exports the validation classes from the package root, so import them from
their submodules (bluecellulab.validation.measurement / .criterion /
.protocol / .parametric_validation).
morphology_paths stages every format the entity carries (asc, swc, h5).
The HOC loads .asc or .swc, so pick by suffix instead of taking the first
entry, which was only accidentally correct.
@ilkilic

ilkilic commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review — addressed the items:

  • Task registration — MEModelValidationTask is now in TaskType, TASK_MAP, and the unions.
  • Registration failures — ValidationTask.execute raises ValidationRegistrationError if any result fails to register, so a fully-failing run no longer passes silently; skipped (already-existing) results are logged.
  • De-dup on name — documented: one name = one verdict per model, a second profile emitting the same name is a re-registration (overwrite_existing=True to replace).
  • bluecellulab pin — bumped to latest; note it also needs the IV-curve fix (Scale IV curve current range to rheobase BlueCelluLab#104 ) released before this is fully correct, so I am holding merge until that lands and I re-lock.
  • Also bumped entitysdk to latest and switched the validation imports to the submodule form, since the published bluecellulab no longer re-exports them from the package root.

The thalamic tonic-firing step is now configurable via tonic_step_current
(default 0.4 nA, the paper's 400 pA for Ecel1 to avoid depolarization block).
Spp and Spp_runaway have higher input resistance and use ~0.8 nA to show
sustained tonic firing rather than an initial rebound burst.

Also corrects stale -65 mV references in the thalamic hold comments to the
-60 mV the profile actually targets (verified: derived holding current reaches
-60 mV at the soma).
…mic pre-held tests

The tonic-firing and depolarization-block presets previously baked a separately
derived holding current into their phase amplitudes (add_hypamp=False). The
derivation searched steady-state voltage with a too-short settle window, which
undershot for high-Rin thalamic cells and gave an unreliable hold.

Use the model's calibrated holding current (emodel_properties.holding_current)
applied via add_hypamp=True instead: the presets now carry only the step on top
of that baseline. build_tests raises if the calibrated hold is zero/missing, so
a model with an unpopulated calibration fails loudly rather than validating at
its bare resting potential. Removes _derive_profile_holding_current and the
context holding_current field.

Verified on the three thalamic TRN models (Spp_runaway, Spp, Ecel): the
calibrated hold settles the cell at ~-65 mV quietly, then the step produces
sustained tonic firing; 8/9 tests pass (AIS the accepted structural fail).
Comment thread pyproject.toml Resolved
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.54502% with 122 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
obi_one/scientific/validations/memodel/tests.py 77.99% 39 Missing and 18 partials ⚠️
obi_one/scientific/validations/memodel/workflow.py 82.35% 25 Missing and 5 partials ⚠️
obi_one/scientific/validations/registration.py 90.17% 7 Missing and 4 partials ⚠️
obi_one/scientific/validations/memodel/profiles.py 92.00% 8 Missing and 2 partials ⚠️
obi_one/scientific/validations/memodel/presets.py 79.54% 6 Missing and 3 partials ⚠️
obi_one/scientific/validations/memodel/config.py 93.75% 2 Missing and 1 partial ⚠️
obi_one/scientific/validations/base.py 96.36% 2 Missing ⚠️
@@           Coverage Diff            @@
##             main     #957    +/-   ##
========================================
  Coverage   85.49%   85.49%            
========================================
  Files         360      371    +11     
  Lines       22674    23518   +844     
  Branches     2558     2656    +98     
========================================
+ Hits        19385    20107   +722     
- Misses       2768     2857    +89     
- Partials      521      554    +33     
Flag Coverage Δ
app 92.64% <ø> (ø)
lib 84.05% <85.54%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...cientific/mappings_and_registry/config_task_map.py 100.00% <ø> (ø)
obi_one/scientific/validations/__init__.py 100.00% <100.00%> (ø)
obi_one/scientific/validations/memodel/__init__.py 100.00% <100.00%> (ø)
obi_one/scientific/validations/memodel/names.py 100.00% <100.00%> (ø)
obi_one/scientific/validations/memodel/task.py 100.00% <100.00%> (ø)
obi_one/types.py 100.00% <100.00%> (ø)
obi_one/scientific/validations/base.py 96.36% <96.36%> (ø)
obi_one/scientific/validations/memodel/config.py 93.75% <93.75%> (ø)
obi_one/scientific/validations/memodel/presets.py 79.54% <79.54%> (ø)
obi_one/scientific/validations/memodel/profiles.py 92.00% <92.00%> (ø)
... and 3 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ilkilic
ilkilic requested a review from darshanmandge November 9, 2026 08:50
@ilkilic

ilkilic commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

On the codecov patch coverage: I have added unit tests for the parts with real logic, the profiles (guards + build_tests), the IV/FI/Rin/hyperpolarization/AIS checks, and the execute() orchestration, which brings those modules up (base 97%, config 95%, tests.py and profiles.py ~77%).

The remaining gap is almost all in workflow.py setup(): downloading the model, compiling mechanisms, building the bluecellulab Cell, computing rheobase/Rin. That path needs a compiled NEURON model and a live entitysdk client, so a unit test there could only mock the whole chain and assert the mocks were called which tracks the implementation rather than verifying behaviour. It's exercised end-to-end instead: the three thalamic ME-models were validated through the full workflow and registered on staging.

@darshanmandge

Copy link
Copy Markdown
Contributor

@ilkilic I don't think the new tests are running in CI, which would explain why Codecov still shows 30.2% patch coverage on the head commit (21882a3).

make test-lib-local only collects tests/obi_one and tests/launch_scripts, but the PR's tests are in tests/test_scientific/test_validations/. test_memodel_workflow.py doesn't appear in the lib or app job logs, and the numbers on head are well below the ones you listed:

File Your comment Codecov on head
base.py 97% 60%
config.py 95% 35%
tests.py ~77% 20%
profiles.py ~77% 33%

This probably started with the lib/app CI split in #1183. Could you move both test files into tests/obi_one/scientific/validations/? That would also bring them under make lint-lib, which doesn't check the current folder.

Once they run in CI we can see what is actually left uncovered. Other files have gaps too, e.g. registration.py is at 25%, though its tests are in the same folder. I'm fine discussing an exception for the parts of setup() that really need compiled NEURON mechanisms, but let's decide that from the real number.

@ilkilic

ilkilic commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Good catch, that was it. Moved both files into tests/obi_one/scientific/validations/ (pushed). Patch coverage is now 68%!

@ilkilic

ilkilic commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Pushed more tests, profiles is now 94% and registration 90%, so patch coverage is up again.

@ilkilic

ilkilic commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Correcting my earlier comment, I was too pessimistic about setup(). Added tests that mock the client and patch the Cell/rheobase/Rin calls so workflow.py is now 82% and the validation subsystem ~88%. The remaining uncovered part is the live NEURON calls.

@darshanmandge darshanmandge left a comment

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.

LGTM. Thanks @ilkilic !

@ilkilic
ilkilic merged commit 6eee607 into main Nov 9, 2026
14 checks passed
@ilkilic
ilkilic deleted the feature/validation-workflow branch November 9, 2026 14:44
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