Repository navigation
refactor: drop the C901 mccabe ratchet 44 → 41 (behavior-neutral) - #524
Merged
Merged
Conversation
…extraction
Pure orchestration/glue extraction, no numerical path touched.
api/relax.py: decompose _relax_nested (C901 43 -> 21) into self-contained
helpers, each with a typed signature and docstring and no shared mutable state
beyond `atoms`:
- _apply_selective_dynamics(atoms, fixed): FixScaled constraint assembly
- _make_cell_filter(atoms, inp): FrechetCellFilter for a vc-relax
- _resolve_line_search(target, inp, verbose): line-search selection + the
cell/non-bfgs fallback cascade, returning (ls_opt, ls_fallback_reason)
- _seed_initial_hessian(opt, atoms, inp, verbose): the Lindh model-Hessian seed
- _build_relax_summary(...): the ~90-line summary-dict assembly
api/dispatch.py: extract the task=="scf" summary-block accretion into
_scf_summary_extras(res, inp, summary, disp_block) (run C901 26 -> 20). The
dispersion energy still folds into `res` before build_summary reads it (the
call stays in `run`); only the block attachments move into the helper.
scf/loop.py: add "# === setup / iteration / finalize ===" section-banner
comments to the 852-line scf() body for navigability. Comments only; no code
in the hot SCF function is moved or extracted.
pyproject.toml: lower [tool.ruff.lint.mccabe] max-complexity 44 -> 41 (the new
worst offender, scf in scf/loop.py), tightening the ratchet.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Behavior-neutral decomposition of the two worst mccabe offenders in the driver layer, then a tightening of the ruff C901 ratchet.
_relax_nested(api/relax.py) was the single function pinning the ratchet: pure orchestration/glue (wires ASE optimizers to the calculator, no numerical hot path). Extracted into self-contained helpers, each typed + docstringed, no shared mutable state beyondatoms:_apply_selective_dynamics(atoms, fixed)— FixScaled constraint assembly_make_cell_filter(atoms, inp)— FrechetCellFilter for a variable-cell relax_resolve_line_search(target, inp, verbose)— line-search selection + the cell/non-bfgs fallback cascade, returning(ls_opt, ls_fallback_reason)_seed_initial_hessian(opt, atoms, inp, verbose)— the Lindh model-Hessian seed_build_relax_summary(...)— the ~90-line summary-dict assemblyrun(api/dispatch.py): thetask=="scf"summary-block accretion (error_estimate / pdos / cohp / bader / work_function, plus the dispersion attach) moved into_scf_summary_extras(res, inp, summary, disp_block). The dispersion energy still folds intoresbeforebuild_summaryreads it — that call stays inrun; only the block attachments move.scf(scf/loop.py): added# === setup / iteration / finalize ===section-banner comments to the 852-line body for navigability. Comments only — no code in the hot SCF function is moved or extracted.pyproject.toml: lowered[tool.ruff.lint.mccabe] max-complexity44 → 41 (the new worst offender,scfinscf/loop.py), tightening the ratchet.Complexity (old → new)
_relax_nestedrun(dispatch)New ceiling 41 is the exact minimum:
ruff --select C901 --config max-complexity=40fails only onscf(41); at 41 there are zero violations.Gates
uv run ruff checkclean at max-complexity=41uv run ty checkunchanged (7 pre-existing optional-dep import errors, none in touched files)uv run lint-importsclean (7/7 contracts)make doc-refscleanValidation
Relax + elastic + dispatch/scf-extras tests run on asus (standard tier) via the pueue queue. No test monkeypatches the extracted internals.
Note: this edits
pyproject.toml's[tool.ruff.lint.mccabe]; a sibling PR edits[[tool.ty.overrides]](different section) — a trivial clean rebase at merge is expected.🤖 Generated with Claude Code