Advanced Usage
Caching Neural Net Parameters
Caching the neural net parameters beforehand skips the process of reading in the parameter files when calling one of the analysis functions. This is particularly helpful in optmization settings where the analysis will be called many times.
using BenchmarkTools
x, y = NeuralFoil.naca4()
coordinates = [x y]
alpha = range(-5,10,step=1.0)
Re = 1e6
model_size = "xlarge"
# Without Caching
t = @benchmark get_aero_from_coordinates(coordinates, alpha, Re; model_size=model_size)BenchmarkTools.Trial: 837 samples with 1 evaluation per sample.
Range (min … max): 4.960 ms … 15.139 ms ┊ GC (min … max): 0.00% … 47.22%
Time (median): 5.564 ms ┊ GC (median): 0.00%
Time (mean ± σ): 5.959 ms ± 876.940 μs ┊ GC (mean ± σ): 9.00% ± 9.28%
▅█▆█▃▅▃▁ ▁▂▃▂▃▄
▃▄█████████▆▄▃▃▂▂▁▁▁▂▂▂▄▇███████▆▄▅▄▃▂▂▂▁▁▂▂▁▁▂▁▁▁▁▁▁▁▁▁▁▂▂ ▄
4.96 ms Histogram: frequency by time 8.33 ms <
Memory estimate: 10.68 MiB, allocs estimate: 17192.# With Caching
net_cache = NetParameters(;model_size=model_size)
t = @benchmark get_aero_from_coordinates(coordinates, alpha, Re; net_cache=net_cache)BenchmarkTools.Trial: 1641 samples with 1 evaluation per sample.
Range (min … max): 2.302 ms … 9.110 ms ┊ GC (min … max): 0.00% … 51.55%
Time (median): 2.648 ms ┊ GC (median): 0.00%
Time (mean ± σ): 3.044 ms ± 709.094 μs ┊ GC (mean ± σ): 13.58% ± 14.68%
▇█▅▄
▃▃▃▆████▇▇▅▅▆▄▄▃▃▂▂▂▁▁▂▂▁▂▂▁▁▂▁▁▁▂▂▂▃▃▄▆█▇█▆▆▅▄▃▃▃▂▂▂▂▁▁▂▁▂ ▃
2.3 ms Histogram: frequency by time 4.46 ms <
Memory estimate: 7.93 MiB, allocs estimate: 13643.As we can see, caching the network parameters is helpful if the analysis is to be called many times.