test: parametrized engine contract test suite#141
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a parametrized integration “contract” test suite to ensure all registered MM engines conform to the MMEngine interface and basic behavioral expectations, while removing duplicated per-engine tests.
Changes:
- Added
test/integration/test_engine_contract.pyto run a shared contract suite across all available MM engines discovered via the registry. - Removed duplicated availability/Hessian/frequency-count tests from JAX and JAX-MD integration suites.
- Updated
q2mm/backends/mm/__init__.pyexports to includeJaxMDEngineand simplified optional import handling.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/integration/test_engine_contract.py | New parametrized contract tests for MM engines using registry discovery. |
| test/integration/test_jax_backend.py | Removes tests now covered by the shared contract suite. |
| test/integration/test_jax_md_backend.py | Removes tests now covered by the shared contract suite. |
| q2mm/backends/mm/init.py | Exports JaxMDEngine and adjusts __all__ population logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c8f96e9 to
4d90dd9
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Create test/integration/test_engine_contract.py with 30+ contract tests that run against every registered MM engine (jax, jax-md, openmm, tinker). Tests cover metadata, bond/angle/vdw energy, analytical gradients, Hessian, frequencies, minimization, and real-molecule (SN2) validation. Gut per-engine test files to keep only truly engine-specific tests: - JAX: known-value energy, handle/context reuse, _build_vdw_pairs, optimizer - JAX-MD: LJ numeric formula, cross-engine parity, energy_breakdown, optimizer - OpenMM: MM3 formula checks, context reuse, Tinker parity, Seminario pipeline - Tinker: file-path API, SN2 imaginary frequencies Import all engine modules unconditionally in mm/__init__.py (modules guard their own deps). Add type hints to all test function arguments. Closes #139 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
8e46980 to
23d73bd
Compare
- Use PEP 562 __getattr__ lazy loading for JaxEngine/JaxMDEngine in mm/__init__.py so importing the package doesn't trigger JAX x64 config as a side effect - Make _functional_form() handle arbitrary engine functional forms instead of hard-coding harmonic/mm3 fallback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Skip entire contract module when no MM engines are available - Make engine/engine_name fixtures module-scoped to avoid repeated instantiation and JIT compilation overhead Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ericchansen
left a comment
There was a problem hiding this comment.
Both items addressed in d16d514:
-
Empty
_AVAILABLEskip — Addedpytest.skip("no MM engines available", allow_module_level=True)when_AVAILABLEis empty. The module now skips cleanly instead of erroring at collection time. -
Module-scope fixtures — Changed both
engine_nameandenginefixtures toscope="module". Each engine is instantiated once per module, avoiding repeated JIT compilation overhead for JAX/JAX-MD.
Summary
Adds a parametrized contract test suite that verifies every available MM engine satisfies the
MMEngineABC contract. Uses the engine registry from #134 to discover engines at collection time — new engines automatically get tested when they register.What's tested
13 contract tests × N available engines (currently 3: OpenMM, JAX, JAX-MD):
namereturns non-empty string,is_available()is True,supported_functional_forms()non-emptyDuplicate removal
Removed 6 tests from individual backend files that were exact duplicates of contract behavior:
test_jax_backend.py:test_is_available,test_hessian_shape,test_hessian_symmetric,test_frequencies_counttest_jax_md_backend.py:test_is_available,test_hessian_shape,test_hessian_symmetricKept all engine-specific extended tests (near-zero translation modes, analytical gradients, cross-engine parity, optimizer integration).
Other changes
mm/__init__.py: AddedJaxMDEngineexport, simplified try/except pattern (removed_HAS_JAX_ENGINEflag)Test results
467 passed, 86 skipped (36 new contract tests, 6 duplicates removed → net +30)
Closes #139