-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Goal
Migrate CPPE incrementally from the current C++ core to a Python-native backend while preserving API behavior and numerical results, with C++ retained as a reference/fallback backend during the transition.
Why this approach
- Reduce build and deployment friction from mandatory C++ compilation.
- Keep scientific reliability by validating every Python component against the existing C++ implementation.
- Allow gradual adoption and rollback by switching backend at runtime.
Scope and principles
- Backend strategy: hybrid first (
cpp+python), then switch default only after parity/performance gates are met. - Porting order: non-FMM first; FMM last.
- Validation discipline: every migrated unit must have cpp-vs-python parity tests.
- Benchmarking axis: number of polarizable sites (
n_polsites) as primary scaling variable.
Success criteria
- API compatibility for Python users across key classes (
CppeState,BMatrix,MultipoleFields, etc.). - Numerical parity vs C++ within agreed tolerances for all migrated components.
- Competitive runtime for Python backend on representative systems/sizes.
- C++ build becomes optional first, then removable after one stabilization cycle.
Milestones
- Baseline tests and benchmark harness
- Backend selection plumbing (
cppvspython) - Non-FMM Python port (fields/solver/state flow)
- Numba parallelization and tuning
- Potfile Python reader parity
- FMM migration design (generator strategy)
- FMM Python port + validation
- Default backend switch
- C++ backend deprecation and removal
Checklist
- Define backend selection mechanism and configuration surface
- Add parity test matrix (component-level and end-to-end)
- Add pytest-parametrized benchmark suite by
n_polsites - Benchmark both backends in same tests (
cpp,python) - Capture warmup vs steady-state timings in benchmark output
- Add numerical-delta reporting alongside timing results
- Port
NuclearFieldsto Python backend - Port
MultipoleExpansionto Python backend - Port
BMatrixapply/diagonal ops to Python backend - Port induced moments solver path to Python backend
- Add Numba acceleration (
njit,parallel=True,prange) to hot kernels - Document Numba runtime tuning knobs (
NUMBA_NUM_THREADS, threading layer) - Implement Python potfile parser with strict parity to current CPPE semantics
- Instantiate CPPE-like Python domain objects from parsed potfiles
- Add reader parity tests against existing potfiles in
tests/potfiles - Decide FMM generator path (adapt
fmmgenor replacement codegen) - Specify FMM acceptance criteria (error envelope + speed targets)
- Port tree/interactions/FMM kernels to Python backend
- Validate FMM against
tests/test_fmm.pyand reference error data - Switch default backend to Python after gates pass
- Keep C++ backend as temporary fallback for one release cycle
- Remove mandatory C++ build from project deployment
Benchmarking plan (pytest-first)
- Use
pytestparametrization for:- backend:
cpp,python - workload: fields, solver, end-to-end
- system size buckets keyed by
n_polsites
- backend:
- Start with lightweight pytest timing; later evaluate
pytest-benchmarkand/orpytest-harvestfor richer persistence/reporting.
Potfile reader notes
- First target: strict parity with CPPE's current reader behavior (
@COORDINATES,ORDER,ORDER 1 1,EXCLISTS, AU/AA conversion, zero-fill behavior). - Follow-up milestone: consider optional support for extended sections inspired by polarizationsolver (
EXCLISTS_PERMANENT,EXCLISTS_INDUCED,@THOLE, distributed polarizabilities).
Risks and mitigations
- Risk: Irregular/tree-heavy kernels may underperform in pure Python.
- Mitigation: Keep C++ fallback, focus on Numba for hot loops, optimize data layout before FMM switch.
- Risk: Numerical drift between backends.
- Mitigation: enforce parity checks in CI and per-milestone acceptance gates.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request