Expose FIRE minimizer Python APIs#225
Conversation
|
| Filename | Overview |
|---|---|
| nvmolkit/types.cpp | New Boost.Python module exposing FireOptions struct; all fields correctly wired with def_readwrite. |
| nvmolkit/_types.pyi | New stub for _types module; all FireOptions fields listed, __init__ correctly annotated. |
| nvmolkit/types.py | Re-exports FireOptions from the new _types C++ module via noqa: F401; minimal and correct. |
| nvmolkit/_mmffOptimization.pyi | New MMFFOptimizeMoleculesConfsDevice stub incorrectly marks maxIters, properties, hardwareOptions, and targetGpu as optional; those are required in the C++ binding. |
| nvmolkit/_uffOptimization.pyi | New UFFOptimizeMoleculesConfsDevice stub marks five required C++ args as optional; fireOptions: object is inconsistent with the MMFF stub (Any). |
| nvmolkit/mmffOptimization.cpp | Adds FIRE path to both MMFFOptimizeMoleculesConfs and MMFFOptimizeMoleculesConfsDevice; backend/minimizer parsing extracted into local helpers; C++ defaults added to MMFFOptimizeMoleculesConfs binding. |
| nvmolkit/uffOptimization.cpp | Mirrors MMFF changes for UFF; FIRE path added; hardwareOptions given a default in the UFFOptimizeMoleculesConfs binding. |
| nvmolkit/batchedForcefield.cpp | FIRE path added to all four minimize methods; fireOptionsWithGradTol helper always overwrites gradTol with the forceTol parameter (previously flagged). |
| nvmolkit/batchedForcefield.py | Adds minimizerKind / fireOptions to _BatchedForcefieldBase._minimize() and propagates them through both MMFFBatchedForcefield and UFFBatchedForcefield overloads with proper validation. |
| nvmolkit/mmffOptimization.py | Adds backend, minimizerKind, fireOptions to the public MMFFOptimizeMoleculesConfs wrapper with Python-level validation and alias normalisation before forwarding to C++. |
| nvmolkit/uffOptimization.py | Adds minimizerKind / fireOptions to UFFOptimizeMoleculesConfs; no backend parameter (UFF FIRE uses a fixed backend internally, asymmetric with MMFF but consistent with the C++ binding). |
| nvmolkit/tests/test_mmff_optimization.py | Adds FIRE correctness tests (BATCHED and PER_MOL backends) plus validation tests for unknown minimizerKind and backend; coverage looks adequate. |
| nvmolkit/tests/test_uff_optimization.py | Adds FIRE correctness test and minimizerKind rejection test for the UFF path; matches the MMFF test structure. |
| nvmolkit/tests/test_batched_forcefield_device.py | New test_minimize_fire_host_returns_nested_energy_and_status covers MMFF and UFF batched-forcefield FIRE path; checks shape and type of returned tensors. |
| nvmolkit/tests/test_types.py | New test_fire_options_exposes_native_defaults_and_mutators verifies default gradTol and field mutability; straightforward and correct. |
| nvmolkit/CMakeLists.txt | Adds _types CMake target for the new types.cpp module; structure matches existing targets. |
Reviews (2): Last reviewed commit: "More fixes" | Re-trigger Greptile
| minimizer_kind = str(minimizerKind).upper() | ||
| if minimizer_kind not in {"BFGS", "FIRE"}: | ||
| raise ValueError("minimizerKind must be 'BFGS' or 'FIRE'") | ||
| if fireOptions is None: | ||
| fireOptions = FireOptions() | ||
| if output == CoordinateOutput.DEVICE: | ||
| return self._native_ff.minimizeDevice(maxIters, forceTol, -1 if target_gpu is None else int(target_gpu)) | ||
| energies, converged = self._native_ff.minimize(maxIters, forceTol) | ||
| return self._native_ff.minimizeDevice( | ||
| maxIters, | ||
| forceTol, | ||
| -1 if target_gpu is None else int(target_gpu), | ||
| minimizer_kind, | ||
| fireOptions, | ||
| ) | ||
| energies, converged = self._native_ff.minimize(maxIters, forceTol, minimizer_kind, fireOptions) |
There was a problem hiding this comment.
forceTol silently overrides user-supplied fireOptions.gradTol
In the C++ binding (batchedForcefield.cpp), the FIRE path calls fireOptionsWithGradTol(fireOptions, gradTol), which copies the user's FireOptions and overwrites its gradTol with the forceTol parameter (default 1e-4). Any explicit fireOptions.gradTol the caller sets is therefore silently discarded. The new test illustrates this: it sets options.gradTol = 1e-3 and calls minimize(maxIters=100, minimizerKind="FIRE", fireOptions=options) — but forceTol defaults to 1e-4, so the test is unknowingly running with a different tolerance than intended. Neither the minimize() docstring nor the FireOptions.gradTol field documents this override.
PR 6 for #216