Skip to content

Connectome rewired-null control — review nitpick follow-ups (#264) - #265

Merged
chrisjz merged 2 commits into
mainfrom
fix/connectome-controls-review-followup
Jul 5, 2026
Merged

Connectome rewired-null control — review nitpick follow-ups (#264)#265
chrisjz merged 2 commits into
mainfrom
fix/connectome-controls-review-followup

Conversation

@chrisjz

@chrisjz chrisjz commented Jul 5, 2026

Copy link
Copy Markdown
Member

Small follow-up to #264 (merged), addressing the PR review nitpicks on the connectome rewired-null control. No behaviour change — the DEGREE-STATISTICS verdict is unaffected.

Fixed

  • Public metric API — t7_continuous_ranking now exposes a public plateau_tail wrapper; the control harness imports that instead of the private _plateau_tail (drops the cross-module private coupling).
  • Manifest diagnostics — load() skips blank/#-comment lines silently but now WARNs on any other malformed line and on a duplicate (arm, seed) overwrite, so analysis issues stay traceable.
  • Robust test path — the harness test locates scripts/analysis/ by walking up to the repo root, not a hardcoded parents[5].
  • Self-loop clarification — a comment at the rewiring simple-graph guard documents that chemical self-loops (autapses) are intentionally permitted.

Skipped (with reasons)

  • Config rename (variant before sensing) — the _klinotaxis_rewired_null order matches the committed siblings _ars_depletion / _no_respawn_control; renaming would break consistency with them.
  • Reject self-loops — the real Cook connectome has 38 chemical autapses; a reject guard would crash the live rewired-null pipeline. They're legitimate structure and the swap preserves their degree contribution.

Gates

Full pytest -m "not nightly" → 4090 passed; full pre-commit run -a clean; openspec validate --specs passes.

ðŸĪ– Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a public plateau-tail ranking metric entry point for reuse across analyses.
  • Bug Fixes
    • Improved manifest loading to ignore blank/comment lines, validate expected fields, and emit warnings for malformed entries, unknown arms, and failed plateau-tail parsing.
    • Duplicate (arm, seed) entries are now detected and explicitly warned before the later value overwrites the earlier one.
  • Tests
    • Updated test setup to locate the analysis scripts more robustly across directory layouts and added coverage for warning/skip/overwrite behavior.

- Expose a public `plateau_tail` wrapper in t7_continuous_ranking and import
  that from the control harness (drop the private `_plateau_tail` coupling).
- load(): skip blank/`#`-comment lines silently but WARN on any other malformed
  line and on a duplicate (arm, seed) overwrite, so manifest issues are traceable.
- Locate scripts/analysis/ by walking up to the repo root in the harness test
  (robust to nesting depth, not a hardcoded parents[5]).
- Clarify the rewiring simple-graph guard: self-loops (autapses) are intentionally
  permitted (the real Cook connectome has 38; degree contribution is preserved).

Skipped two inline findings with reasons:
- config rename: the `_klinotaxis_rewired_null` order matches the committed
  `_ars_depletion` / `_no_respawn_control` siblings; renaming would break that
  consistency.
- reject self-loops: the real Cook connectome has 38 chemical autapses, so a
  reject guard would crash the live pipeline; they are legitimate structure and
  degree-preserved.

Verdict unchanged (DEGREE-STATISTICS re-verified); pre-commit + tests green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

â„đïļ Recent review info
⚙ïļ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2521eec6-ed43-4806-b8c2-dca2213d63d7

ðŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between 2a2255a and d26671a.

📒 Files selected for processing (2)
  • packages/quantum-nematode/tests/quantumnematode_tests/analysis/test_connectome_structure_controls.py
  • scripts/analysis/connectome_structure_controls.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/quantum-nematode/tests/quantumnematode_tests/analysis/test_connectome_structure_controls.py
  • scripts/analysis/connectome_structure_controls.py

📝 Walkthrough

Walkthrough

Adds a public plateau_tail wrapper, updates connectome manifest loading to use it with warnings and duplicate handling, strengthens the analysis test setup and coverage, and clarifies the rewiring guard comment.

Changes

Analysis API and manifest handling

Layer / File(s) Summary
Public plateau_tail wrapper
scripts/analysis/t7_continuous_ranking.py
Adds a public plateau_tail(out_path) function delegating to the existing private helper.
Manifest loading and metric call
scripts/analysis/connectome_structure_controls.py
Updates the module docstring and import to use plateau_tail, changes _success() to call it, and expands load(manifest) to warn on malformed lines, unknown arms, missing plateau data, and duplicate keys.

Tests and rewiring comment

Layer / File(s) Summary
Test harness and load warnings
packages/quantum-nematode/tests/quantumnematode_tests/analysis/test_connectome_structure_controls.py
Replaces the hardcoded scripts/analysis path lookup with directory traversal and adds tests for malformed lines, unknown arms, and duplicate manifest entries.
Rewiring guard comment
packages/quantum-nematode/quantumnematode/connectome/rewiring.py
Refines the inline comment to say the guard prevents parallel or duplicate edges while allowing self-loops.

Estimated code review effort: 2 (Simple) | ~10 minutes

ðŸšĨ Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects a follow-up PR for the connectome rewired-null control and review nitpick fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
âœĻ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧊 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/connectome-controls-review-followup

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

ðŸ§đ Nitpick comments (3)
packages/quantum-nematode/tests/quantumnematode_tests/analysis/test_connectome_structure_controls.py (1)

7-12: 📐 Maintainability & Code Quality | ðŸ”ĩ Trivial | ðŸ’Ī Low value

Good fix for the brittle hardcoded parents[5] traversal.

Walking up until scripts/analysis is found is robust to nesting depth. One nitpick: if the directory is never found, the loop silently stops at the filesystem root and sys.path gets a nonexistent path, so the failure surfaces later as an opaque ModuleNotFoundError on import rather than a clear message about the missing scripts/analysis directory.

â™ŧïļ Optional: fail fast with a clearer error
 _root = Path(__file__).resolve()
 while _root != _root.parent and not (_root / "scripts" / "analysis").is_dir():
     _root = _root.parent
-sys.path.insert(0, str(_root / "scripts" / "analysis"))
+_analysis_dir = _root / "scripts" / "analysis"
+if not _analysis_dir.is_dir():
+    raise RuntimeError(f"Could not locate scripts/analysis above {Path(__file__).resolve()}")
+sys.path.insert(0, str(_analysis_dir))
ðŸĪ– 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/analysis/test_connectome_structure_controls.py`
around lines 7 - 12, The path-walking logic in
test_connectome_structure_controls.py is fine, but it can still silently fall
through to the filesystem root and add a nonexistent path if scripts/analysis is
missing. Update the root āĪ–āĨ‹āΜ logic around the _root loop and sys.path.insert
setup to fail fast with a clear error when the directory is not found, so
imports don’t later surface as an opaque ModuleNotFoundError.
scripts/analysis/t7_continuous_ranking.py (1)

93-99: 📐 Maintainability & Code Quality | ðŸ”ĩ Trivial | ⚡ Quick win

Docstring missing NumPy Parameters/Returns sections.

The new public plateau_tail is a "Stable cross-module API" per its own docstring, but only has prose, no Parameters/Returns sections.

📝 Suggested docstring
 def plateau_tail(out_path: Path) -> tuple[float, float] | None:
-    """Public entry point for the plateau-tail ranked metric (see :func:`_plateau_tail`).
+    """Public entry point for the plateau-tail ranked metric (see :func:`_plateau_tail`).
 
-    Stable cross-module API so other analyses (e.g. the connectome-structure controls) can reuse the
-    exact 029 ranked metric without importing the private helper.
-    """
+    Stable cross-module API so other analyses (e.g. the connectome-structure controls)
+    can reuse the exact 029 ranked metric without importing the private helper.
+
+    Parameters
+    ----------
+    out_path : Path
+        Path to the per-run ``.out`` file.
+
+    Returns
+    -------
+    tuple[float, float] | None
+        (full-clear success %, mean foods) over the final-quarter plateau tail, or
+        ``None`` if ``out_path`` does not exist or contains no parseable runs.
+    """
     return _plateau_tail(out_path)

As per coding guidelines, "Use NumPy-style docstrings for functions and classes."

ðŸĪ– 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 `@scripts/analysis/t7_continuous_ranking.py` around lines 93 - 99, The public
plateau_tail function currently has only prose in its docstring, so update the
docstring on plateau_tail to use NumPy style with explicit Parameters and
Returns sections. Keep the existing intent about being a stable cross-module
API, and document the out_path argument plus the tuple[float, float] | None
return value in the same docstring format used elsewhere in the module, such as
around _plateau_tail.

Source: Coding guidelines

scripts/analysis/connectome_structure_controls.py (1)

52-77: 📐 Maintainability & Code Quality | ðŸ”ĩ Trivial | ⚡ Quick win

Add test coverage for the new warning branches.

The provided test context (test_load_parses_manifest, test_missing_file_is_none) exercises the happy path and comment-skipping, but not the newly-added malformed-line-shape warning or duplicate-(arm, seed)-overwrite warning paths introduced here. Given these are new, previously-untested behaviors central to this PR's "manifest diagnostics" goal, targeted tests would guard against regressions.

ðŸĪ– 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 `@scripts/analysis/connectome_structure_controls.py` around lines 52 - 77, Add
targeted tests for the new warning paths in load(manifest): one test should feed
a malformed manifest line that fails the expected <arm> <int seed> <out> shape
and assert the “skipping malformed manifest line” warning is emitted, and
another should include duplicate (arm, seed) entries to verify the overwrite
warning is printed and the later value wins. Reuse the existing load helper and
the manifest-parsing test setup so the new cases sit alongside
test_load_parses_manifest and cover the new diagnostics behavior.
ðŸĪ– 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 `@scripts/analysis/connectome_structure_controls.py`:
- Around line 60-77: The manifest parser in parse_manifest() only checks line
shape and numeric seed, so unknown arm names can be accepted and later ignored
by analyse(), causing silent sample loss. Add explicit validation that parts[0]
is one of the expected arm symbols (_WILD and _REWIRED) before storing the
entry, and emit a WARN when it is not. Keep the existing duplicate/seed
handling, but ensure typo’d arm names are rejected in the same validation path
as other malformed manifest lines.

---

Nitpick comments:
In
`@packages/quantum-nematode/tests/quantumnematode_tests/analysis/test_connectome_structure_controls.py`:
- Around line 7-12: The path-walking logic in
test_connectome_structure_controls.py is fine, but it can still silently fall
through to the filesystem root and add a nonexistent path if scripts/analysis is
missing. Update the root āĪ–āĨ‹āΜ logic around the _root loop and sys.path.insert
setup to fail fast with a clear error when the directory is not found, so
imports don’t later surface as an opaque ModuleNotFoundError.

In `@scripts/analysis/connectome_structure_controls.py`:
- Around line 52-77: Add targeted tests for the new warning paths in
load(manifest): one test should feed a malformed manifest line that fails the
expected <arm> <int seed> <out> shape and assert the “skipping malformed
manifest line” warning is emitted, and another should include duplicate (arm,
seed) entries to verify the overwrite warning is printed and the later value
wins. Reuse the existing load helper and the manifest-parsing test setup so the
new cases sit alongside test_load_parses_manifest and cover the new diagnostics
behavior.

In `@scripts/analysis/t7_continuous_ranking.py`:
- Around line 93-99: The public plateau_tail function currently has only prose
in its docstring, so update the docstring on plateau_tail to use NumPy style
with explicit Parameters and Returns sections. Keep the existing intent about
being a stable cross-module API, and document the out_path argument plus the
tuple[float, float] | None return value in the same docstring format used
elsewhere in the module, such as around _plateau_tail.
🊄 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: 2ffc45ef-bfde-4093-bc73-f550580d1ad6

ðŸ“Ĩ Commits

Reviewing files that changed from the base of the PR and between d22f051 and 2a2255a.

📒 Files selected for processing (4)
  • packages/quantum-nematode/quantumnematode/connectome/rewiring.py
  • packages/quantum-nematode/tests/quantumnematode_tests/analysis/test_connectome_structure_controls.py
  • scripts/analysis/connectome_structure_controls.py
  • scripts/analysis/t7_continuous_ranking.py

Comment thread scripts/analysis/connectome_structure_controls.py
@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

ðŸ“Ē Thoughts on this report? Let us know!

- load(): reject unknown arm names (not in {wild_type, rewired_null}) with a
  WARN instead of storing them to be silently ignored by analyse().
- Harness test: fail fast with a clear error if the scripts/analysis walk-up
  can't find the directory, rather than inserting a nonexistent path and
  surfacing an opaque ModuleNotFoundError.
- Add tests for the new load() diagnostics: malformed-line + unknown-arm WARNs,
  and the duplicate-(arm,seed) overwrite (later value wins).

Skipped the NumPy-docstring nitpick: t7_continuous_ranking (incl. _plateau_tail)
uses prose docstrings, not NumPy Parameters/Returns; plateau_tail already matches
that convention — NumPy sections would be inconsistent with the module.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chrisjz
chrisjz merged commit dc2feb0 into main Jul 5, 2026
4 checks passed
@chrisjz
chrisjz deleted the fix/connectome-controls-review-followup branch July 5, 2026 04:18
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