Skip to content

Add mpi4py parallel backend support for distributed optimization#13

Open
darshanmandge wants to merge 2 commits into
mainfrom
feature/add-mpi4py-support
Open

Add mpi4py parallel backend support for distributed optimization#13
darshanmandge wants to merge 2 commits into
mainfrom
feature/add-mpi4py-support

Conversation

@darshanmandge

Copy link
Copy Markdown
Collaborator

Summary

This PR adds support for mpi4py as a parallel backend option, enabling distributed optimization across multiple MPI processes. This complements the existing ipyparallel and multiprocessing backends.

Changes

Core Changes

  • bluepyemodel/tools/multiprocessing.py: Added mpi_map_function() using MPI scatter/gather pattern
  • bluepyemodel/emodel_pipeline/emodel_pipeline.py: Added use_mpi parameter with proper mutual exclusivity check against use_ipyparallel and use_multiprocessing

Dependencies

  • pyproject.toml: Added mpi optional dependency (mpi4py>=3.0) and included it in the all group

Examples

  • examples/L5PC/pipeline.py: Added --use_mpi CLI argument
  • examples/nexus/pipeline.py: Added --use_mpi CLI argument
  • examples/nexus/run_pipeline.ipynb: Added use_mpi=False parameter

Usage

Install with MPI support:

pip install bluepyemodel[mpi]
# or
pip install mpi4py

- Add mpi_map_function() using scatter/gather pattern in multiprocessing.py
- Add mpi backend option to get_mapper()
- Add use_mpi parameter to EModel_pipeline with mutual exclusivity check
- Add mpi4py>=3.0 as optional dependency in pyproject.toml
- Update examples (L5PC, nexus) to support --use_mpi CLI flag
- Update nexus notebook with use_mpi parameter
@darshanmandge darshanmandge self-assigned this Jun 8, 2026
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
Comment thread examples/others/memodel/register_memodel.py Fixed
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 9.21986% with 128 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tests/unit_tests/test_multiprocessing.py 10.52% 102 Missing ⚠️
bluepyemodel/tools/multiprocessing.py 4.16% 23 Missing ⚠️
bluepyemodel/emodel_pipeline/emodel_pipeline.py 0.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
bluepyemodel/emodel_pipeline/emodel_pipeline.py 40.54% <0.00%> (ø)
bluepyemodel/tools/multiprocessing.py 26.22% <4.16%> (ø)
tests/unit_tests/test_multiprocessing.py 10.52% <10.52%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# Need to reimport to pick up the mock
import importlib

import bluepyemodel.tools.multiprocessing as mp
from unittest.mock import MagicMock
from unittest.mock import patch

import pytest
from bluepyemodel.tools import multiprocessing as mp

# Temporarily replace MPI import
original_func = mp.mpi_map_function
rank = 1

def mapper(func, it):
items = list(it)
forge_ontology_path = "./forge_ontology_path.yml" # this file also
# memodel_id = "<MEMODEL ID>" # replace with the id of the MEModel you want to update

mapper = map
morph_format = "swc" # assumes swc is always present and we do not care about small differences between format

# additional metadata we will need when saving me-model resource
subject_ontology = emodel_r.subject if hasattr(emodel_r, "subject") else None

# additional metadata we will need when saving me-model resource
subject_ontology = emodel_r.subject if hasattr(emodel_r, "subject") else None
brain_location_ontology = morph_r.brainLocation if hasattr(morph_r, "brainLocation") else None
Comment thread examples/others/memodel/register_memodel.py Dismissed
Comment thread examples/others/memodel/register_memodel.py Dismissed
- Remove unused imports from examples/others/memodel/register_memodel.py
  (pathlib, Dataset, scores, compute_responses,
  get_evaluator_from_access_point, copy_emodel_pdf_dependencies_to_new_path,
  compute_scores)
- Fix pycodestyle issues (blank lines, comment spacing, trailing whitespace)
- Apply black formatting to multiprocessing.py and register_memodel.py
- Add unit tests for mpi_map_function and get_mapper MPI backend
  (tests/unit_tests/test_multiprocessing.py)
@darshanmandge darshanmandge force-pushed the feature/add-mpi4py-support branch from 2893242 to 43fc450 Compare June 11, 2026 06:48
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.

1 participant