Change matrix format to CSC in depletion #2764
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
This PR is related to #2703, but is just looking at changing the matrix format (no change to the solver method) since in my test case this reduces the time spent in CRAM by more than 25% (for
IndependentOperator
calculations). The majority of the speed up is actually just from setting the matrix format ofident = sp.eye(A.shape[0], format='csc')
to be compatible withA
prior to looping over the residues and also works for CSR format. The motivation to change to CSC is to avoidSparseEfficiencyWarnings
and repeated conversions from CSR to CSC once we introduced explicit LU factorization as outlined in #2703. My idea here was to work through restructuring any necessary regression tests here to make sure we aren't making depletion less accurate. Interestingly enough the CSC format change results in fewer negative density warnings as shown in the files attached (it's not the addition of the factorization like I originally thought)One test case didn't pass locally, although I did confirm that the resulting atom numbers coming out of CRAM agree to within a relative tolerance of 1e-14 between this patch and develop. I believe the error is resulting from the calculated reaction rates in the transport run done when
final_step=True
.Below are the profile outputs for this problem:
no_patch.txt
csc_patch.txt
Update after merging #2771 and #2779: This PR offers negligible speed up (but at least no slow down) while reducing the number of negative density warnings, plus is more efficient for future work to be carried out in #2703 (see updated outputs below).
with_no_csc_patch.txt
with_csc_patch.txt
Checklist
- [ ] I have run clang-format (version 15) on any C++ source files (if applicable)- [ ] I have added tests that prove my fix is effective or that my feature works (if applicable)