Skip to content

Improvements to the isotope sorting function. Refactor of the PyREBUS constructor (__init__).

Shriwise, Patrick requested to merge iso_sort_perf into development

This MR contains updates to the PyARCModel.sort_list_isotopes function to improve performance and reduce memory usage as well as a refactor of the PyREBUS constructor for clarity and slight performance improvements.

Notable changes to sort_list_isotopes include:

  • use of sets to check for isotopes added to be sorted instead of lists,
  • removal of a superfluous list of AZ values. The function now uses and sorts the set of AZ keys in dictionary_tosort,
  • use of defaultdict(list) to keep from having to check that entries are in the dictionary,
  • single retrieval of the isotope's homogenous mixture data to avoid additional key searches in dictionaries on the user object,
  • and some refactoring of logic to reduce the number of lines and improve readability.

These changes resulted in a 4-5x speedup in this function. For the complex ABTR problem @nstauff provided, it reduced the overall runtime by ~3 minutes (25% of the original runtime).

The refactor of PyREBUS.__init__ mostly involves an early loop continuation for empty lines in the reference file and changes to loop variables from indices to objects to skip repetition of indexing into lists. These had minor effects on performance, but make the code more readable in my opinion.

In several of these files I also found a number of loops using enumerate that didn't use the index value, so I've removed those to improve readability as well. A few unused imports have been removed also.

Edited by Shriwise, Patrick

Merge request reports