Skip to content

Fix dependency conflicts, add psims, CI workflow, and end-to-end test - #18

Closed
martingarridorc wants to merge 4 commits into
Noble-Lab:mainfrom
martingarridorc:main
Closed

martingarridorc wants to merge 4 commits into
Noble-Lab:mainfrom
martingarridorc:main

Conversation

@martingarridorc

@martingarridorc martingarridorc commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes several installation issues discovered during a clean-environment install, adds a missing dependency, repairs a latent runtime bug uncovered by end-to-end testing, and introduces a GitHub Actions CI workflow that runs on every push.

Dependency fixes (pyproject.toml)

  • Remove pytorch-lightning>=1.9,<2.0 — this conflicted fatally with lightning>=2.0. Starting with version 2.0, pytorch-lightning was merged into the lightning package, which already ships a pytorch_lightning backward-compatibility shim. Declaring both caused pip to fail on any fresh install.
  • Widen lightning bound to <3.0 — the previous <2.1 cap prevented installation of any release after 2.0.x. The public Trainer/LightningModule API used by Cascadia is stable across the 2.x series.
  • Add psims — pyteomics ≥ 4.7 requires psims for PSI format (mzML/mzXML) parsing. The package was absent from the declared dependencies; it happened to be present in the authors' conda environments as a transitive dependency, masking the gap. A clean install fails without it.

Bug fix: missing write_results import (cascadia/cascadia.py)

write_results is defined in cascadia/utils.py but was never imported — only cascadia/depthcharge/utils was pulled in via wildcard import. Every call to cascadia sequence would raise NameError: name 'write_results' is not defined at the final output step. This was caught by the new end-to-end test running inference all the way to SSL file generation.

CI workflow (.github/workflows/ci.yml)

Runs on every push and pull request against Python 3.10 and 3.11.

Key design choices:

  • Installs PyTorch CPU-only first (--index-url https://download.pytorch.org/whl/cpu) so pip does not pull in the multi-GB CUDA wheel.
  • Generates a random-weight checkpoint with the production architecture (d_model=512, n_layers=9) and caches it via actions/cache with a stable key — only regenerated when the architecture changes (~90 s first run, ~5 s on cache hits).
  • No GPU or real trained weights required.

Test suite (tests/)

File What it tests
tests/create_mini_mzml.py Generates a 41 KB synthetic DIA mzML (5 cycles × 4 spectra)
tests/create_dummy_ckpt.py Saves a random-weight production-architecture Lightning checkpoint
tests/test_install.py Import, mzML parsing, augment_spectra, tokenizer (no checkpoint needed)
tests/test_e2e.py Full cascadia sequence pipeline — augmentation → inference → SSL output

Test plan

  • All 6 pytest tests pass on Python 3.10 and 3.11 in CI
  • pip install . succeeds in a fresh virtual environment
  • cascadia sequence <mzml> <ckpt> produces a .ssl output file

Summary by CodeRabbit

  • New Features

    • Added support for newer Lightning releases and included psims.
    • Added an optional test installation with pytest.
  • Bug Fixes

    • Improved result writing for the sequence command.
  • Tests

    • Added end-to-end tests covering installation, mzML parsing, spectrum augmentation, tokenizer loading, and CLI output.
    • Added deterministic test data generation for checkpoints and mzML files.
    • Added continuous integration testing across Python 3.10 and 3.11 with checkpoint caching.

- Remove pytorch-lightning>=1.9,<2.0 (conflicts with lightning>=2.0;
  the lightning package already ships pytorch_lightning as a compat shim)
- Widen lightning bound to <3.0 so pip resolves against current releases
- Add [test] extra with pytest
- Add .github/workflows/ci.yml: installs CPU-only torch first to avoid
  the CUDA wheel, then runs the full test suite on Python 3.10 and 3.11
- Add tests/create_mini_mzml.py: generates a 41 KB synthetic DIA mzML
  (5 cycles x 4 spectra) to exercise the augmentation pipeline in CI
- Add tests/create_dummy_ckpt.py: saves a random-weight production-arch
  checkpoint (~190 MB) cached across runs via actions/cache
- Add tests/test_install.py: import, mzML parsing, augment_spectra,
  tokenizer smoke tests (no GPU or checkpoint required)
- Add tests/test_e2e.py: full cascadia sequence pipeline test using the
  cached dummy checkpoint (skipped if CASCADIA_DUMMY_CKPT is unset)
Two bugs from the first CI run:

1. trainer.strategy.connect() + trainer.save_checkpoint() requires
   Lightning to have completed internal fit setup, which does not happen
   without an actual training call.  Replaced with a direct torch.save()
   of the Lightning checkpoint dict (load_from_checkpoint only needs
   state_dict when all hyperparams are supplied as kwargs).

2. ~ in YAML env vars is not shell-expanded, so "${{ env.CKPT_PATH }}"
   passed the literal string ~/... to Python, causing mkdir to create a
   directory named ~.  Fixed by resolving the path via $HOME in a
   dedicated workflow step that writes to GITHUB_ENV, and added
   Path.expanduser() in both Python scripts as a defensive measure.
pyteomics>=4.7 requires psims for PSI format (mzML/mzXML) parsing.
Was present locally as a transitive dep but missing from the declared
dependencies, causing CI to fail on a clean install.
write_results is defined in cascadia/utils.py but was never imported —
only .depthcharge.utils was pulled in via wildcard import. The function
call on line 87 raised NameError at runtime. Exposed by CI running the
full sequence() pipeline end-to-end.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds dependency updates, deterministic mzML and checkpoint generators, installation and end-to-end tests, an explicit utility import, and a GitHub Actions matrix that runs the test suite with cached CPU checkpoints.

Changes

CI and end-to-end validation

Layer / File(s) Summary
Runtime and test dependency contracts
pyproject.toml, cascadia/cascadia.py
Expands the Lightning constraint, adds psims and the test extra, removes pytorch-lightning, and explicitly imports write_results.
Deterministic mzML and checkpoint fixtures
tests/create_mini_mzml.py, tests/create_dummy_ckpt.py
Adds reproducible synthetic DIA mzML and Lightning-compatible checkpoint generators with CLI entrypoints.
Package and CLI validation
tests/test_install.py, tests/test_e2e.py
Adds import, parsing, augmentation, tokenizer, and sequence-command tests using the generated fixtures.
GitHub Actions test pipeline
.github/workflows/ci.yml
Adds Python 3.10/3.11 CI, CPU-only PyTorch installation, checkpoint caching, import verification, and verbose pytest execution.

Estimated code review effort: 3 (Moderate) | ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: dependency fixes, a new psims dependency, CI workflow, and an end-to-end test.
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 unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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)
tests/test_e2e.py (2)

28-36: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Use the exact --outfile flag instead of the abbreviated --out.

cascadia/cascadia.py defines -o/--outfile, not --out. This currently works only because argparse's default abbreviation matching resolves it unambiguously — it will silently break if a future flag starting with --out is added.

♻️ Suggested fix
     sys.argv = [
         "cascadia",
         "sequence",
         str(mzml_file),
         CKPT_PATH,
-        "--out", out_prefix,
+        "--outfile", out_prefix,
         "--batch_size", "4",
         "--max_charge", "2",
     ]
🤖 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 `@tests/test_e2e.py` around lines 28 - 36, Update the command arguments in the
e2e test’s sys.argv setup to use the exact --outfile option defined by the
cascadia CLI, replacing the abbreviated --out flag while preserving the existing
output prefix value.

28-39: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer monkeypatch for sys.argv instead of a raw assignment.

sys.argv is overwritten globally with no teardown/restoration; pytest's monkeypatch fixture would auto-restore it and is the idiomatic pattern for CLI-arg tests.

🤖 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 `@tests/test_e2e.py` around lines 28 - 39, Update the test invoking
cascadia.cascadia.sequence to accept pytest’s monkeypatch fixture and use it to
replace sys.argv, preserving the existing CLI arguments while ensuring automatic
restoration after the test.
tests/test_install.py (1)

24-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated mzML-fixture bootstrap logic across test files. Both files repeat the same sys.path.insert(0, str(TESTS_DIR)) + from create_mini_mzml import create_mini_mzml pattern instead of sharing one helper/fixture.

  • tests/test_install.py#L24-L29: keep _make_mini_mzml here, or better, move it into a shared tests/conftest.py fixture.
  • tests/test_e2e.py#L21-L24: replace the inline sys.path.insert + import with the shared helper/fixture from tests/conftest.py (or import _make_mini_mzml from test_install.py) instead of duplicating the bootstrap logic.
🤖 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 `@tests/test_install.py` around lines 24 - 29, Centralize the duplicated
create_mini_mzml bootstrap by moving _make_mini_mzml from tests/test_install.py
into a shared tests/conftest.py helper or fixture, preserving its existing
behavior. Update tests/test_e2e.py to use that shared helper/fixture instead of
maintaining its own sys.path insertion and import; both affected sites require
these changes.
🤖 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 @.github/workflows/ci.yml:
- Line 25: Update the actions/checkout@v4 step to disable credential persistence
by setting its persist-credentials option to false, while leaving the existing
checkout behavior unchanged.

---

Nitpick comments:
In `@tests/test_e2e.py`:
- Around line 28-36: Update the command arguments in the e2e test’s sys.argv
setup to use the exact --outfile option defined by the cascadia CLI, replacing
the abbreviated --out flag while preserving the existing output prefix value.
- Around line 28-39: Update the test invoking cascadia.cascadia.sequence to
accept pytest’s monkeypatch fixture and use it to replace sys.argv, preserving
the existing CLI arguments while ensuring automatic restoration after the test.

In `@tests/test_install.py`:
- Around line 24-29: Centralize the duplicated create_mini_mzml bootstrap by
moving _make_mini_mzml from tests/test_install.py into a shared
tests/conftest.py helper or fixture, preserving its existing behavior. Update
tests/test_e2e.py to use that shared helper/fixture instead of maintaining its
own sys.path insertion and import; both affected sites require these changes.
🪄 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 Plus

Run ID: 7ab9e380-e1e4-410a-9336-0de0ccc92b41

📥 Commits

Reviewing files that changed from the base of the PR and between b55a177 and 0ec7f86.

📒 Files selected for processing (8)
  • .github/workflows/ci.yml
  • cascadia/cascadia.py
  • pyproject.toml
  • tests/__init__.py
  • tests/create_dummy_ckpt.py
  • tests/create_mini_mzml.py
  • tests/test_e2e.py
  • tests/test_install.py

Comment thread .github/workflows/ci.yml
CKPT_CACHE_KEY: cascadia-dummy-ckpt-arch-v1

steps:
- uses: actions/checkout@v4

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Disable checkout credential persistence.

This workflow executes pull-request-controlled code via package installation, fixture generation, and pytest. actions/checkout@v4 otherwise stores GITHUB_TOKEN in .git/config, allowing malicious setup or test code to read and exfiltrate it. contents: read limits the token’s permissions but does not prevent credential exposure.

🔒 Proposed fix
       - uses: actions/checkout@v4
+        with:
+          persist-credentials: false
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
persist-credentials: false
🧰 Tools
🪛 zizmor (1.26.1)

[warning] 25-25: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)

🤖 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 @.github/workflows/ci.yml at line 25, Update the actions/checkout@v4 step to
disable credential persistence by setting its persist-credentials option to
false, while leaving the existing checkout behavior unchanged.

Source: Linters/SAST tools

@martingarridorc

Copy link
Copy Markdown
Contributor Author

Ran into second torch issue. Cancelling the PR

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