Fix Chain.form_matrix to work with scipy 1.12 #2922
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
openmc/openmc/deplete/chain.py
Line 680 in 23f19a0
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)