Skip to content

Hoist b_factor and occupancy annotations out of per-sample loop#18

Open
longleo17 wants to merge 1 commit intobytedance:mainfrom
longleo17:pr/parallel-cif-writing
Open

Hoist b_factor and occupancy annotations out of per-sample loop#18
longleo17 wants to merge 1 commit intobytedance:mainfrom
longleo17:pr/parallel-cif-writing

Conversation

@longleo17
Copy link

Summary

Moves the b_factor and occupancy annotation setup out of the per-sample loop in _save_structure(). Previously these were redundantly set on every iteration (100-500 times) despite being identical across samples.

Changes

  • pxdesign/runner/dumper.pyDataDumper._save_structure(): set annotations once before the loop

Test plan

  • pytest tests/test_parallel_cif_writing.py -v
  • Run inference, verify CIF output is identical

Copy link

Copilot AI left a comment

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 reduces redundant work in DataDumper._save_structure() by moving b_factor and occupancy annotation initialization out of the per-sample CIF writing loop, avoiding repeating identical annotation setup across many samples.

Changes:

  • Hoist b_factor and occupancy annotation setup to run once before iterating over samples in _save_structure().
  • Add a test that asserts annotation setup occurs before the per-sample loop (via source inspection).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
pxdesign/runner/dumper.py Moves annotation initialization outside the per-sample loop to avoid redundant per-iteration work.
tests/test_parallel_cif_writing.py Adds a regression test intended to ensure annotations are set before the loop.
tests/__init__.py Adds an (empty) package marker for the tests directory.

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

Comment on lines +12 to +15
method_source = source[method_start:]
b_factor_pos = method_source.find("b_factor")
loop_pos = method_source.find("for sample_idx")
assert b_factor_pos < loop_pos, (
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

This test can produce false positives because str.find() returns -1 when the substring is missing (e.g., if b_factor is renamed/removed). In that case b_factor_pos < loop_pos can still pass, so the test would not actually enforce the intended ordering. Consider asserting that method_start, b_factor_pos, and loop_pos are all != -1 and/or searching for the more specific pattern set_annotation("b_factor" (and similarly for occupancy) or using ast parsing to validate the statement order reliably.

Suggested change
method_source = source[method_start:]
b_factor_pos = method_source.find("b_factor")
loop_pos = method_source.find("for sample_idx")
assert b_factor_pos < loop_pos, (
assert method_start != -1, "Expected to find '_save_structure' in dumper.py"
method_source = source[method_start:]
b_factor_pos = method_source.find('set_annotation("b_factor"')
occupancy_pos = method_source.find('set_annotation("occupancy"')
loop_pos = method_source.find("for sample_idx")
assert b_factor_pos != -1, "Expected b_factor annotation to be set in _save_structure"
assert occupancy_pos != -1, "Expected occupancy annotation to be set in _save_structure"
assert loop_pos != -1, "Expected per-sample loop ('for sample_idx') in _save_structure"
assert b_factor_pos < loop_pos and occupancy_pos < loop_pos, (

Copilot uses AI. Check for mistakes.
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