Optimizing Performance¶
Selecting sensible propagation parameters¶
Calls to the the propagate()
method are almost always the most expensive
part of any model. Even the most efficient and streamlined models will suffer from poor
performance when working with large arrays and many wavelengths. Understanding how each
of the propagate()
method’s parameters influence accuracy and speed will
allow you to identify appropriate values for your specific needs.
propagate()
¶
Parameter |
Usage |
Performance considerations |
---|---|---|
|
Arrays representing wavelength and the corresponding weight of each wavelength in the propagation. |
Propagation time scales linearly with the number of wavelengths. |
|
Shape of output plane. |
The output plane size has minimal impact on propagation performance unless it is
astronomically large or if |
|
Shape of propagation plane. |
Propagation time scales quadtatically with |
|
Number of times to oversample the output and propagation planes. |
Propagation time scales quadratically with |
|
If |
radiometry.trim_spectrum()
¶
Parameter |
Usage |
Performance considerations |
---|---|---|
|
radiometry.sample_spectrum()
and radiometry.trim_spectrum()
¶
Parameter |
Usage |
Performance considerations |
---|---|---|
|
Multiprocessing¶
Using appropriately sized planes¶
Planes should be sized to ensure the smallest spatial features of interest are adequately sampled.
Image simulation¶
Caching¶
Plane attributes¶
A number of plane attributes are accessed with each propagation wavelength. This
behavior does does not impact performance unless any of these attributes are computed on
the fly or are otherwise expensive to retrieve. To mitigate any potential performance
impacts, Lentil’s propagate()
method performs a pre-propagation caching
step by calling each plane’s cache_propagate()
method, temporarily
storing a copy of possibly expensive to compute attributes for faster access during the
actual numerical propagation. When the propagation calculations are complete, a
post-propagation cleanup calls each plane’s clear_cache_propagate()
to clear any cached values.
The cached attributes are defined in a list in each Plane’s
cache_attrs
attribute. This list is user-settable but the only
valid values are ‘amplitude’ and ‘phase’. The default behavior is to cache both
amplitude and phase attributes.
DFT matrices¶
Profiling your code¶
There are several approaches to finding bottlenecks and inefficiencies. To really
understand what is happening, the code needs to be profiled. The Python standard
library includes several profilers.
cProfile
is simple to use and its profile results files can be visualized using
snakeviz.