Skip to content

Simplify Python RPCA: remove dead code, fix numba structure, vectorize hot loop#1

Open
mazenahmad wants to merge 3 commits into
masterfrom
claude/simplify-python-code-HjbzQ
Open

Simplify Python RPCA: remove dead code, fix numba structure, vectorize hot loop#1
mazenahmad wants to merge 3 commits into
masterfrom
claude/simplify-python-code-HjbzQ

Conversation

@mazenahmad

Copy link
Copy Markdown
Owner
  • Move GPA accumulation kernel to a module-level @njit function instead of
    @jit on an instance method (numba cannot compile self); drop the
    ProcessPoolExecutor + wrapper + chunking machinery it required and let
    numba handle per-frame parallelism. Compute the reference mean once
    instead of every frame, and preallocate the coords array.
  • Delete dead helpers _calculate_rotation_matrix and _project_coordinates.
  • Collapse the O(n_res^2 * atoms^2) interaction-matrix loop into per-residue
    group vectors (G_i . G_j) for identical results in O(n_res^2).
  • Drop unused imports (align, cdist, ThreadPoolExecutor, multiprocessing,
    numba float64/int64) and no-op per-method OMP_NUM_THREADS env writes.
  • Replace the broken per-frame time scan in read_trajectory with a
    materialized times array + np.searchsorted.
  • Remove the invalid n_jobs kwarg passed to AnalysisBase and use zero-arg
    super() in the nested FastCovarianceAnalysis class.

https://claude.ai/code/session_018SSc1GoJMfc7Ey8n9EKgrK

claude added 3 commits June 1, 2026 19:07
…e hot loop

- Move GPA accumulation kernel to a module-level @njit function instead of
  @jit on an instance method (numba cannot compile self); drop the
  ProcessPoolExecutor + wrapper + chunking machinery it required and let
  numba handle per-frame parallelism. Compute the reference mean once
  instead of every frame, and preallocate the coords array.
- Delete dead helpers _calculate_rotation_matrix and _project_coordinates.
- Collapse the O(n_res^2 * atoms^2) interaction-matrix loop into per-residue
  group vectors (G_i . G_j) for identical results in O(n_res^2).
- Drop unused imports (align, cdist, ThreadPoolExecutor, multiprocessing,
  numba float64/int64) and no-op per-method OMP_NUM_THREADS env writes.
- Replace the broken per-frame time scan in read_trajectory with a
  materialized times array + np.searchsorted.
- Remove the invalid n_jobs kwarg passed to AnalysisBase and use zero-arg
  super() in the nested FastCovarianceAnalysis class.

https://claude.ai/code/session_018SSc1GoJMfc7Ey8n9EKgrK
…ACS/MDA

Proof-of-concept Python package that reuses the project's original C
numerical core for relative PCA without any GROMACS or MDAnalysis
dependency.

- rpca_api.c/.h: thin buffer-in/buffer-out C entry point that calls
  Simultaneous_Diagonalization() from src/linear_algebra.c and adds the
  relative-PCA KL scoring/ordering glue.
- _sdiag.pyx: zero-copy, nogil Cython binding exposing sdiag() on numpy
  arrays; returns geigval/gevec/kl/kl_m/acc_kl/rank.
- setup.py links the package's C API against ../src/linear_algebra.c
  (single source of truth) and LAPACK/BLAS only.
- Tests validate the defining property (G^T A G = I, G^T B G = diag),
  the KL formula and ordering, and cross-check eigenvalues against
  scipy.linalg.eigh. The built extension links only openblas/libm/libc/
  libgfortran - verified no gromacs/mdanalysis.

https://claude.ai/code/session_018SSc1GoJMfc7Ey8n9EKgrK
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