feat: real-worm behavioural-thermotaxis validation (T7, second modality â honest PARTIAL) - #269
Conversation
A second, non-gating real-worm behavioural-validation arm folded into Phase 6a before the T9a synthesis: extend the Logbook-035 chemotaxis validation to thermotaxis (a MUST behaviour) so the biologically-validated-substrate claim spans modalities. Reuses the 035 capture/metrics/grading/harness with a homeostatic-setpoint covariate (thermal error toward the comfort band). MLP primary + connectome companion, n>=8, behaviour-level reference (Ryu & Samuel 2002; thermal klinotaxis). Direct doc task under phase6-tracking, no new OpenSpec change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
âĶ(capture + reference) Author the OpenSpec change (course-corrected from the initial "no change" call: this extends the archived realworm-behavioural-validation capability with a new capture modality + thermal reference â real capability code â so it warrants a reviewed change). Self-reviewed via nematode-review-spec; fixed the citation (Luo et al. 2014 primary), the D5 specificity-control claim (thermotaxis_mode: derivative IS the analogue of 035's food-derivative control), and the tracker note (now points at this change, sign-only references). §1 capture modality (byte-identical when food): - SensingConfig.capture_behaviour_modality: food | thermotaxis (default food). - Agent _behaviour_capture_fields helper: food returns today's values; thermotaxis returns the homeostatic setpoint drive -|T - Tc|, its one-step derivative, and the live toward-comfort direction â so the existing bias-curve metrics apply unchanged. Tests: food byte-identical; thermotaxis records the setpoint drive + live thermal gradient. §2 thermal reference + modality-aware loading + harness flag: - data/thermotaxis/behavioural_bias_signatures.json (four sign-only statistics; Luo 2014 / Ryu & Samuel 2002 / Clark 2007) + _default_bias_signatures_thermotaxis fallback + load_bias_signatures(modality=...); explicit missing path still raises. - Harness --modality food|thermotaxis grades against the modality reference set + records the modality in the summary. Tests for the thermotaxis reference set. Remaining (under the change): §3 thermotaxis-dominant config â §4 smoke (PAUSE) â §5 panels â §6 logbook 036. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Audit of the thermotaxis eval (verifying no bugs before the panel) exposed a latent bug in the committed curving-rate floor: `suggest_min_path_len` uses 0.25x the median stride, which collapses toward 0 when the worm PARKS (a converged thermotaxis worm dwelling at its comfort target â median stride 0.008mm, 74% of steps <0.1mm). The collapsed floor let the dtheta/path_len creep artifact through and inflated the weathervane wildly (a smoke read +12.8, ~99% artifact; the true slope is ~+0.2-0.5). Fall back to the median *moving* stride (strides above 0.1x the max) only when the raw median has collapsed below that fraction of the max â so a continuously-moving worm (e.g. all of 035's foraging arms) keeps the raw-median floor byte-identical (verified: the three 035 panel JSONs regenerate with unchanged values), while a parked worm floors at the true stride scale. 035 wasn't affected in-flight because its foraging worm moves continuously (median stride ~1mm); thermotaxis exposed the fragility. Regression test added. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
âĶIAL) Second real-worm validation modality (non-gating). On the faithful linear-gradient Tc-seeking assay (MLP, n=4): the thermotaxis WEATHERVANE is reproduced weakly but robustly (theta-free slope +0.020, 95% CI [+0.010,+0.031], all seeds positive, ~5x weaker than chemotaxis) and a derivative-sensing specificity control confirms it is sensor-driven (collapses to +0.000). Thermal KLINOKINESIS is ABSENT in both sensing modes â the substrate reproduces the spatial-steering half of thermotaxis but not the biased-random-walk, because the continuous-Gaussian head has a state-independent std (can't stochastically random-walk; sharpens 035 too) and the RL worm migrates-and-parks rather than isothermal-tracks (temperature isn't consumable -> static endpoint). A genuine behavioural difference motivating Phase 7; chemotaxis (035) remains the strong validation of record. Logbook 036 + supporting artefacts (2 per-arm JSONs + 2 figures), README row, T7.validation.thermotaxis ticked, the two validation configs, the capture_behaviour_modality + --modality docs in AGENTS.md, and the change design/tasks updated to the honest scope (radial-spot geometry rejected as assay-shopping). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
âĶtring; JSON eof Full pre-commit run -a caught two over-length lines (the capture_behaviour_modality comment + a thermotaxis reference-test docstring) and normalised the two 036 supporting JSONs' end-of-file. No behavioural change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Change complete: thermotaxis capture modality + thermal reference + harness --modality merged into the realworm-behavioural-validation capability (+4 requirements). All §1-§7 task boxes ticked. Result: Logbook 036 (weathervane weakly reproduced + sensor-driven; klinokinesis absent â a behavioural difference). Archived to 2026-07-06-add-realworm-thermotaxis-validation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Branch-review findings (fail-loud instead of silent-wrong): - load_bias_signatures(modality=...) now raises ValueError on an unknown modality instead of silently falling back to the FOOD references (which would grade thermotaxis captures against Pierce-Shimomura ranges + wrong citations). - run_simulation warns when capture_behaviour_modality=thermotaxis but thermotaxis is disabled (the capture would silently fall back to the food drive, recording a non-thermotactic trajectory). Tests: the toward-comfort direction FLIP when T > Tc (the previously-untested `else tgrad[1] + pi` branch â base above Tc); the unknown-modality raise. Also verified in review (no change needed): capture math exact; food-modality byte-identical; thermotaxis JSON matches the hardcoded fallback (no drift); configs parse; no planning-label refs in the new code. The floor's fully-parked edge (no stride > 0.1x max) is latent + unreachable in practice (a never-moving worm yields no measurable curving) â noted, not fixed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. ð âđïļ Recent review infoâïļ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ð Files selected for processing (4)
ð§ Files skipped from review as they are similar to previous changes (4)
ð WalkthroughWalkthroughAdds thermotaxis behavioural capture alongside chemotaxis, with modality-aware thermotaxis references, grading, scenario configs, OpenSpec/spec updates, and logbook/tracker documentation. It also hardens path-length estimation for parked trajectories and adds tests for the new modality paths. ChangesReal-worm behavioural-thermotaxis validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
ðĨ Pre-merge checks | â 5â Passed checks (5 passed)
âĻ Finishing Touchesð Generate docstrings
ð§Š Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ð§đ Nitpick comments (3)
packages/quantum-nematode/quantumnematode/validation/behavioural_curves.py (1)
242-261: ð Maintainability & Code Quality | ðĩ Trivial | ⥠Quick winAdd Parameters/Returns sections to the docstring.
The rewritten docstring is detailed but omits the NumPy-style
Parameters/Returnssections (kin,fraction, and thefloatreturn aren't documented in that format), unlikeload_bias_signatureselsewhere in this PR which follows full NumPy style.ð Proposed docstring structure
def suggest_min_path_len(kin: Sequence[StepKinematics], fraction: float = 0.25) -> float: """Return a curving-rate displacement floor: ``fraction`` x the typical *moving* stride. Scale-free (data-driven): excludes creep/dwell steps whose tiny ``path_len`` would otherwise make ``dtheta / path_len`` explode. The scale is the raw median stride, EXCEPT when that median has collapsed below ``_MOVING_STRIDE_FRACTION`` of the largest stride â i.e. the worm parks (a converged thermotaxis worm dwelling at its comfort target) â in which case it falls back to the median of the *moving* strides so the floor stays at the true stride scale rather than letting the creep artifact through. A continuously-moving worm keeps the raw-median floor unchanged. - 0.0 when there are no strides. + + Parameters + ---------- + kin : Sequence[StepKinematics] + Per-step kinematics to derive the stride-length scale from. + fraction : float + Multiplier applied to the derived stride scale. + + Returns + ------- + float + The suggested minimum path-length floor, or ``0.0`` when there are no usable strides. """ðĪ Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/quantum-nematode/quantumnematode/validation/behavioural_curves.py` around lines 242 - 261, The docstring for suggest_min_path_len is missing NumPy-style Parameters and Returns sections. Update the existing docstring to document kin, fraction, and the float return value in the same style used by load_bias_signatures, while keeping the current explanatory text intact.packages/quantum-nematode/quantumnematode/agent/agent.py (1)
983-1002: ð Maintainability & Code Quality | ðĩ Trivial | ⥠Quick winAdd NumPy-style Parameters/Returns sections to the docstring.
The docstring documents the return semantics via prose but omits the standard
Parameters/Returnssections for the 6 parameters and returned tuple.As per coding guidelines, "Write NumPy-style docstrings in Python code."
ð Proposed docstring fix
def _behaviour_capture_fields( # noqa: PLR0913 self, sensing: SensingConfig, temporal: dict, food_grad_dir: float, food_grad_strength: float, sensing_pos: tuple[float, float], temperature: float | None, ) -> tuple[float, float, float, float]: """Return the captured drive fields, selected by ``capture_behaviour_modality``. - The tuple is ``(drive, drive-derivative, toward-drive direction, gradient strength)``: + Parameters + ---------- + sensing : SensingConfig + Sensing configuration (reads ``capture_behaviour_modality``). + temporal : dict + Temporal sensing fields, used for the "food" fallback. + food_grad_dir : float + Live food-gradient direction (food modality only). + food_grad_strength : float + Live food-gradient strength (food modality only). + sensing_pos : tuple[float, float] + Position to sample the thermal gradient at (thermotaxis modality only). + temperature : float | None + Current temperature at the agent's position, if thermotaxis is enabled. + Returns + ------- + tuple[float, float, float, float] + ``(drive, drive-derivative, toward-drive direction, gradient strength)``:ðĪ Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/quantum-nematode/quantumnematode/agent/agent.py` around lines 983 - 1002, Update the docstring for _behaviour_capture_fields to follow NumPy style by adding explicit Parameters and Returns sections. Document all six inputs on the method signature (self, sensing, temporal, food_grad_dir, food_grad_strength, sensing_pos, temperature) and describe the returned 4-tuple with its element meanings. Keep the existing behavioral description, but move the prose into the structured returns/parameter entries so the docstring matches the projectâs Python docstring guidelines.packages/quantum-nematode/tests/quantumnematode_tests/agent/test_behaviour_capture.py (1)
100-129: ð Maintainability & Code Quality | ðĩ Trivial | ⥠Quick winDuplicate agent/env/brain construction across both new tests.
Both tests repeat the same
Continuous2DEnvironment+ConnectomePPOBrain+QuantumNematodeAgentboilerplate, differing only inThermotaxisParams.base_temperature. Consider extending the existing_agent()helper to accept an optionalthermotaxisparam andcapture_behaviour_modality.Also applies to: 144-173
ðĪ Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/quantum-nematode/tests/quantumnematode_tests/agent/test_behaviour_capture.py` around lines 100 - 129, The new tests duplicate the same `Continuous2DEnvironment`, `ConnectomePPOBrain`, and `QuantumNematodeAgent` setup in `test_behaviour_capture.py`. Refactor the existing `_agent()` helper to accept optional `thermotaxis` and `capture_behaviour_modality` parameters, and have both tests call that helper instead of rebuilding the agent/env/brain inline. Keep the differing `ThermotaxisParams.base_temperature` values as the only per-test variation.
ðĪ Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/experiments/logbooks/036-realworm-thermotaxis-validation.md`:
- Around line 74-88: The Îļ-free confidence interval in the
weathervane/derivative-control summary is inconsistent with the supporting data.
Update the reported interval in this logbook entry where the thermal weathervane
collapse is described so it matches the `klinotaxis_all` values from
`derivative-control-curves.json` (the interval should reflect the rounded JSON
CI), and keep the surrounding `weathervane slope (Îļ-free)` / collapse wording
unchanged.
---
Nitpick comments:
In `@packages/quantum-nematode/quantumnematode/agent/agent.py`:
- Around line 983-1002: Update the docstring for _behaviour_capture_fields to
follow NumPy style by adding explicit Parameters and Returns sections. Document
all six inputs on the method signature (self, sensing, temporal, food_grad_dir,
food_grad_strength, sensing_pos, temperature) and describe the returned 4-tuple
with its element meanings. Keep the existing behavioral description, but move
the prose into the structured returns/parameter entries so the docstring matches
the projectâs Python docstring guidelines.
In `@packages/quantum-nematode/quantumnematode/validation/behavioural_curves.py`:
- Around line 242-261: The docstring for suggest_min_path_len is missing
NumPy-style Parameters and Returns sections. Update the existing docstring to
document kin, fraction, and the float return value in the same style used by
load_bias_signatures, while keeping the current explanatory text intact.
In
`@packages/quantum-nematode/tests/quantumnematode_tests/agent/test_behaviour_capture.py`:
- Around line 100-129: The new tests duplicate the same
`Continuous2DEnvironment`, `ConnectomePPOBrain`, and `QuantumNematodeAgent`
setup in `test_behaviour_capture.py`. Refactor the existing `_agent()` helper to
accept optional `thermotaxis` and `capture_behaviour_modality` parameters, and
have both tests call that helper instead of rebuilding the agent/env/brain
inline. Keep the differing `ThermotaxisParams.base_temperature` values as the
only per-test variation.
ðŠ Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
âđïļ Review info
âïļ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f8d4bf16-c244-4dd1-a456-2d2ba9ae728a
â Files ignored due to path filters (2)
docs/experiments/logbooks/supporting/036-realworm-thermotaxis-validation/klinotaxis-turn-rate-vs-dcdt.pngis excluded by!**/*.pngdocs/experiments/logbooks/supporting/036-realworm-thermotaxis-validation/klinotaxis-weathervane.pngis excluded by!**/*.png
ð Files selected for processing (24)
AGENTS.mdconfigs/scenarios/thermal_foraging/mlpppo_small_continuous2d_thermotaxis_seeking_derivative.ymlconfigs/scenarios/thermal_foraging/mlpppo_small_continuous2d_thermotaxis_seeking_klinotaxis.ymldata/thermotaxis/behavioural_bias_signatures.jsondocs/experiments/README.mddocs/experiments/logbooks/036-realworm-thermotaxis-validation.mddocs/experiments/logbooks/supporting/036-realworm-thermotaxis-validation/derivative-control-curves.jsondocs/experiments/logbooks/supporting/036-realworm-thermotaxis-validation/klinotaxis-curves.jsonopenspec/changes/archive/2026-07-06-add-realworm-thermotaxis-validation/.openspec.yamlopenspec/changes/archive/2026-07-06-add-realworm-thermotaxis-validation/design.mdopenspec/changes/archive/2026-07-06-add-realworm-thermotaxis-validation/proposal.mdopenspec/changes/archive/2026-07-06-add-realworm-thermotaxis-validation/specs/realworm-behavioural-validation/spec.mdopenspec/changes/archive/2026-07-06-add-realworm-thermotaxis-validation/tasks.mdopenspec/changes/phase6-tracking/tasks.mdopenspec/specs/realworm-behavioural-validation/spec.mdpackages/quantum-nematode/quantumnematode/agent/agent.pypackages/quantum-nematode/quantumnematode/utils/config_loader.pypackages/quantum-nematode/quantumnematode/validation/behavioural_curves.pypackages/quantum-nematode/quantumnematode/validation/datasets.pypackages/quantum-nematode/tests/quantumnematode_tests/agent/test_behaviour_capture.pypackages/quantum-nematode/tests/quantumnematode_tests/validation/test_behavioural_curves.pypackages/quantum-nematode/tests/quantumnematode_tests/validation/test_bias_signatures.pyscripts/analysis/behavioural_chemotaxis_validation.pyscripts/run_simulation.py
Codecov Reportâ Patch coverage is ðĒ Thoughts on this report? Let us know! |
âĶngs, test dedup - pyright (the failing check): the T>Tc flip test compared get_temperature() (float | None) with `>`; coerce None -> 0.0. Type the _agent helper's capture_behaviour_modality as Literal["food","thermotaxis"] to match SensingConfig. - Logbook 036: the Îļ-free weathervane CIs in the results table + the derivative collapse prose showed 95% bounds under an "80% CIs" table; corrected to the JSON 80% CIs (MLP +0.020 [+0.013,+0.027]; derivative +0.000 [â0.008,+0.009]). The separately-labelled 95% claims in the prose are unchanged. - NumPy-style Parameters/Returns on _behaviour_capture_fields and suggest_min_path_len (matching load_bias_signatures / the package's direction). - Dedup the thermotaxis capture tests: _agent() now takes thermotaxis + capture_behaviour_modality; a _thermotaxis(base) helper leaves base_temperature as the only per-test variation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
A second real-worm behavioural-validation modality (thermotaxis), extending the archived
realworm-behavioural-validationcapability from Logbook 035. Non-gating â Gate 3 G3.d stands on chemotaxis; 035 remains the strong, complete validation of record. This is an honest partial / behavioural-difference result (Logbook 036).Result (MLP, n=4, faithful linear-gradient Tc-seeking assay)
Why â a genuine behavioural difference (motivates Phase 7)
The substrate reproduces the spatial-steering half of thermotaxis but not the biased-random-walk, for two principled reasons, reported rather than engineered around:
Method notes / integrity
â|TâTc|, toward-comfort direction), gated bycapture_behaviour_modality(defaultfoodâ byte-identical). Thermal references are sign-only (Luo et al. 2014 primary; magnitudes not literature-comparable).Testing
uv run pytest -m "not nightly"â 4138 passed, 1 skipped, 2 xfailedpre-commit run -agreen ·openspec validate --strictvalid · change archived (capability spec +4 requirements)Post-review hardening (last commit)
A branch review surfaced two wrong-modality footguns, now fixed to fail loud:
load_bias_signaturesraises on an unknown modality (was silently grading against food refs);run_simulationwarns whencapture_behaviour_modality: thermotaxisruns with thermotaxis disabled. + a test for the T>Tc toward-comfort flip.ðĪ Generated with Claude Code
Summary by CodeRabbit