Skip to content

feat(eval): discover trials from job metadata#321

Open
manzuoni-astera wants to merge 3 commits into
diff-use:mainfrom
manzuoni-astera:michaelanzuoni/issue-213-trial-metadata
Open

feat(eval): discover trials from job metadata#321
manzuoni-astera wants to merge 3 commits into
diff-use:mainfrom
manzuoni-astera:michaelanzuoni/issue-213-trial-metadata

Conversation

@manzuoni-astera

@manzuoni-astera manzuoni-astera commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • load job_metadata.json while discovering completed grid-search trials
  • prefer recorded model, method, scaler, ensemble, guidance settings, and explicit altloc occupancies over directory-name reconstruction
  • record altloc_occupancies in new job metadata files
  • carry recorded input structure, density-map, and resolution paths on each Trial
  • make RSCC evaluation use those recorded map, reference-structure, and resolution values
  • centralize metadata resolution and preserve path/config parsing as a historical fallback
  • accept both current model and forthcoming model_name metadata schemas

Implementation work for #213. Other evaluators can now migrate to the same Trial fields; the legacy input/config arguments remain available for selections and historical runs.

Validation

  • pytest tests/eval/test_grid_search_trial_metadata.py tests/eval/test_eval_dataclasses.py tests/eval/test_rscc_grid_search_script.py tests/utils/test_guidance_script_utils.py -q (34 passed)
  • targeted ty check passes
  • ruff check and ruff format --check on touched files
  • git diff --check

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Trial now stores optional input structure, density, and resolution values. Grid-search scanning reads valid job_metadata.json data, applies metadata-derived parameters with path-based fallbacks, and populates these fields. Tests cover the expanded dataclass and metadata handling.

Changes

Metadata-backed trial discovery

Layer / File(s) Summary
Extend the Trial contract
src/sampleworks/eval/eval_dataclasses.py, tests/eval/test_eval_dataclasses.py
Trial adds optional input structure, density, and resolution fields, with updated field-set assertions.
Load metadata during grid-search scanning
src/sampleworks/eval/grid_search_eval_utils.py, tests/eval/test_grid_search_trial_metadata.py
Grid-search discovery loads and validates job_metadata.json, applies metadata-derived parameters with path-based fallbacks, and populates the extended Trial fields. Tests cover metadata precedence and non-object JSON rejection.

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

Sequence Diagram(s)

sequenceDiagram
  participant scan_grid_search_results
  participant trial_directory
  participant load_job_metadata
  participant Trial
  scan_grid_search_results->>trial_directory: Find refined.cif and job_metadata.json
  scan_grid_search_results->>load_job_metadata: Load trial metadata
  load_job_metadata-->>scan_grid_search_results: Return object or None
  scan_grid_search_results->>Trial: Construct metadata-derived trial
Loading

Possibly related PRs

Suggested reviewers: marcuscollins, dorismai, k-chrispens

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: discovering eval trials from job metadata.
✨ 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.

Copilot AI 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.

Pull request overview

This PR implements metadata-backed discovery of completed grid-search trials by loading job_metadata.json during result scanning, so evaluators can rely on recorded trial identity and input paths instead of reconstructing them from directory names (with a compatibility fallback for historical runs). This aligns with Issue #213’s goal of sourcing map/structure locations from run metadata.

Changes:

  • Added load_job_metadata() and updated scan_grid_search_results() to prefer job_metadata.json values (supporting both model and model_name) with path-based fallback.
  • Extended the Trial dataclass to carry input_structure_path, density_path, and resolution.
  • Added/updated tests to ensure metadata is preferred and Trial.__dict__.copy() includes the new fields.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/sampleworks/eval/grid_search_eval_utils.py Load and consume job_metadata.json when discovering trials; keep path-parsing fallback.
src/sampleworks/eval/eval_dataclasses.py Add optional input paths and resolution fields to Trial.
tests/eval/test_grid_search_trial_metadata.py New tests asserting metadata is preferred and invalid metadata is ignored.
tests/eval/test_eval_dataclasses.py Update expected Trial.__dict__.copy() keys to include new fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +193 to +199
protein_value = metadata.get("protein", path_protein)
protein = str(protein_value) if protein_value is not None else None
model_value = metadata.get("model_name", metadata.get("model", path_model))
model = str(model_value)
method_value = metadata.get("method", method)
method = str(method_value) if method_value is not None else None
scaler = str(metadata.get("guidance_type", scaler_dir.name))
Comment on lines +208 to +210
gd_steps_value = metadata.get("num_gd_steps", params["gd_steps"])
gd_steps = int(str(gd_steps_value)) if gd_steps_value is not None else None
ensemble_size_value = metadata.get("ensemble_size", params["ensemble_size"])
scaler=scaler_dir.name,
ensemble_size=int(params["ensemble_size"]),
scaler=scaler,
ensemble_size=int(str(ensemble_size_value)),

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/sampleworks/eval/grid_search_eval_utils.py (1)

202-210: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Avoid casting numbers to str before int and float conversion.

Casting parsed JSON numbers to strings before converting them to int or float can cause runtime exceptions (for example, if gd_steps_value is parsed as a JSON float like 10.0, int(str(10.0)) will evaluate to int("10.0") and raise a ValueError). Using int() or float() directly handles both integer and float inputs cleanly.

  • src/sampleworks/eval/grid_search_eval_utils.py#L202-L210: change float(str(guidance_weight_value)) to float(guidance_weight_value) and int(str(gd_steps_value)) to int(gd_steps_value).
  • src/sampleworks/eval/grid_search_eval_utils.py#L229-L244: change int(str(ensemble_size_value)) to int(ensemble_size_value) and float(str(metadata["resolution"])) to float(metadata["resolution"]).
🤖 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 `@src/sampleworks/eval/grid_search_eval_utils.py` around lines 202 - 210,
Remove the unnecessary string conversions before numeric parsing in the metadata
handling logic: update guidance_weight_value and gd_steps_value conversions in
src/sampleworks/eval/grid_search_eval_utils.py lines 202-210, and
ensemble_size_value plus metadata["resolution"] conversions in lines 229-244, to
pass the values directly to float() or int().
🤖 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.

Nitpick comments:
In `@src/sampleworks/eval/grid_search_eval_utils.py`:
- Around line 202-210: Remove the unnecessary string conversions before numeric
parsing in the metadata handling logic: update guidance_weight_value and
gd_steps_value conversions in src/sampleworks/eval/grid_search_eval_utils.py
lines 202-210, and ensemble_size_value plus metadata["resolution"] conversions
in lines 229-244, to pass the values directly to float() or int().

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aee01236-c4b7-40c7-96af-a5b92b84029f

📥 Commits

Reviewing files that changed from the base of the PR and between 063f519 and 0af4eee.

📒 Files selected for processing (4)
  • src/sampleworks/eval/eval_dataclasses.py
  • src/sampleworks/eval/grid_search_eval_utils.py
  • tests/eval/test_eval_dataclasses.py
  • tests/eval/test_grid_search_trial_metadata.py

Comment thread src/sampleworks/eval/grid_search_eval_utils.py Outdated
Comment thread src/sampleworks/eval/grid_search_eval_utils.py Outdated
Comment thread tests/eval/test_grid_search_trial_metadata.py

@marcuscollins marcuscollins left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There's one issue about the altloc_occupancies that we should chase down. Otherwise LGTM.

@manzuoni-astera

Copy link
Copy Markdown
Contributor Author

Addressed the requested changes in ce07d23:

  • new runs now write explicit altloc_occupancies into job_metadata.json
  • trial discovery prefers those occupancies and uses directory parsing only for historical fallback
  • metadata resolution is centralized in typed helpers, including null/empty and invalid-number fallbacks
  • tests prove metadata occupancies override different directory occupancies and cover metadata writing

Focused evaluation/metadata tests pass (34 passed) and targeted type/lint checks are clean. Ready for re-review.

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.

4 participants