cctbx / cctbx_project

Computational Crystallography Toolbox
https://cci.lbl.gov/docs/cctbx
Other
207 stars 111 forks source link

Mpi helper counter #991

Closed Baharis closed 1 month ago

Baharis commented 1 month ago

I was working on a custom cctbx.xfel worker and found myself gathering + counting objects multiple times. I realized that mpi_helper could just as well use a simple count method that returns a Counter object (a dict-like that automatically counts every occurrence of input list or dict).

While at it, I realized that the mpi_helper methods could be simplified; in particular, the flex_type can be implicitly learned from flex_array – as long as the root rank has a not-None flex_array. Consequently, I allowed the flex_type to be inherited from flex_array if left undefined.

Initially, I wanted to simplify all instances where cumulative_flex and aggregate_flex use "redundant" flex_type, but since it works in case of completely empty input, I left it as it. After all, Explicit is better than implicit.

Baharis commented 1 month ago

Note: I found an implementation of MPI.reduce.SUM for counters, but it was needlessly complex compared to this.