openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
699 stars 444 forks source link

Fix Chain.form_matrix to work with scipy 1.12 #2922

Closed paulromano closed 1 month ago

paulromano commented 1 month ago

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 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