Skip to content

Commit fb02c41

Browse files
committed
refactor(core): add initial backend and sample contracts
1 parent 71d5fbe commit fb02c41

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

deepks/core/contracts/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
"""Scaffold package for refactor architecture."""
1+
"""Core contracts for ML/physics backends and sample schemas."""
2+
3+
from .backends import ModelBackend, PhysicsBackend
4+
from .sample_schema import SampleSchema
5+
6+
__all__ = ["ModelBackend", "PhysicsBackend", "SampleSchema"]

deepks/core/contracts/backends.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Abstract backend contracts used by orchestration and pipelines.
2+
3+
These interfaces provide a stable boundary between orchestration logic and
4+
concrete ML/physics implementations during incremental refactoring.
5+
"""
6+
7+
from abc import ABC, abstractmethod
8+
9+
10+
class ModelBackend(ABC):
11+
"""Contract for ML model training/inference backends."""
12+
13+
@abstractmethod
14+
def train(self, **kwargs):
15+
"""Run model training with keyword-only configuration."""
16+
17+
@abstractmethod
18+
def evaluate(self, **kwargs):
19+
"""Run model evaluation and return backend-specific metrics."""
20+
21+
@abstractmethod
22+
def predict(self, **kwargs):
23+
"""Run model inference for a prepared input batch."""
24+
25+
26+
class PhysicsBackend(ABC):
27+
"""Contract for physics/SCF backends."""
28+
29+
@abstractmethod
30+
def run_scf(self, **kwargs):
31+
"""Run SCF calculation and return backend-specific outputs."""
32+
33+
@abstractmethod
34+
def collect_stats(self, **kwargs):
35+
"""Collect summary statistics from generated SCF results."""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Shared sample schema metadata for cross-layer data contracts."""
2+
3+
from dataclasses import dataclass
4+
from typing import Tuple
5+
6+
7+
@dataclass(frozen=True)
8+
class SampleSchema:
9+
"""Canonical key names and shape hints for model samples."""
10+
11+
energy_key: str = "lb_e"
12+
descriptor_key: str = "eig"
13+
force_key: str = "lb_f"
14+
stress_key: str = "lb_s"
15+
orbital_key: str = "lb_o"
16+
hamiltonian_k_key: str = "lb_vd"
17+
hamiltonian_r_key: str = "lb_vdr"
18+
19+
# Shape conventions are informational and used for schema checks.
20+
energy_shape: Tuple[str, ...] = ("nframe", "1")
21+
descriptor_shape: Tuple[str, ...] = ("nframe", "natom", "ndesc")
22+
force_shape: Tuple[str, ...] = ("nframe", "natom", "3")
23+
stress_shape: Tuple[str, ...] = ("nframe", "6")

0 commit comments

Comments
 (0)