Skip to content

refactor(backends): Simplify backend helpers and type MM modules - #376

Merged
ericchansen merged 1 commit into
masterfrom
ericchansen-simplify-backends-layer
Oct 20, 2026
Merged

ericchansen merged 1 commit into
masterfrom
ericchansen-simplify-backends-layer

Conversation

@ericchansen

@ericchansen ericchansen commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR simplifies the q2mm.backends layer by deduplicating shared validation, topology-matching, and prepared-session helpers across contracts, conformance, reference backends, and MM backends, while making all seven q2mm.backends.mm* modules mypy-clean and removing the final [[tool.mypy.overrides]] grandfather block from pyproject.toml.

Changes

  • Unify capability and functional-form validation (_normalize_capabilities_and_forms), parameter-vector request validation (_ParameterVectorRequest), and MM prepared-session _ff_for, _provenance, _raw_hessian, and _mm_frequencies helpers in q2mm/backends/contracts.py.
  • Deduplicate undeclared BATCHED_HESSIAN and REUSABLE_STATE verification in q2mm/backends/conformance.py, and discovery record normalization in q2mm/backends/discovery.py.
  • Share reference preparation validation (_validate_reference_prepare) across q2mm/backends/reference/ase.py and q2mm/backends/reference/qcengine.py, unify ASE Atoms state validation into _unsupported_atoms_state_reason, and share frequency wavefunction evaluation in q2mm/backends/reference/psi4.py.
  • Add _require_mm_force_field in q2mm/backends/mm/_term_support.py and shared match_mm_topology + _PreparedJaxBase in q2mm/backends/mm/_jax_common.py, eliminating repeated bond/angle matching passes, duplicate PreparedJax/PreparedJaxMd session hooks, and the duplicated harmonic vs. MM3 energy_fn body in q2mm/backends/mm/jax_engine.py.
  • Deduplicate OpenMM vdW force and 1-4 exception construction (_build_vdw_force, _exception_14_params) in q2mm/backends/mm/openmm.py and template export checks (_uses_template_export) in q2mm/backends/mm/tinker.py.
  • Fix all type annotations across q2mm.backends.mm* and remove the remaining [[tool.mypy.overrides]] grandfather block in pyproject.toml so all 109 source files are checked with zero ignore_errors overrides.

Testing

  • Verified python -m ruff check q2mm/ test/ scripts/, python -m ruff format --check q2mm test scripts examples, and python -m mypy q2mm/ pass with zero errors across all 109 source files (zero ignore_errors overrides remaining in pyproject.toml).
  • Verified core and backend test suites pass (7592 passed in core tests, 340 passed in JAX/contract backend tests, plus direct unit coverage for _raw_hessian/_mm_frequencies penalty mode, _exception_14_params, TinkerBackend._uses_template_export, and match_mm_topology).
  • Verified all 19 CI jobs—including native openmm-cpu, tinker, jax-cpu, jax-md-cpu, parity-openmm-jax, parity-openmm-tinker, and parity-jax-jaxmd—pass on this branch.

Base automatically changed from ericchansen-refactor-review to master October 19, 2026 22:42
@ericchansen
ericchansen force-pushed the ericchansen-simplify-backends-layer branch from 5ae73d0 to 8612598 Compare October 19, 2026 22:44
@ericchansen
ericchansen requested a balanced review from Copilot October 19, 2026 22:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread q2mm/backends/contracts.py Resolved
@ericchansen
ericchansen force-pushed the ericchansen-simplify-backends-layer branch from 8612598 to c6c7372 Compare October 20, 2026 17:39
Copilot AI balanced review requested due to automatic review settings October 20, 2026 17:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Shared numerical paths span four MM engines and need human confirmation of backend-specific regression results beyond the reported JAX/contract coverage.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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
ericchansen force-pushed the ericchansen-simplify-backends-layer branch from c6c7372 to 6249c4c Compare October 20, 2026 18:04
Copilot AI balanced review requested due to automatic review settings October 20, 2026 18:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved blocking defects remain, and the prior frequency-penalty regression is addressed with dedicated coverage.

No open issues 🎉

Review effort: Balanced

@ericchansen
ericchansen merged commit 9f0cf0a into master Oct 20, 2026
20 checks passed
@ericchansen
ericchansen deleted the ericchansen-simplify-backends-layer branch October 20, 2026 19:23
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