Skip to content

made distributions agnostic of the distributed object - #1026

Merged
zerothi merged 1 commit into
mainfrom
mpi-agnostic
Oct 12, 2026
Merged

zerothi merged 1 commit into
mainfrom
mpi-agnostic

Conversation

@zerothi

@zerothi zerothi commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Moved the distributions from sisl/_core/mpi to sisl/mpi/_distribute.py and exposed them through sisl.mpi. The SparseCSR specifics now live in sisl/_core/_sparse_distribute.py, and sisl/_core/mpi is removed.

A Distribution now only holds the communicator and the indices it distributes, so it can be re-used on any object of the same length:

dist = BlockCyclicDistribution(n, blocksize=1, comm=None)
dist(obj, *args, **kwargs) # -> obj.sisl_distribute(dist, *args, **kwargs)

The object decides what distributing means (in-place assembly for SparseCSR, a generator could serve batches of k-points). The comm is keyword-only and defaults to sisl.mpi.get_comm(), so basic distributions need no communicator; size and the default rank in range/indices/count follow from the communicator.

Renames:

  • Partition -> Distribution
  • BlockCyclicPartition -> BlockCyclicDistribution
  • old Distribution (epoch/assembled) -> DistributionState, stored on the object in SparseCSR._dist_state (was _distribution)

Other changes:

  • distribute(csr, dist=None, op="single") accepts a distribution; a different distribution than the attached one re-ships all elements to their new owners.
  • distribute's default op was "insert", which its own check rejected; now "single".
  • Distribution equality also compares the communicator.
  • removed Distribution.len (ambiguous between n and size), use .n or .size.
  • removed Partition.from_comm and the partition/comm size check, the size now comes from the communicator.

Added documentation: a guide on distributing work under "Advanced usage" (docs/distribution.rst), the sisl.mpi API page (docs/api/mpi.rst), and SISL_MPI in docs/environment.rst.

Tests split into sisl/mpi/tests/test_distribute.py (distributions) and sisl/_core/tests/test_sparse_distribute.py (SparseCSR), including a parallel redistribution check.

Assisted-by: claude-code:claude-opus-5-5

  • Closes #
  • Added tests for new/changed functions?
  • Documentation for functionality in docs/
  • Changes documented in changes/<num>.<type>.rst

Moved the distributions from sisl/_core/mpi to sisl/mpi/_distribute.py
and exposed them through sisl.mpi. The SparseCSR specifics now live in
sisl/_core/_sparse_distribute.py, and sisl/_core/mpi is removed.

A Distribution now only holds the communicator and the indices it
distributes, so it can be re-used on any object of the same length:

  dist = BlockCyclicDistribution(n, blocksize=1, comm=None)
  dist(obj, *args, **kwargs)  # -> obj.__sisl_distribute__(dist, *args, **kwargs)

The object decides what distributing means (in-place assembly for
SparseCSR, a generator could serve batches of k-points).
The comm is keyword-only and defaults to sisl.mpi.get_comm(), so basic
distributions need no communicator; size and the default rank in
range/indices/count follow from the communicator.

Renames:
- Partition -> Distribution
- BlockCyclicPartition -> BlockCyclicDistribution
- old Distribution (epoch/assembled) -> DistributionState, stored on the
  object in SparseCSR._dist_state (was _distribution)

Other changes:
- distribute(csr, dist=None, op="single") accepts a distribution;
  a different distribution than the attached one re-ships all elements
  to their new owners.
- distribute's default op was "insert", which its own check rejected;
  now "single".
- Distribution equality also compares the communicator.
- removed Distribution.__len__ (ambiguous between n and size), use
  .n or .size.
- removed Partition.from_comm and the partition/comm size check, the
  size now comes from the communicator.

Added documentation: a guide on distributing work under
"Advanced usage" (docs/distribution.rst), the sisl.mpi API page
(docs/api/mpi.rst), and SISL_MPI in docs/environment.rst.

Tests split into sisl/mpi/tests/test_distribute.py (distributions) and
sisl/_core/tests/test_sparse_distribute.py (SparseCSR), including a
parallel redistribution check.

Signed-off-by: Nick Papior <nickpapior@gmail.com>
Assisted-by: claude-code:claude-opus-5-5
from sisl.mpi._distribute import Distribution, DistributionState

from .distribute import Partition
from .sparse import SparseCSR
Comment thread src/sisl/_core/sparse.py
distribute : the implementation, and the details
"""
from .mpi.sparse_distribute import distribute
from ._sparse_distribute import distribute
distribute,
local_rows,
)
from sisl._core._sparse_distribute import distribute, local_rows
@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.36691% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.45%. Comparing base (d481ce8) to head (7313e67).

Files with missing lines Patch % Lines
src/sisl/mpi/_distribute.py 80.00% 11 Missing ⚠️
src/sisl/_core/_sparse_distribute.py 95.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1026      +/-   ##
==========================================
+ Coverage   85.89%   86.45%   +0.56%     
==========================================
  Files         421      419       -2     
  Lines       55593    55495      -98     
==========================================
+ Hits        47751    47979     +228     
+ Misses       7842     7516     -326     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zerothi
zerothi merged commit bc0375a into main Oct 12, 2026
13 checks passed
@zerothi
zerothi deleted the mpi-agnostic branch October 12, 2026 12:18
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