Skip to content

Gate BFGS gradient-convergence denominator fix on RDKit >= 2026.03#183

Merged
scal444 merged 1 commit into
NVIDIA-BioNeMo:mainfrom
mooreneural:mooreneural
May 28, 2026
Merged

Gate BFGS gradient-convergence denominator fix on RDKit >= 2026.03#183
scal444 merged 1 commit into
NVIDIA-BioNeMo:mainfrom
mooreneural:mooreneural

Conversation

@mooreneural
Copy link
Copy Markdown
Contributor

rdkit/rdkit#9298 (merged into RDKit 2026.03) fixed a bug where a negative energy value caused max(energy * gradScale, 1.0) to clamp to 1, artificially tightening the gradient-tolerance convergence test mid-minimisation. Force fields with stabilising electrostatic or dispersion terms (MMFF94, UFF) can produce negative intermediate energies, so this affected real workloads.

Apply the same fix in both nvMolKit BFGS paths, gated on the linked RDKit version so that behaviour is unchanged when built against older RDKit:

  • src/minimizer/bfgs_minimize.cu (updateDGradKernel, batched path)
  • src/minimizer/bfgs_minimize_permol_kernels.cu (updateDGrad, per-mol path)

Mirrors the version-conditional pattern already used for kRdkitHasGradScaleFix in scaleGradKernel.

rdkit/rdkit#9298 (merged into RDKit 2026.03) fixed a bug where a negative
energy value caused max(energy * gradScale, 1.0) to clamp to 1, artificially
tightening the gradient-tolerance convergence test mid-minimisation. Force
fields with stabilising electrostatic or dispersion terms (MMFF94, UFF) can
produce negative intermediate energies, so this affected real workloads.

Apply the same fix in both nvMolKit BFGS paths, gated on the linked RDKit
version so that behaviour is unchanged when built against older RDKit:

- src/minimizer/bfgs_minimize.cu       (updateDGradKernel, batched path)
- src/minimizer/bfgs_minimize_permol_kernels.cu (updateDGrad, per-mol path)

Mirrors the version-conditional pattern already used for kRdkitHasGradScaleFix
in scaleGradKernel.

Signed-off-by: Clay Moore <claytonwaynemoore@gmail.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 28, 2026

Greptile Summary

Gates the negative-energy denominator bug fix (rdkit/rdkit#9298, merged in RDKit 2026.03) behind a compile-time version check in both the batched and per-molecule BFGS kernels, resolving the existing TODO and matching the kRdkitHasGradScaleFix versioning pattern already in these files.

  • updateDGradKernel (bfgs_minimize.cu) and updateDGrad (bfgs_minimize_permol_kernels.cu) both introduce constexpr bool kRdkitHasGradDenomFix with the same >= 2026.03 predicate, replacing the raw energies[sysIdx] / energy with fabs(...) only when the fix is present upstream.
  • The version check expression is structurally identical to the existing kRdkitHasGradScaleFix guards, keeping the gating pattern consistent across the file.

Confidence Score: 5/5

Safe to merge. Both changed sites apply the absolute-value fix behind an identical compile-time version predicate, leaving behaviour unchanged on older RDKit builds.

The two hunks are symmetric, minimal, and resolve a documented TODO. The version check expression is structurally identical to the pre-existing kRdkitHasGradScaleFix guard and correctly enables the fix only for RDKit >= 2026.03. No new type conversions, no new memory accesses, and no control-flow changes are introduced.

No files require special attention.

Important Files Changed

Filename Overview
src/minimizer/bfgs_minimize.cu Adds kRdkitHasGradDenomFix version gate in updateDGradKernel to use fabs(energy) when linked against RDKit >= 2026.03, replacing the stale TODO comment; change is correct and consistent with the kRdkitHasGradScaleFix pattern.
src/minimizer/bfgs_minimize_permol_kernels.cu Mirrors the same kRdkitHasGradDenomFix gate in the per-mol updateDGrad device function; logic is identical to the batched path and correct.

Reviews (1): Last reviewed commit: "Gate BFGS gradient-convergence denominat..." | Re-trigger Greptile

@scal444
Copy link
Copy Markdown
Collaborator

scal444 commented May 28, 2026

Awesome, thank you!

@scal444 scal444 merged commit 7ad16cf into NVIDIA-BioNeMo:main May 28, 2026
8 checks passed
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