Skip to content

Fix GoParallelTuple tuple truncation (\#120) and Tensor2 uninitialized phonon checks (\#47)#123

Open
mesonepigreco wants to merge 2 commits into
masterfrom
fix-issues-120-47
Open

Fix GoParallelTuple tuple truncation (\#120) and Tensor2 uninitialized phonon checks (\#47)#123
mesonepigreco wants to merge 2 commits into
masterfrom
fix-issues-120-47

Conversation

@mesonepigreco

Copy link
Copy Markdown
Collaborator

Summary

Fixes two open issues:

#120 — GoParallelTuple drops tuple elements with mpi4py

The mpi4py reduction path in GoParallelTuple had a one-line bug: result = results[0] overwrote the result with only the first element's allgathered list, silently dropping all other tuple elements. This affected any mpi4py run, including single-process.

Fix: Replace the broken block with a loop that properly reduces each tuple element across ranks.

Test: tests/TestParallel/test_goparalleltuple.py — verifies all tuple elements survive serial and mpi4py paths. Manual verification with mpirun -np 2 confirmed correct across-rank reduction.

#47 — Uninitialized phonon crashes Tensor2.SetupFromPhonons

Passing an empty Phonons() (no structure loaded) to SetupFromPhonons crashed with AttributeError: 'NoneType' object has no attribute 'unit_cell'. The issue also noted supercell mismatch detection.

Fix: Add an early validation check raising a clear ValueError when the phonon object has no structure or empty q_tot.

Test: tests/TestTensor2/test_setup_from_phonons.py — verifies clear errors for uninitialized phonons and supercell mismatches.

Bonus: Synchronized empty-work-item abort

Both GoParallel and GoParallelTuple now use MPI_COMM_WORLD.allreduce(MIN) to detect when any rank has no work items. All ranks raise together (via comm.Abort), preventing the hang that occurred when some ranks crashed alone before a collective call.

… checks

Fix #120: GoParallelTuple with mpi4py dropped all but the first element
of the returned tuple due to  overwriting only
the first allgathered element. Replace with a proper loop that reduces
each tuple element across ranks and returns the full result list.

Fix #47: Tensor2.SetupFromPhonons crashed with an unhelpful
AttributeError when passed an uninitialized Phonons object (no
structure loaded). Add an early validation that raises a clear
ValueError about the phonon not being initialized.

Also add synchronized empty-work-item checks in both GoParallel and
GoParallelTuple: when a rank has no work items, all ranks abort
together via MPI_Abort (or raise on master) with a clear message,
preventing the hang that occurred before.

Tests:
- test_goparalleltuple: verifies tuple elements survive serial and
  mpi4py paths, including across-rank reduction (mpirun -np 2 tested)
- test_setup_from_phonons: verifies clear errors for uninitialized
  phonons and supercell mismatches
@mesonepigreco mesonepigreco added this to the 1.7 milestone Jul 20, 2026
Previously the serial/mpi4py code path raised NotImplementedError when
reduce_op=None, even in serial mode where no cross-rank synchronization
is needed.  Fixed by returning the collected per-input results directly,
matching the behaviour of GoParallel (non-Tuple) which already supports
this case.
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