Skip to content

Commit

Permalink
qtcurrent: use j0 and j1 bessel functions (supposedly faster)
Browse files Browse the repository at this point in the history
  • Loading branch information
John Garrett committed May 16, 2023
1 parent 952a6b7 commit 4ea6c28
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions profile/benchmark/plot-results.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ax[i].text(0.95, 0.95, '{} tone'.format(i+1),
ha='right', va='top', transform=ax[i].transAxes)
ax[i].set_ylabel('Time (ms)')
ax[i].set_ylim(ymin=0)

ax[3].set_xlim([0, len(results[0])])
ax[3].set_xlabel('Trial number')
Expand All @@ -37,6 +38,7 @@
ax[i].text(0.95, 0.95, '{} tone'.format(i+1),
ha='right', va='top', transform=ax[i].transAxes)
ax[i].set_ylabel('Change (%)')
ax[i].set_ylim(ymax=0)

ax[3].set_xlim([0, len(results[0])])
ax[3].set_xlabel('Trial number')
Expand Down
1 change: 1 addition & 0 deletions profile/benchmark/results/coeff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Date / Time 1 Tone 2 Tone 3 Tone 4 Tone Comp
2020-06-26 18:11:06.033800 0.001584 0.003119 0.004673 0.005719 SI385814.local
2020-07-08 17:24:34.067181 0.001578 0.002397 0.003201 0.003792 SI385814.local
2023-04-02 14:50:20.841778 0.000956 0.001445 0.001975 0.002339 Johns-iMac.local
2023-05-15 22:34:20.711433 0.000913 0.001378 0.001819 0.002163 Johns-iMac.local
1 change: 1 addition & 0 deletions profile/benchmark/results/harmonic-balance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Date / Time 1 Tone 2 Tone 3 Tone 4 Tone Comp
2020-06-24 23:05:52.248639 0.010388 0.052701 0.688327 38.920361 SI385814.local
2020-06-26 18:18:05.051621 0.006548 0.036384 0.697109 39.292153 SI385814.local
2023-04-02 14:51:02.082464 0.003814 0.020309 0.501490 23.542724 Johns-iMac.local
2023-05-15 22:35:08.817191 0.003453 0.019249 0.486977 24.280405 Johns-iMac.local
1 change: 1 addition & 0 deletions profile/benchmark/results/qtcurrent.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Date / Time 1 Tone 2 Tone 3 Tone 4 Tone Comp
2020-06-24 22:55:09.311778 0.001124 0.004920 0.053502 0.934294 SI385814.local
2020-06-26 18:18:31.218578 0.000841 0.004336 0.050435 0.958465 SI385814.local
2023-04-02 14:54:38.451465 0.000506 0.003216 0.037850 0.640506 Johns-iMac.local
2023-05-15 22:33:03.519334 0.000513 0.003203 0.038375 0.646757 Johns-iMac.local
8 changes: 6 additions & 2 deletions qmix/qtcurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import numba as nb
import numpy as np
from scipy.special import jv as bessel
from scipy.special import j0, j1


# round frequency values to this number of decimal places
Expand Down Expand Up @@ -371,10 +372,13 @@ def calculate_phase_factor_coeff(vj, freq, num_f, num_p, num_b):
jac = np.zeros((num_f + 1, num_p + 1, max(num_b) * 2 + 1, npts), dtype=complex)
for f in range(1, num_f + 1):
for p in range(1, num_p + 1):
jac[f, p, 0] = bessel(0, alpha[f, p])
jac[f, p, 0] = j0(alpha[f, p])
for n in range(1, num_b[f - 1] + 1):
# using Bessel function identity
jn = bessel(n, alpha[f, p])
if n == 1:
jn = j1(alpha[f, p])
else:
jn = bessel(n, alpha[f, p])
jac[f, p, n] = jn * np.exp(-1j * n * phi[f, p])
jac[f, p, -n] = (-1)**n * np.conj(jac[f, p, n])

Expand Down

0 comments on commit 4ea6c28

Please sign in to comment.