The release of scipy 1.12 apparently broke OpenMC's depletion solver, which we deployed a temporary workaround for in #2854 by forcing CI to use an older version. This PR fixes the underlying issue so that the depletion solver works with scipy 1.12.
In this line, matrix_dok is a scipy.sparse.dok_matrix object, which prior to scipy 1.12 directly subclassed the dict class. However, in scipy 1.12 the design was changed so that a dictionary was stored as an attribute rather than the class subclassing dict directly (see scipy/scipy#18929), which breaks the implicit assumption of the line above that it can be treated like a dictionary. The reason this was originally done in OpenMC was because the performance of building a dictionary of (i, j) to matrix element values and then using that to update the DOK matrix all at once was found to be faster than incrementally updating a dok_matrix, but with the updates in scipy 1.12, the performance for this operation directly on the dok_matrix is supposed to be improved. So, my solution in this PR is to get rid of the temporary dict used to map (i, j) to matrix elements and instead update the dok_matrix directly.
Checklist
[x] I have performed a self-review of my own code
[x] I have run clang-format (version 15) on any C++ source files (if applicable)
[x] I have followed the style guidelines for Python source files (if applicable)
[x] I have made corresponding changes to the documentation (if applicable)
[x] I have added tests that prove my fix is effective or that my feature works (if applicable)
Description
The release of scipy 1.12 apparently broke OpenMC's depletion solver, which we deployed a temporary workaround for in #2854 by forcing CI to use an older version. This PR fixes the underlying issue so that the depletion solver works with scipy 1.12.
The problem was this line: https://github.com/openmc-dev/openmc/blob/23f19a0310f462c81313d4e21f3cb08a3695e85f/openmc/deplete/chain.py#L680
In this line,
matrix_dok
is ascipy.sparse.dok_matrix
object, which prior to scipy 1.12 directly subclassed thedict
class. However, in scipy 1.12 the design was changed so that a dictionary was stored as an attribute rather than the class subclassingdict
directly (see scipy/scipy#18929), which breaks the implicit assumption of the line above that it can be treated like a dictionary. The reason this was originally done in OpenMC was because the performance of building a dictionary of (i, j) to matrix element values and then using that to update the DOK matrix all at once was found to be faster than incrementally updating adok_matrix
, but with the updates in scipy 1.12, the performance for this operation directly on thedok_matrix
is supposed to be improved. So, my solution in this PR is to get rid of the temporary dict used to map (i, j) to matrix elements and instead update thedok_matrix
directly.Checklist
I have run clang-format (version 15) on any C++ source files (if applicable)I have made corresponding changes to the documentation (if applicable)I have added tests that prove my fix is effective or that my feature works (if applicable)