Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dipolarkernal speedup #473

Merged
merged 3 commits into from
Jun 12, 2024
Merged

Dipolarkernal speedup #473

merged 3 commits into from
Jun 12, 2024

Conversation

HKaras
Copy link
Member

@HKaras HKaras commented Jun 12, 2024

A significant speed up of the dipolar kernal

Currently the effective dipolar evolution time vector is interpolated on every run of dipolar kernal even though it never changes. Interpolation should be avoid as much as possible as it is very slow in Python. This interpolation is now cached so it only done once per pathway.

Speedup:
(Using CVXOPT nnlssolver) 9.0s -> 7.9s 10% faster
(Using quadprog nnlssolver) 2.8s -> 2.2s 20 % faster

CProfile (using quadprog):
Before:

   471585 function calls (454090 primitive calls) in 2.776 seconds

   Ordered by: internal time
   List reduced from 765 to 10 due to restriction <10>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
       60    0.584    0.010    0.585    0.010 linalg.py:1499(svd)
      101    0.549    0.005    0.550    0.005 linalg.py:492(inv)
      115    0.413    0.004    0.447    0.004 _bsplines.py:1138(make_interp_spline)
      101    0.207    0.002    0.929    0.009 selregparam.py:190(_evalalpha)
      157    0.153    0.001    0.164    0.001 solvers.py:1104(qpnnls)
      115    0.119    0.001    0.981    0.009 dipolarmodel.py:427(Vtwospin_nonlinear_fcn)
      157    0.095    0.001    0.096    0.001 solvers.py:88(_lsqcomponents)
      230    0.056    0.000    0.056    0.000 _bsplines.py:511(_evaluate)
       56    0.032    0.001    1.593    0.028 solvers.py:581(linear_problem)
      115    0.029    0.000    0.855    0.007 dipolarkernel.py:22(dipolarkernel)

After:

      450059 function calls (432453 primitive calls) in 2.194 seconds

   Ordered by: internal time
   List reduced from 766 to 10 due to restriction <10>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      101    0.704    0.007    0.705    0.007 linalg.py:492(inv)
       60    0.424    0.007    0.425    0.007 linalg.py:1499(svd)
      101    0.199    0.002    1.088    0.011 selregparam.py:190(_evalalpha)
      157    0.149    0.001    0.158    0.001 solvers.py:1104(qpnnls)
      157    0.108    0.001    0.108    0.001 solvers.py:88(_lsqcomponents)
      115    0.063    0.001    0.409    0.004 dipolarmodel.py:427(Vtwospin_nonlinear_fcn)
      230    0.035    0.000    0.035    0.000 _bsplines.py:511(_evaluate)
       56    0.029    0.001    1.613    0.029 solvers.py:581(linear_problem)
      115    0.026    0.000    0.339    0.003 dipolarkernel.py:22(dipolarkernel)
12876/348    0.024    0.000    0.078    0.000 arrayprint.py:789(recurser)

HKaras added 3 commits June 12, 2024 18:29
Interpolation in Scipy is very slow, currently the same interpolation is being rerun for every calculation of the dipolarkernal. This is now cached to speed it up.
This hunk of code is not needed when fresnel integrals are used so does not need to be evaluated
@HKaras HKaras marked this pull request as ready for review June 12, 2024 17:31
@HKaras HKaras merged commit a088f31 into JeschkeLab:main Jun 12, 2024
7 checks passed
@HKaras HKaras deleted the dipolarkernal_speedup branch June 12, 2024 17:33
HKaras added a commit to HKaras/DeerLab that referenced this pull request Jul 31, 2024
* Seperate Kinterpolator into its own function

Interpolation in Scipy is very slow, currently the same interpolation is being rerun for every calculation of the dipolarkernal. This is now cached to speed it up.

* Only run orientation selection on grid and integral based kernals

This hunk of code is not needed when fresnel integrals are used so does not need to be evaluated

* Update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants