Validate batchesPerGpu in HardwareOptions rather than individual callers#103
Conversation
batchesPerGpu validation (reject values ≤ 0 other than -1) previously lived only in EmbedMolecules, leaving MMFFOptimizeMoleculesConfs and any future API unprotected. Invalid values passed to MMFF would reach the C++ layer and produce cryptic errors. Move the check into HardwareOptions.__init__ and the batchesPerGpu setter so every consumer is covered consistently. Remove the now-redundant check from EmbedMolecules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: andreivolgin <andrei@rebelation.com>
|
| Filename | Overview |
|---|---|
| nvmolkit/types.py | Moves batchesPerGpu validation into the setter and delegates from init to it, eliminating duplication. The ordering in init (self._native assigned before the setter call) is correct. Logic is clean and safe. |
| nvmolkit/embedMolecules.py | Removes the now-redundant batchesPerGpu check. The removal is safe because HardwareOptions constructor/setter enforces the same rule earlier, before native_options is extracted. |
| nvmolkit/tests/test_types.py | Adds a parametrized test covering both construction-time and setter validation paths for invalid batchesPerGpu values. The pytest.raises match pattern is a valid substring of the actual error message and will match correctly. |
Last reviewed commit: 2ba3e0c
Address Greptile review: test the property setter in addition to the constructor so future refactors cannot silently drop the check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: andreivolgin <andrei@rebelation.com>
Address Greptile review: remove inline validation from __init__ and assign through the property setter so the check lives in one place. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: andreivolgin <andrei@rebelation.com>
| embed.EmbedMolecules([mol], params) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("invalid_value", [0, -2, -99]) |
There was a problem hiding this comment.
Since this is now testing HardwareOptions validation rather than EmbedMolecules behavior, could you move this test to test_types.py?
|
Thanks for the contribution! The validation consolidation looks good. One minor comment: the new test would be better placed in |
Move test_hardware_options_invalid_batches_per_gpu from test_embed_molecules.py to test_types.py per maintainer feedback, as it tests HardwareOptions directly. Also adds GitHub Actions CI workflow using the gpu-t4 runner. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: andreivolgin <andrei@rebelation.com>
|
Thanks for moving the test to test_types.py! The validation changes look good. However, could you please remove the |
This file belongs on the fork's main branch, not in the upstream contribution. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: andreivolgin <andrei@rebelation.com>
evasnow1992
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
Summary
batchesPerGpuvalidation (reject values ≤ 0 other than -1) previously lived only inEmbedMolecules, leavingMMFFOptimizeMoleculesConfsand any future API unprotected. Invalid values passed to MMFF would reach the C++ layer and produce cryptic errors.HardwareOptions.__init__and thebatchesPerGpusetter so every consumer is covered consistently.EmbedMolecules.Context
We use nvMolKit for GPU-accelerated conformer generation in a drug discovery pipeline (Novel Therapeutics). We hit this gap when passing hardware options to
MMFFOptimizeMoleculesConfs— invalidbatchesPerGpuvalues produced opaque C++ errors instead of a clear Python-sideValueError.Test plan
EmbedMolecules)test_embed_molecules_invalid_batches_per_gpucovers 0, -2, -99MMFFOptimizeMoleculesConfsnow rejects invalid values atHardwareOptionsconstruction🤖 Generated with Claude Code