Skip to content

Conversation

@brandynlucca
Copy link
Collaborator

This PR includes updated functions, methods, etc. for running the matrix inversion analysis (for both krill and in general).

Note: the tests have pretty spotty coverage at the moment so I am still actively working on these to make sure at least the primary usage is covered and working from there.

Name                                                       Stmts   Miss  Cover
------------------------------------------------------------------------------
echopop\inversion\inversion_matrix.py                        192    117    39%
echopop\inversion\operations.py                               65     35    46%
echopop\inversion\scattering_models.py                        95     82    14%

@brandynlucca brandynlucca self-assigned this Sep 1, 2025
@brandynlucca brandynlucca marked this pull request as ready for review September 3, 2025 19:41
@brandynlucca
Copy link
Collaborator Author

Did you observe significant benefits to go with JIT compilation for the calculations under scattering_models.py?

Yep! It's possible that it was just my machine, but I was running into significant performance issues when running the optimization step via lmfit. So when I profiled the code, the pcdwba and pcdwba_fbs functions expectedly overshadowed the other operations as being the costliest. For the overall pcdwba function, a single run of the function was taking upwards of ~2 seconds per call, which when repeated over the optimization results meant a single transect (i.e. a single parameter set) was sometimes taking up to ~16 minutes (extrapolated out to ~27 hours per 100 transects).

When profiling those functions, the Bessel function interpolation was heads-and-shoulders above everything else. Adding the @njit(fastmath=True) decorator around the wrapper function batch_interp conferred a 10-fold decrease in the calculation time for pcdwba_fbs. For whatever reason, the phase calculation was also a major contributor to the bottleneck despite being a pretty straightforward calculation. Wrapping that calculation with the fast_phase function with @njit decorator effectively negated how much the calculation contributed to the slowdown.

From what I understand, I think converting the frequency-loop within pcdwba_fbs to be a JIT-compiled function would probably have been the better approach, but I didn't want to overcomplicate things for the time being until there is a clear need for improving performance (i.e. not now). I just made sure that I could at least make it through a full set of model runs on my end of things so I could actually bugtest and identify edge cases that I hadn't anticipated.

@brandynlucca brandynlucca linked an issue Sep 22, 2025 that may be closed by this pull request
@brandynlucca brandynlucca merged commit 7aa51f2 into OSOceanAcoustics:main Oct 14, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add krill inversion to the inversion class

2 participants