This notebook is available at https://github.com/tardis-sn/tardis/tree/master/docs/development/profiling/profiling_example.ipynb

Basic Profile of TARDIS

A profile is a set of statistics that describes how often and for how long various parts of the program execute (cProfile). A majority of TARDIS can be profiled, however, some code is Numba code, which cannot be profiled. This is because Numba compiles these functions directly to machine code; the python interpreter doesn’t see these functions and therefore it doesn’t read them.

This notebook uses snakeviz, which is a graphical viewer for the output of cProfile, to visualize the results and make them interactive. In order to use SnakeViz, you must first download it via pip. The first cell loads SnakeViz and gets the notebook ready to run TARDIS.

[1]:
%load_ext snakeviz

from tardis import run_tardis
from tardis.io.atom_data.util import download_atom_data
download_atom_data('kurucz_cd23_chianti_H_He')
/usr/share/miniconda3/envs/tardis/lib/python3.7/importlib/_bootstrap.py:219: QAWarning: pyne.data is not yet QA compliant.
  return f(*args, **kwds)
Configuration File /home/runner/.astropy/config/tardis_internal_config.yml does not exist - creating new one from default
CRITICAL:root:
********************************************************************************

TARDIS will download different kinds of data (e.g. atomic) to its data directory /home/runner/Downloads/tardis-data

TARDIS DATA DIRECTORY not specified in /home/runner/.astropy/config/tardis_internal_config.yml:

ASSUMING DEFAULT DATA DIRECTORY /home/runner/Downloads/tardis-data
 YOU CAN CHANGE THIS AT ANY TIME IN /home/runner/.astropy/config/tardis_internal_config.yml

********************************************************************************


I am telling the cell below to use snakeviz on the function below, which is a run of TARDIS in its enteriety. An option is to add the -t flag, which will tell it to display the HTML in a new tab, instead of embedding it.

[2]:
%%snakeviz

run_tardis('tardis_example.yml')
[py.warnings         ][WARNING]  /usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/astropy/units/equivalencies.py:124: RuntimeWarning: divide by zero encountered in double_scalars
  (si.m, si.Hz, lambda x: _si.c.value / x),
 (warnings.py:110)
WARNING:py.warnings:/usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/astropy/units/equivalencies.py:124: RuntimeWarning: divide by zero encountered in double_scalars
  (si.m, si.Hz, lambda x: _si.c.value / x),

[py.warnings         ][WARNING]  /usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/traitlets/traitlets.py:3050: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
  FutureWarning,
 (warnings.py:110)
WARNING:py.warnings:/usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/traitlets/traitlets.py:3050: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
  FutureWarning,

Shell No. t_rad next_t_rad w next_w
0 9.93e+03 1.01e+04 0.4 0.507
5 9.85e+03 1.02e+04 0.211 0.197
10 9.78e+03 1.01e+04 0.143 0.117
15 9.71e+03 9.87e+03 0.105 0.0869
[py.warnings         ][WARNING]  /usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/astropy/units/equivalencies.py:124: RuntimeWarning: divide by zero encountered in double_scalars
  (si.m, si.Hz, lambda x: _si.c.value / x),
 (warnings.py:110)
WARNING:py.warnings:/usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/astropy/units/equivalencies.py:124: RuntimeWarning: divide by zero encountered in double_scalars
  (si.m, si.Hz, lambda x: _si.c.value / x),

Shell No. t_rad next_t_rad w next_w
0 1.01e+04 1.15e+04 0.507 0.546
5 1.02e+04 1.15e+04 0.197 0.223
10 1.01e+04 1.13e+04 0.117 0.135
15 9.87e+03 1.1e+04 0.0869 0.101
Shell No. t_rad next_t_rad w next_w
0 1.15e+04 1.05e+04 0.546 0.442
5 1.15e+04 1.08e+04 0.223 0.165
10 1.13e+04 1.07e+04 0.135 0.101
15 1.1e+04 1.02e+04 0.101 0.0781
Shell No. t_rad next_t_rad w next_w
0 1.05e+04 1.16e+04 0.442 0.498
5 1.08e+04 1.17e+04 0.165 0.201
10 1.07e+04 1.14e+04 0.101 0.127
15 1.02e+04 1.1e+04 0.0781 0.0953
Shell No. t_rad next_t_rad w next_w
0 1.16e+04 1.06e+04 0.498 0.444
5 1.17e+04 1.09e+04 0.201 0.162
10 1.14e+04 1.07e+04 0.127 0.101
15 1.1e+04 1.03e+04 0.0953 0.0769
Shell No. t_rad next_t_rad w next_w
0 1.06e+04 1.15e+04 0.444 0.51
5 1.09e+04 1.17e+04 0.162 0.201
10 1.07e+04 1.14e+04 0.101 0.127
15 1.03e+04 1.1e+04 0.0769 0.0955
Shell No. t_rad next_t_rad w next_w
0 1.15e+04 1.06e+04 0.51 0.443
5 1.17e+04 1.1e+04 0.201 0.158
10 1.14e+04 1.07e+04 0.127 0.102
15 1.1e+04 1.03e+04 0.0955 0.0768
Shell No. t_rad next_t_rad w next_w
0 1.06e+04 1.15e+04 0.443 0.502
5 1.1e+04 1.17e+04 0.158 0.197
10 1.07e+04 1.14e+04 0.102 0.124
15 1.03e+04 1.1e+04 0.0768 0.0941
Shell No. t_rad next_t_rad w next_w
0 1.15e+04 1.06e+04 0.502 0.443
5 1.17e+04 1.1e+04 0.197 0.161
10 1.14e+04 1.07e+04 0.124 0.102
15 1.1e+04 1.04e+04 0.0941 0.0753
Shell No. t_rad next_t_rad w next_w
0 1.06e+04 1.15e+04 0.443 0.505
5 1.1e+04 1.17e+04 0.161 0.197
10 1.07e+04 1.15e+04 0.102 0.122
15 1.04e+04 1.11e+04 0.0753 0.0933
Shell No. t_rad next_t_rad w next_w
0 1.15e+04 1.06e+04 0.505 0.444
5 1.17e+04 1.1e+04 0.197 0.162
10 1.15e+04 1.09e+04 0.122 0.0958
15 1.11e+04 1.05e+04 0.0933 0.0744
Shell No. t_rad next_t_rad w next_w
0 1.06e+04 1.16e+04 0.444 0.486
5 1.1e+04 1.18e+04 0.162 0.19
10 1.09e+04 1.14e+04 0.0958 0.121
15 1.05e+04 1.11e+04 0.0744 0.089
Shell No. t_rad next_t_rad w next_w
0 1.16e+04 1.07e+04 0.486 0.438
5 1.18e+04 1.1e+04 0.19 0.162
10 1.14e+04 1.08e+04 0.121 0.101
15 1.11e+04 1.04e+04 0.089 0.0767
Shell No. t_rad next_t_rad w next_w
0 1.07e+04 1.15e+04 0.438 0.495
5 1.1e+04 1.17e+04 0.162 0.191
10 1.08e+04 1.14e+04 0.101 0.12
15 1.04e+04 1.1e+04 0.0767 0.0918
Shell No. t_rad next_t_rad w next_w
0 1.15e+04 1.07e+04 0.495 0.449
5 1.17e+04 1.1e+04 0.191 0.163
10 1.14e+04 1.09e+04 0.12 0.0997
15 1.1e+04 1.05e+04 0.0918 0.0768
Shell No. t_rad next_t_rad w next_w
0 1.07e+04 1.15e+04 0.449 0.495
5 1.1e+04 1.18e+04 0.163 0.184
10 1.09e+04 1.14e+04 0.0997 0.122
15 1.05e+04 1.11e+04 0.0768 0.0898
Shell No. t_rad next_t_rad w next_w
0 1.15e+04 1.07e+04 0.495 0.439
5 1.18e+04 1.11e+04 0.184 0.16
10 1.14e+04 1.1e+04 0.122 0.0962
15 1.11e+04 1.05e+04 0.0898 0.0763
Shell No. t_rad next_t_rad w next_w
0 1.07e+04 1.14e+04 0.439 0.492
5 1.11e+04 1.17e+04 0.16 0.186
10 1.1e+04 1.15e+04 0.0962 0.117
15 1.05e+04 1.11e+04 0.0763 0.0876
Shell No. t_rad next_t_rad w next_w
0 1.14e+04 1.07e+04 0.492 0.441
5 1.17e+04 1.11e+04 0.186 0.161
10 1.15e+04 1.09e+04 0.117 0.1
15 1.11e+04 1.05e+04 0.0876 0.0765

*** Profile stats marshalled to file '/tmp/tmp6vf7_afp'.
Embedding SnakeViz in this document...

As SnakeViz uses a web browser to create the HTML to display, when this notebook is run the HTML isn’t viewable. In order to view this a picture of the HTML output is saved and displayed below.

The SnakeViz visualization gives two things. At the top is a stack trace, where you can see which functions call others, and how long those functions take in respect to the caller function. At the bottom is all of the information that cProfile provides.

The bottom left montecarlo_radial1d is montecarlo_main_loop. This function does a majority of the computation, yet there is nothing below it. This is because it, and all the functions that it calls, are Numba functions. montecarlo_main_loop is visible as montecarlo_radial1d calls it, but the functions that it calls are not visible as it is a Numba function.

If the SnakeViz is run again without restarting the kernel, then the times will decrease and more time will be spent in montecarlo_main_loop relative to montecarlo_radial1d, as the Numba functions will have all compiled.

If you run this notebook the HTML from cell 2 will be displayed at the bottom without issue; the lower cell is just a solution to display the SnakeViz output without having access to the HTML.

../../_images/tardis_prof.png