[WIP] Lanes's time complexity

using Plots
# Independent variables and parameters
Ns = [1; 1000:1000:10000] # Time steps
Ms = [512, 4096, 32768] # No. of atoms
Ps = [2^i for i in 0:8] # No. of processors
s = 0.05 # Serial code proportion
L = 60 # No. of configurations
I = 60 # No. of bispectrum components
UQ_subit = 100 # No. of UQ subiterations
UQ_runs = 100 # No. of UQ runs
UQ_prop = 0.1
STD_AD = 1.0
Enzyme = 0.25
# Time complexities. TODO: define time complexities
DFT(M, P) = M * (s + (1-s) / P)
SNAP_FITTING(M, P) = (L * M * I + L) / P + 2 * (L - (I + 2) / 3) * (I + 2)^2 / P
MD(M, P) = 3 * M * (s + (1-s) / P)
UQ(M, P, AD) = UQ_runs * M * AD / P
Lane1(N, M, P, AD) = N * UQ_subit * (DFT(M, P) + MD(M, P) + UQ(M, P, AD)) 
Lane3(N, M, P, AD) = N * UQ_prop  * (DFT(M, P) + SNAP_FITTING(M, P, AD)) +
                     N * UQ_subit * (MD(M, P)  + UQ(M, P, AD))
# twojmax = 6
# J = twojmax / 2.0
# ncoeff = round(Int, (J + 1) * (J + 2) * (( J + (1.5)) / 3. ) + 1)
# numTypes = 2
# A_cols = numTypes * ncoeff
# no_atomic_conf = 62
# A_rows(M) = no_atomic_conf * (1 + 3 * M + 3 * 3 * M)
# # https://www.stat.cmu.edu/~ryantibs/convexopt-S15/scribes/09-num-lin-alg-scribed.pdf
# SNAP_SYSTEM_DEF(M, P, AD) = 
# QR_SOL(M, P, AD) = 2 * (A_cols - A_rows(M) / 3) * A_rows(M)^2
# SNAP_FITTING(M, P, AD) = SNAP_SYSTEM_DEF(M, P, AD) + QR_SOL(M, P, AD)
# SNAP_FORCES(M, P, AD) = 3 * AD(M) + 3 * M * ncoeff * numTypes 
# Lane1(N, M, P, AD) = N * (DFT_FORCES(M, P) + MD(M, P) + UQ(M, P, AD)) 
# Lane2(N, M, P, AD) = N * (SNAP_FORCES(M, P, AD) + MD(M, P) + UQ(M, P, AD))
# Lane3(N, M, P, AD) = SNAP_FITTING(M, P, AD) + N * (SNAP_FORCES(M, P, AD) + MD(M, P) + UQ(M, P, AD))
17.5s

=

# Plot time complexity
plot()
styles = [:solid, :dash, :dot]
P = 1
for i in 1:length(Ms)
  local M = Ms[i]
  plot!(Ns, Lane1.(Ns, M, P, STD_AD), yaxis=:log, color="black",
        line=styles[i], linewidth=2.5, label = "$M atoms")
  plot!(Ns, Lane1.(Ns, M, P, Enzyme), yaxis=:log, color="red",
        line=styles[i], linewidth=2.5, label = "$M atoms")
end
plot!(  legend=:outerright, legendfontsize=10, 
        xtickfontsize=12, ytickfontsize=12,
        xguidefontsize=12, yguidefontsize=12, dpi=600)
ylabel!("Time complexity")
xlabel!("No. of time steps")
#savefig("Lane1_time_complexity_serial_prop_$s.png")
15.7s
# Plot time complexity difference
plot()
styles = [:solid, :dash, :dot]
N = Ns[end]
P = 1
diff = Lane1.(N, Ms, P, STD_AD) .- Lane1.(N, Ms, P, Enzyme)
plot!(diff, yaxis=:log, color="red", falpha=0.5, linewidth=2.5, st=:bar,
      xticks=(1:length(Ms), Ms), label = "$N time steps", m=5)
plot!(  legend=:topleft, legendfontsize=12, 
        xtickfontsize=12, ytickfontsize=12,
        xguidefontsize=12, yguidefontsize=12, dpi=600)
ylabel!("Time complexity")
xlabel!("No. of atoms")
#savefig("Lane1_time_complexity_diff_serial_prop_$s.png")
4.8s
# Plot speedup
styles = [:solid, :dash, :dot]
N = Ns[end]
M = Ms[end]
t_serial = Lane1(N, M, 1, STD_AD)
plot(Ps, t_serial ./ Lane1.(N, M, Ps, STD_AD), color="black",
     line=styles[1], linewidth=2.5, label = "Standard AD")
t_serial = Lane1(N, M, 1, Enzyme)
plot!(Ps, t_serial ./ Lane1.(N, M, Ps, Enzyme), color="red",
      line=styles[2], linewidth=2.5, label = "Enzyme")
plot!(  legend=:bottomright, legendfontsize=12, 
        xtickfontsize=12, ytickfontsize=12,
        xguidefontsize=12, yguidefontsize=12, dpi=600)
ylabel!("Theoretical speedup")
xlabel!("No. of processors")
#savefig("Lane1_speedup.png")
0.7s
Runtimes (1)