You can interact with this notebook online: Launch notebook

Configuring the Logging Output for TARDIS

TARDIS has a Notebook logger that logs information of Simulation runs. The logs allows to access vital information regarding the execution sequence, data for plasma stratification & progress of the simulation. TARDIS allows configuring the logger via Functional Arguments as well as YAML Parameters. The following code snippets are some of the possible configuration that is available for the notebook logging done with TARDIS simulation.

Default Configuration

The default configuration of the Notebook Simulation logger is such that it doesn’t output any logs.

The output simulation logging, while executing the TARDIS simulation (default behaviour), can be seen below:

[1]:
from tardis import run_tardis
from tardis.io.atom_data import download_atom_data
[2]:
# We download the atomic data needed to run the simulation
download_atom_data('kurucz_cd23_chianti_H_He')
Atomic Data kurucz_cd23_chianti_H_He already exists in /home/runner/Downloads/tardis-data/kurucz_cd23_chianti_H_He.h5. Will not download - override with force_download=True.
[3]:
sim = run_tardis("tardis_config_logger.yml", show_cplots=False)

It can be examined that the logs are not printed. The logging level, by default, is set to CRITICAL. Logs will only be captured if any CRITICAL level logs are encountered while running the simulation.

Logging Configuration (Functional Arguments)

The run_tardis() function from the tardis module has two functional arguments:log_level & specific_log_level.

Note

Both log_level & specific are optional arguments for the run_tardis() function, however, if specific argument is used then, log_level must be set to a particular level.

The log_level Argument

The log_level argument can be passed in run_tardis() to set the logging level for the simulation. The input for this argument must be one of the following: Notset, Debug, Info, Warning, Error or Critical.

[4]:
sim = run_tardis("tardis_config_logger.yml", log_level="Info", show_cplots=False)

By setting up the log_level parameter to “Info” in the above example, we can check that the logs are at the “Info” or higher logging level.

The specific Argument

The specific_log_level argument tells the logger to capture log messages set by the log_level parameter. It can only take Boolean values for input, which are True or False. Take for example the following:

[5]:
sim = run_tardis("tardis_config_logger.yml", log_level="Debug", specific_log_level=True, show_cplots=False)

It can be examined that, when we set specific_log_level to True, the log messages captured were only at the DEBUG log level. This allows for logging only specified logging messages for inspection.

The changes in the captured log messages can be seen when we set specific_log_level to False.

[6]:
sim = run_tardis("tardis_config_logger.yml", log_level="Debug", specific_log_level=False, show_cplots=False)

It can be examined in this example that when we kept specific_log_level to False, the captured log output includes all log messages from DEBUG and higher logging levels, which is the default behavior of the logger.

Logging Configuration (YAML Configuration)

The behavior of the logging output for the simulation can be configured via the tardis_config_logger.yml (YAML Configuration) file. For setting up the logger via the YAML file, the configuration file must include a debug section. An example configuration for the debug section can be seen below:

...
debug:
  log_level: "Info"
  specific_log_level : False

The debug schema includes the log_level & specific_log_level parameters.

Note

The debug section of the YAML config file is optional. The log_level and the specific arguments are optional as well. If none of the parameters are defined, then the values of these parameter fall back on the default values.

Let us load the tardis_config_logger.yml configuration to a variable & check out the schema:

[7]:
from tardis.io.configuration.config_reader import Configuration
[8]:
# Loading the Schema
config = Configuration.from_yaml("tardis_config_logger.yml")

# Checking the Debug Schema via dictionary
config["debug"]
[8]:
{'specific_log_level': False, 'log_level': 'Critical'}

The log_level Entry

The log_level parameter, in the debug section of the config file, is similar in functionality to the log_level functional argument that can be passed via the run_tardis() function. The value of this parameter must be one of the following: Notset, Debug, Info, Warning, Error or Critical.

Let us see an example of the captured simulation logging output, when the log_level parameter is set to "Info" log level in the tardis_config_logger.yml config file.

[9]:
config["debug"]["log_level"] = "Info"
[10]:
# Running the simulation by passing the config dictionary to `run_tardis()` function
sim = run_tardis(config, show_cplots=False)

The specific Entry

The specific_log_level parameter in the debug section of the schema is similar in functionality to the specific_log_level functional argument. It takes Boolean values, i.e., True or False. It is an optional parameter.

Let us see an example when we set specific_log_level to True at the Debug level.

[11]:
config["debug"]["log_level"] = "Debug"
config["debug"]["specific_log_level"] = True
[12]:
sim = run_tardis(config, show_cplots=False)

Setting specific_log_level to False to check the actual output at the DEBUG level for the simulation logs.

[13]:
config["debug"]["specific_log_level"] = False
[14]:
sim = run_tardis(config,show_cplots=False)

What Happens When Both Parameters Are Specified? { Function & YAML Arguments }

If a user specifies both the parameters passed through the log_level & log_level in the YAML configuration file, then the log_level parameter (Functional Argument) takes precedence & is used to determine the logging level for the simulation logs.

Let us consider the following example for the configuration:

Continuing from the previous example, the config["debug"]["log_level"] is set to Debug via the YAML file. The user will also set the log_level {Functional Argument} to Info.

[15]:
sim = run_tardis(config, log_level="Info")

A new message can be seen from the execution of the simulation,

log_level is defined both in Functional Argument & YAML Configuration {debug section}
log_level = Info will be used for Log Level Determination

that is informing the user which input log level value will determine the logging level. Thus, log_level = "Info" is used for logging the simulation output.

In regards to the specific_log_level parameter, if any of the config input value is True, then specific_log_level will be set to True for the simulation output.

[16]:
sim = run_tardis(config, log_level="Info", specific=True)