refactor: Central engine registry with decorator-based registration#140
Merged
ericchansen merged 2 commits intomasterfrom Mar 23, 2026
Merged
refactor: Central engine registry with decorator-based registration#140ericchansen merged 2 commits intomasterfrom
ericchansen merged 2 commits intomasterfrom
Conversation
- Create q2mm/backends/registry.py with register_mm/register_qm decorators, lazy discovery, get_engine/available_engines API - Decorate all 5 engine classes (@register_mm or @register_qm) - Replace 5 try/except blocks in conftest.py with registry query - Replace _discover_backends() in diagnostics/cli.py with registry - Add 17 unit tests for registry (test/test_registry.py) Net -42 lines: eliminates duplicated backend detection in conftest and cli.py. Adding a new engine now requires only the @register decorator — tests, CLI, and docs get it automatically. Closes #134 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a centralized backend engine registry (q2mm/backends/registry.py) to replace duplicated try/except backend detection across tests and diagnostics, enabling backend lookup via get_engine() and availability listing via available_engines().
Changes:
- Added
q2mm/backends/registry.pywith decorator-based registration (register_mm/register_qm) and discovery + retrieval APIs. - Updated all engine classes to self-register via decorators (OpenMM, Tinker, JAX, JAX-MD, Psi4).
- Refactored backend detection in
test/conftest.pyandq2mm/diagnostics/cli.pyto use the registry; addedtest/test_registry.pycoverage.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
q2mm/backends/registry.py |
New central registry, discovery, availability checks, and engine construction APIs. |
q2mm/backends/mm/openmm.py |
Registers OpenMM engine via @register_mm("openmm"). |
q2mm/backends/mm/tinker.py |
Registers Tinker engine via @register_mm("tinker"). |
q2mm/backends/mm/jax_engine.py |
Registers JAX engine via @register_mm("jax"). |
q2mm/backends/mm/jax_md_engine.py |
Registers JAX-MD engine via @register_mm("jax-md"). |
q2mm/backends/qm/psi4.py |
Registers Psi4 engine via @register_qm("psi4"). |
test/conftest.py |
Replaces per-backend try/except detection with registry-driven availability + marker mapping. |
q2mm/diagnostics/cli.py |
Replaces manual backend discovery with registry-based discovery for benchmark CLI. |
test/test_registry.py |
Adds unit tests for registration, availability, instantiation, kwargs forwarding, and errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Gate OpenMM-dependent registry tests with @pytest.mark.openmm so they skip when OpenMM is not installed - Fix EngineNotAvailable docstring: 'not registered' (not 'not available') to match actual semantics - Make error message assertion backend-agnostic Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Adds a central engine registry (
q2mm/backends/registry.py) that replaces scattered try/except backend detection with decorator-based registration and a singleget_engine()/available_engines()API.Changes
q2mm/backends/registry.py—register_mm()/register_qm()decorators, lazy discovery viaimportlib,get_engine(name, **kwargs),available_engines(), and typed retrieval helpers@register_mm("openmm")etc. to all 5 engine classes (OpenMM, Tinker, JAX, JAX-MD, Psi4)test/conftest.py: Replaced 5 try/except blocks (34 lines) with a singleavailable_engines()call + marker-to-registry mappingq2mm/diagnostics/cli.py: Replaced_discover_backends()(45 lines of try/except) with a registry-based implementation (20 lines)test/test_registry.py— 17 unit tests covering registration, availability, instantiation, kwargs forwarding, and error messagesImpact
@register_mm("name")on the class — tests, CLI, and docs pick it up automaticallyTesting
Closes #134