refactor: extract magic numbers into named constants module#448
Open
haoyu-haoyu wants to merge 1 commit intoRosettaCommons:mainfrom
Open
refactor: extract magic numbers into named constants module#448haoyu-haoyu wants to merge 1 commit intoRosettaCommons:mainfrom
haoyu-haoyu wants to merge 1 commit intoRosettaCommons:mainfrom
Conversation
Add rfdiffusion/constants.py centralizing magic numbers used across the codebase, with documentation of each constant's meaning and provenance. Replace inline values in 4 files: - Cbeta reconstruction coefficients (-0.58273431, 0.56802827, -0.54067466) used in util.py (2x), Embeddings.py, coords6d.py → CBETA_A/B/C - Amino acid token indices (21=mask, 7=glycine) in run_inference.py → AA_MASK_TOKEN, AA_GLYCINE Also documents additional constants (NO_CONTACT_DIST, CHAIN_BREAK_*, SE3_*_SCALE, diffusion schedule params) for future refactoring.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
rfdiffusion/constants.pycentralizing undocumented magic numbers with explanations, and replace the most widely duplicated ones.Constants replaced in this PR
CBETA_A/B/Cutil.py,Embeddings.py,coords6d.pyAA_MASK_TOKENrun_inference.pyAA_GLYCINErun_inference.pyConstants documented (for future refactoring)
The constants module also defines (but does not yet wire up) documented constants for:
NO_CONTACT_DIST(999.9) — sentinel distance, used 7 times across 3 filesCHAIN_BREAK_INDEX_JUMP(200) — contig chain break offsetSE3_TRANSLATION_SCALE/SE3_ROTATION_SCALE(10.0 / 100.0) — Track module scalingThese are intentionally left as documentation-only in this PR to keep the diff reviewable. They can be wired up incrementally in follow-up PRs.
Test plan
tests/test_diffusion.py— output should be bit-identical