Repository navigation
refactor(backends): Simplify backend helpers and type MM modules - #376
Merged
Merged
Conversation
ericchansen
force-pushed
the
ericchansen-simplify-backends-layer
branch
from
October 19, 2026 22:44
5ae73d0 to
8612598
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Shared frequency evaluation rejects non-finite Hessians before penalty-mode recovery can run.
1 open issue
What changed in this PR
Simplifies q2mm’s backend layer by sharing validation and evaluation helpers and extending enforced type checking.
Changes:
- Consolidates backend contracts, conformance checks, and reference preparation.
- Shares MM topology matching, prepared-session operations, and force construction.
- Removes seven MM modules from mypy exemptions.
| File | Description |
|---|---|
| q2mm/backends/reference/qcengine.py | Uses shared preparation validation. |
| q2mm/backends/reference/psi4.py | Shares frequency wavefunction evaluation. |
| q2mm/backends/reference/ase.py | Consolidates preparation and state validation. |
| q2mm/backends/reference/__init__.py | Adds shared reference preparation validation. |
| q2mm/backends/mm/tinker.py | Shares export checks and frequency conversion. |
| q2mm/backends/mm/openmm.py | Deduplicates nonbonded force construction and session helpers. |
| q2mm/backends/mm/jax_md_engine.py | Adopts shared topology and session helpers. |
| q2mm/backends/mm/jax_engine.py | Consolidates topology matching and energy kernels. |
| q2mm/backends/mm/batched.py | Tightens typing and validates session types. |
| q2mm/backends/mm/_term_support.py | Adds shared force-field validation. |
| q2mm/backends/mm/_jax_common.py | Adds shared topology and prepared-session implementations. |
| q2mm/backends/mm/__init__.py | Adjusts lazy-export typing. |
| q2mm/backends/discovery.py | Consolidates discovery-record normalization. |
| q2mm/backends/contracts.py | Shares request validation and MM session utilities. |
| q2mm/backends/conformance.py | Deduplicates capability checks. |
| pyproject.toml | Removes seven MM mypy exemptions. |
Review effort: Balanced
ericchansen
force-pushed
the
ericchansen-simplify-backends-layer
branch
from
October 20, 2026 17:39
8612598 to
c6c7372
Compare
Unify capability/functional-form normalization, parameter-vector request validation, MM force-field/frequency helpers, and conformance checks across the backend contracts and discovery layer. Share reference preparation validation across ASE and QCEngine, consolidate JAX/JAX-MD topology matching and prepared-session hooks in _jax_common, and deduplicate OpenMM vdW and 1-4 exception construction. Make all q2mm.backends.mm* modules mypy-clean and remove them from the mypy grandfather overrides in pyproject.toml. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
ericchansen
force-pushed
the
ericchansen-simplify-backends-layer
branch
from
October 20, 2026 18:04
c6c7372 to
6249c4c
Compare
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.

Summary
This PR simplifies the
q2mm.backendslayer by deduplicating shared validation, topology-matching, and prepared-session helpers across contracts, conformance, reference backends, and MM backends, while making all sevenq2mm.backends.mm*modulesmypy-clean and removing the final[[tool.mypy.overrides]]grandfather block frompyproject.toml.Changes
_normalize_capabilities_and_forms), parameter-vector request validation (_ParameterVectorRequest), and MM prepared-session_ff_for,_provenance,_raw_hessian, and_mm_frequencieshelpers inq2mm/backends/contracts.py.BATCHED_HESSIANandREUSABLE_STATEverification inq2mm/backends/conformance.py, and discovery record normalization inq2mm/backends/discovery.py._validate_reference_prepare) acrossq2mm/backends/reference/ase.pyandq2mm/backends/reference/qcengine.py, unify ASEAtomsstate validation into_unsupported_atoms_state_reason, and share frequency wavefunction evaluation inq2mm/backends/reference/psi4.py._require_mm_force_fieldinq2mm/backends/mm/_term_support.pyand sharedmatch_mm_topology+_PreparedJaxBaseinq2mm/backends/mm/_jax_common.py, eliminating repeated bond/angle matching passes, duplicatePreparedJax/PreparedJaxMdsession hooks, and the duplicated harmonic vs. MM3energy_fnbody inq2mm/backends/mm/jax_engine.py._build_vdw_force,_exception_14_params) inq2mm/backends/mm/openmm.pyand template export checks (_uses_template_export) inq2mm/backends/mm/tinker.py.q2mm.backends.mm*and remove the remaining[[tool.mypy.overrides]]grandfather block inpyproject.tomlso all 109 source files are checked with zeroignore_errorsoverrides.Testing
python -m ruff check q2mm/ test/ scripts/,python -m ruff format --check q2mm test scripts examples, andpython -m mypy q2mm/pass with zero errors across all 109 source files (zeroignore_errorsoverrides remaining inpyproject.toml).7592 passedin core tests,340 passedin JAX/contract backend tests, plus direct unit coverage for_raw_hessian/_mm_frequenciespenalty mode,_exception_14_params,TinkerBackend._uses_template_export, andmatch_mm_topology).openmm-cpu,tinker,jax-cpu,jax-md-cpu,parity-openmm-jax,parity-openmm-tinker, andparity-jax-jaxmd—pass on this branch.