diff --git a/docs/io/optional/index.rst b/docs/io/optional/index.rst
index de5fe67d99b..77c8c737a74 100644
--- a/docs/io/optional/index.rst
+++ b/docs/io/optional/index.rst
@@ -9,6 +9,7 @@ TARDIS also allows other inputs that are passed as arguments into the ``run_tard
custom_source
callback_example
+ logging_configuration
Additionally, ``run_tardis`` can take in a filepath for the atomic data and a boolian for virtual packet logging, both of
diff --git a/docs/io/optional/logging_configuration.ipynb b/docs/io/optional/logging_configuration.ipynb
new file mode 100644
index 00000000000..2cdb0bd4a0e
--- /dev/null
+++ b/docs/io/optional/logging_configuration.ipynb
@@ -0,0 +1,512 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "67d6982f",
+ "metadata": {},
+ "source": [
+ "# Configuring the Logging Output for TARDIS"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "ac4ba612",
+ "metadata": {},
+ "source": [
+ "**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.
\n",
+ "**TARDIS** allows configuring the logger via *Functional Arguments* as well as *YAML Parameters*.\n",
+ "The following code snippets are some of the possible configuration that is available for the notebook logging done with TARDIS simulation."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "ce886182",
+ "metadata": {},
+ "source": [
+ "## Default Configuration"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "34e59abc",
+ "metadata": {},
+ "source": [
+ "The default configuration of the Notebook Simulation logger is such that it doesn't output any logs."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "41da9db6",
+ "metadata": {},
+ "source": [
+ "The output simulation logging, while executing the **TARDIS** simulation (default behaviour), can be seen below:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "018bb127",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from tardis import run_tardis\n",
+ "from tardis.io.atom_data.util import download_atom_data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ad59aa05",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "download_atom_data('kurucz_cd23_chianti_H_He')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "64cf4bb2",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "sim = run_tardis(\"tardis_config_logger.yml\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "9bf77405",
+ "metadata": {},
+ "source": [
+ "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."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "420dd7c2",
+ "metadata": {},
+ "source": [
+ "## Logging Configuration (Functional Arguments)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "ac8d5088",
+ "metadata": {},
+ "source": [
+ "The `run_tardis()` function from the `tardis module` has two functional arguments:`log_state` & `specific`."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d58f2d9c",
+ "metadata": {},
+ "source": [
+ "
\n",
+ " Both log_state & specific are optional arguments for the run_tardis() function, however, if specific argument is used then, log_state must be set to a particular level.\n",
+ "
"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "1176f370",
+ "metadata": {},
+ "source": [
+ "### `log_state`"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c3547b04",
+ "metadata": {},
+ "source": [
+ "The `log_state` 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**."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "dc2dcd71",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "sim = run_tardis(\"tardis_config_logger.yml\", log_state=\"Info\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "52e778bc",
+ "metadata": {},
+ "source": [
+ "By setting up the `log_state` parameter to **\"Info\"** in the above example, we can check that the logs are at the **\"Info\"** or higher logging level. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "25277fe8",
+ "metadata": {},
+ "source": [
+ "### `specific`"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "56a5ef36",
+ "metadata": {},
+ "source": [
+ "The `specific` argument tells the logger to capture log messages set by the `log_state` parameter. It can only take *Boolean* values for input, which are `True` or `False`. Take for example the following:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a0df43d1",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "sim = run_tardis(\"tardis_config_logger.yml\", log_state=\"Debug\", specific=True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5c6ff57c",
+ "metadata": {},
+ "source": [
+ "It can be examined that, when we set `specific` to `True`, the log messages captured were only at the `DEBUG` log level.
This allows for logging only specified logging messages for inspection."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5083321b",
+ "metadata": {},
+ "source": [
+ "The changes in the captured log messages can be seen when we set `specific` to `False`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "566919b3",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "sim = run_tardis(\"tardis_config_logger.yml\", log_state=\"Debug\", specific=False)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "42ddc98b",
+ "metadata": {},
+ "source": [
+ "It can be examined in this example that when we kept `specific` to `False`, the captured log output includes all log messages from `DEBUG` and higher logging levels, which is the default behavior of the logger."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f9f478f6",
+ "metadata": {},
+ "source": [
+ "## Logging Configuration (YAML Configuration)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "0d672a8d",
+ "metadata": {},
+ "source": [
+ "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:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "cd8c3eed",
+ "metadata": {},
+ "source": [
+ "```YAML\n",
+ "...\n",
+ "debug:\n",
+ " log_state: \"Info\"\n",
+ " specific : False\n",
+ "```"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "85ea7ae2",
+ "metadata": {},
+ "source": [
+ "The `debug` schema includes the `log_state` & `specific` parameters."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "65204c82",
+ "metadata": {},
+ "source": [
+ "\n",
+ " The debug section of the YAML config file is optional. The log_state 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.\n",
+ "
"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "62750463",
+ "metadata": {},
+ "source": [
+ "Let us load the `tardis_config_logger.yml` configuration to a variable & check out the schema:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "d9a5e83b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from tardis.io.config_reader import Configuration"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a1fa5e1b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Loading the Schema \n",
+ "config = Configuration.from_yaml(\"tardis_config_logger.yml\")\n",
+ "\n",
+ "# Checking the Debug Schema via dictionary\n",
+ "config[\"debug\"]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "7f5f2d9f",
+ "metadata": {},
+ "source": [
+ "### `log_state`"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "1389e902",
+ "metadata": {},
+ "source": [
+ "The `log_state` parameter, in the `debug` section of the config file, is similar in functionality to the `log_state` 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**."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3bdd9972",
+ "metadata": {},
+ "source": [
+ "Let us see an example of the captured simulation logging output, when the `log_state` parameter is set to `\"Info\"` log level in the `tardis_config_logger.yml` config file."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "88223ed0",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "config[\"debug\"][\"log_state\"] = \"Info\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ad8eac94",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "# Running the simulation by passing the config dictionary to `run_tardis()` function\n",
+ "sim = run_tardis(config)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3fadc651",
+ "metadata": {},
+ "source": [
+ "### `specific`"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "df50d2e1",
+ "metadata": {},
+ "source": [
+ "The `specific` parameter in the `debug` section of the schema is similar in functionality to the `specific` functional argument. It takes **Boolean** values, i.e., `True` or `False`. It is an optional parameter. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b71946ad",
+ "metadata": {},
+ "source": [
+ "Let us see an example when we set `specific` to `True` at the `Debug` level."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "64ce1048",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "config[\"debug\"][\"log_state\"] = \"Debug\"\n",
+ "config[\"debug\"][\"specific\"] = True"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "33696bdd",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "sim = run_tardis(config)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3e895aec",
+ "metadata": {},
+ "source": [
+ "Setting `specific` to `False` to check the actual output at the `DEBUG` level for the simulation logs."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "762c858f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "config[\"debug\"][\"specific\"] = False"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "581f2d8d",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "sim = run_tardis(config)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5e8f1dbe",
+ "metadata": {},
+ "source": [
+ "### What Happens When Both Parameters Are Specified? { Function & YAML Arguments }"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f32403c7",
+ "metadata": {},
+ "source": [
+ "If a user specifies both the parameters passed through the `log_state` & `log_state` in the **YAML** configuration file, then the `log_state` parameter *(Functional Argument)* takes precedence & is used to determine the logging level for the simulation logs."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f2a24e11",
+ "metadata": {},
+ "source": [
+ "Let us consider the following example for the configuration:"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "863042a4",
+ "metadata": {},
+ "source": [
+ "Continuing from the previous example, the `config[\"debug\"][\"log_state\"]` is set to `Debug` via the **YAML** file. The user will also set the `log_state` {Functional Argument} to `Info`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "30763e52",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "sim = run_tardis(config, log_state = \"Info\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "674f4972",
+ "metadata": {},
+ "source": [
+ "A new message can be seen from the execution of the simulation,\n",
+ "```\n",
+ "log_state is defined both in Functional Argument & YAML Configuration {debug section}\n",
+ "log_state = Info will be used for Log Level Determination\n",
+ "```\n",
+ "that is informing the user which input log level value will determine the logging level. Thus, `log_state = \"Info\"` is used for logging the simulation output."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "9ff806bd",
+ "metadata": {},
+ "source": [
+ "In regards to the `specific` parameter, if any of the config input value is `True`, then `specific` will be set to `True` for the simulation output."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5d1900f5",
+ "metadata": {
+ "scrolled": false
+ },
+ "outputs": [],
+ "source": [
+ "sim = run_tardis(config, log_state = \"Info\", specific = True)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.7.10"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/docs/io/optional/tardis_config_logger.yml b/docs/io/optional/tardis_config_logger.yml
new file mode 100644
index 00000000000..d61e71b2814
--- /dev/null
+++ b/docs/io/optional/tardis_config_logger.yml
@@ -0,0 +1,60 @@
+# Example YAML configuration for TARDIS Simulation Logging
+tardis_config_version: v1.0
+
+supernova:
+ luminosity_requested: 9.44 log_lsun
+ time_explosion: 13 day
+
+atom_data: kurucz_cd23_chianti_H_He.h5
+
+model:
+ structure:
+ type: specific
+ velocity:
+ start: 1.1e4 km/s
+ stop: 20000 km/s
+ num: 20
+ density:
+ type: branch85_w7
+
+ abundances:
+ type: uniform
+ O: 0.19
+ Mg: 0.03
+ Si: 0.52
+ S: 0.19
+ Ar: 0.04
+ Ca: 0.03
+
+plasma:
+ disable_electron_scattering: no
+ ionization: lte
+ excitation: lte
+ radiative_rates_type: dilute-blackbody
+ line_interaction_type: macroatom
+
+montecarlo:
+ seed: 23111963
+ no_of_packets: 4.0e+3
+ iterations: 5
+ nthreads: 1
+
+ last_no_of_packets: 1.e+4
+ no_of_virtual_packets: 2
+
+ convergence_strategy:
+ type: damped
+ damping_constant: 1.0
+ threshold: 0.05
+ fraction: 0.8
+ hold_iterations: 3
+ t_inner:
+ damping_constant: 1.0
+
+spectrum:
+ start: 500 angstrom
+ stop: 20000 angstrom
+ num: 10000
+
+debug:
+ specific: False
\ No newline at end of file
diff --git a/docs/quickstart/quickstart.ipynb b/docs/quickstart/quickstart.ipynb
index bc0442a7df6..289e80a616e 100644
--- a/docs/quickstart/quickstart.ipynb
+++ b/docs/quickstart/quickstart.ipynb
@@ -77,7 +77,7 @@
"outputs": [],
"source": [
"#TARDIS now uses the data in the data repo\n",
- "sim = run_tardis('tardis_example.yml')"
+ "sim = run_tardis('tardis_example.yml', log_state = \"Info\")"
]
},
{
diff --git a/tardis/__init__.py b/tardis/__init__.py
index 7db1fb432e1..579a224268c 100644
--- a/tardis/__init__.py
+++ b/tardis/__init__.py
@@ -33,6 +33,131 @@
logger.addHandler(console_handler)
logging.getLogger("py.warnings").addHandler(console_handler)
+LOGGING_LEVELS = {
+ "NOTSET": logging.NOTSET,
+ "DEBUG": logging.DEBUG,
+ "INFO": logging.INFO,
+ "WARNING": logging.WARNING,
+ "ERROR": logging.ERROR,
+ "CRITICAL": logging.CRITICAL,
+}
+DEFAULT_LOG_STATE = "CRITICAL"
+
+
+class FilterLog(object):
+ """
+ Filter Log Class for Filtering Logging Output
+ to a particular level
+
+ Parameters
+ ----------
+ log_level : logging object
+ allows to have a filter for the
+ particular log_level
+ """
+
+ def __init__(self, log_level):
+ self.log_level = log_level
+
+ def filter(self, log_record):
+ """
+ filter() allows to set the logging level for
+ all the record that are being parsed & hence remove those
+ which are not of the particular level
+
+ Parameters
+ ----------
+ log_record : logging.record
+ which the paricular record upon which the
+ filter will be applied
+
+ Returns
+ -------
+ boolean : True, if the current log_record has the
+ level that of the specified log_level
+ False, if the current log_record doesn't have the
+ same log_level as the specified one
+ """
+ return log_record.levelno == self.log_level
+
+
+# Setting up a list to store the Logging Filters set by logger.addFilter()
+list_of_filter = []
+
+
+def logging_state(log_state, tardis_config, specific):
+ """
+ Function to set the logging configuration for the simulation output
+ Called from within run_tardis()
+ Configured via functional arguments passed through run_tardis() - log_state & specific
+ Configured via YAML parameters under `debug` section - logging_level & specific_logging
+
+ Parameters
+ ----------
+ log_state: str
+ Allows to input the log level for the simulation
+ Uses Python logging framework to determine the messages that will be output
+ specific: boolean
+ Allows to set specific logging levels. Logs of the `log_state` level would be output.
+ """
+
+ if "debug" in tardis_config:
+ specific = (
+ tardis_config["debug"]["specific"] if specific is None else specific
+ )
+
+ logging_level = (
+ log_state if log_state else tardis_config["debug"]["log_state"]
+ )
+
+ # Displays a message when both log_state & tardis["debug"]["log_state"] are specified
+ if log_state and tardis_config["debug"]["log_state"]:
+ print(
+ "log_state is defined both in Functional Argument & YAML Configuration {debug section}"
+ )
+ print(
+ f"log_state = {log_state.upper()} will be used for Log Level Determination\n"
+ )
+
+ else:
+ if log_state:
+ logging_level = log_state
+ else:
+ tardis_config["debug"] = {"log_state": DEFAULT_LOG_STATE}
+ logging_level = tardis_config["debug"]["log_state"]
+
+ if specific:
+ specific = specific
+
+ logging_level = logging_level.upper()
+ if not logging_level in LOGGING_LEVELS:
+ raise ValueError(
+ f"Passed Value for log_state = {logging_level} is Invalid. Must be one of the following {list(LOGGING_LEVELS.keys())}"
+ )
+
+ loggers = [
+ logging.getLogger(name) for name in logging.root.manager.loggerDict
+ ]
+ if logging_level in LOGGING_LEVELS:
+ for logger in loggers:
+ logger.setLevel(LOGGING_LEVELS[logging_level])
+
+ if list_of_filter:
+ for filter in list_of_filter:
+ for logger in loggers:
+ logger.removeFilter(filter)
+
+ if specific:
+ filter_log = FilterLog(LOGGING_LEVELS[logging_level])
+ list_of_filter.append(filter_log)
+ for logger in loggers:
+ logger.addFilter(filter_log)
+ else:
+ for filter in list_of_filter:
+ for logger in loggers:
+ logger.removeFilter(filter)
+
+
# ----------------------------------------------------------------------------
# pyne holds Python 3.7 on macOS, but refdata is pickled with protocol 5 (3.8.3)
diff --git a/tardis/base.py b/tardis/base.py
index 73766f7fe63..e9e03fe42bb 100644
--- a/tardis/base.py
+++ b/tardis/base.py
@@ -7,6 +7,8 @@ def run_tardis(
packet_source=None,
simulation_callbacks=[],
virtual_packet_logging=False,
+ log_state=None,
+ specific=None,
):
"""
This function is one of the core functions to run TARDIS from a given
@@ -31,16 +33,11 @@ def run_tardis(
-------
Simulation
"""
+ from tardis import logging_state
from tardis.io.config_reader import Configuration
from tardis.io.atom_data.base import AtomData
from tardis.simulation import Simulation
- if atom_data is not None:
- try:
- atom_data = AtomData.from_hdf(atom_data)
- except TypeError:
- atom_data = atom_data
-
if isinstance(config, Configuration):
tardis_config = config
else:
@@ -49,6 +46,14 @@ def run_tardis(
except TypeError:
tardis_config = Configuration.from_config_dict(config)
+ logging_state(log_state, tardis_config, specific)
+
+ if atom_data is not None:
+ try:
+ atom_data = AtomData.from_hdf(atom_data)
+ except TypeError:
+ atom_data = atom_data
+
simulation = Simulation.from_config(
tardis_config,
packet_source=packet_source,
diff --git a/tardis/io/schemas/base.yml b/tardis/io/schemas/base.yml
index 5bfdc0e774d..474d686e6ff 100644
--- a/tardis/io/schemas/base.yml
+++ b/tardis/io/schemas/base.yml
@@ -26,6 +26,9 @@ properties:
spectrum:
$ref: spectrum.yml
description: Final spectrum sampling
+ debug:
+ $ref: debug.yml
+ description: Debugging setup for the simulation
required:
- tardis_config_version
- atom_data
diff --git a/tardis/io/schemas/debug.yml b/tardis/io/schemas/debug.yml
new file mode 100644
index 00000000000..4f20081e442
--- /dev/null
+++ b/tardis/io/schemas/debug.yml
@@ -0,0 +1,22 @@
+$$target: debug.yml
+type: object
+additionalProperties: false
+properties:
+ log_state:
+ type: string
+ default: "Critical"
+ description: Sets the logging Level for the logger
+ properties:
+ type:
+ enum:
+ - "Notset"
+ - "Info"
+ - "Debug"
+ - "Warning"
+ - "Error"
+ - "Critical"
+ specific:
+ type: boolean
+ default: false
+ description: Allows for logging on the specified logging levels
+
diff --git a/tardis/io/tests/data/tardis_configv1_verysimple_logger.yml b/tardis/io/tests/data/tardis_configv1_verysimple_logger.yml
new file mode 100644
index 00000000000..ffe566ed792
--- /dev/null
+++ b/tardis/io/tests/data/tardis_configv1_verysimple_logger.yml
@@ -0,0 +1,51 @@
+tardis_config_version: v1.0
+
+supernova:
+ luminosity_requested: 2.8e9 solLum
+ time_explosion: 13 day
+
+atom_data: kurucz_atom_pure_simple.h5
+model:
+
+ structure:
+ type: specific
+
+ velocity:
+ start: 1.1e4 km/s
+ stop: 2.0e4 km/s
+ num: 1
+
+ density:
+ type: branch85_w7
+
+ abundances:
+ type: uniform
+ O: 1.0
+
+plasma:
+ ionization: lte
+ excitation: lte
+ radiative_rates_type: dilute-blackbody
+ line_interaction_type: macroatom
+
+montecarlo:
+ seed: 23111963
+ no_of_packets : 100
+ iterations: 3
+ last_no_of_packets: 10
+ no_of_virtual_packets: 0
+ convergence_strategy:
+ type: damped
+ damping_constant: 0.5
+ threshold: 0.05
+ lock_t_inner_cycles: 1
+ t_inner_update_exponent: -0.5
+
+spectrum:
+ start: 500 angstrom
+ stop: 20000 angstrom
+ num: 10000
+
+debug:
+ log_state: ""
+ specific: False
\ No newline at end of file
diff --git a/tardis/simulation/base.py b/tardis/simulation/base.py
index 61ca133c3e2..8e0d020a9ef 100644
--- a/tardis/simulation/base.py
+++ b/tardis/simulation/base.py
@@ -428,11 +428,21 @@ def log_plasma_state(
if is_notebook():
logger.info("\n\tPlasma stratification:")
- logger.info(
- display(
- plasma_state_log.iloc[::log_sampling].style.format("{:.3g}")
- )
- )
+
+ # Displaying the DataFrame only when the logging level is NOTSET, DEBUG or INFO
+ if logger.level <= logging.INFO:
+ if not logger.filters:
+ display(
+ plasma_state_log.iloc[::log_sampling].style.format(
+ "{:.3g}"
+ )
+ )
+ elif logger.filters[0].log_level == 20:
+ display(
+ plasma_state_log.iloc[::log_sampling].style.format(
+ "{:.3g}"
+ )
+ )
else:
output_df = ""
plasma_output = plasma_state_log.iloc[::log_sampling].to_string(
diff --git a/tardis/simulation/tests/test_simulation.py b/tardis/simulation/tests/test_simulation.py
index 567be2f5aba..ea6b0f55ffe 100644
--- a/tardis/simulation/tests/test_simulation.py
+++ b/tardis/simulation/tests/test_simulation.py
@@ -5,6 +5,7 @@
from tardis.io.config_reader import Configuration
from tardis.simulation import Simulation
+from tardis import run_tardis, LOGGING_LEVELS
import numpy as np
import pandas as pd
@@ -172,3 +173,79 @@ def test_logging_simulation(atomic_data_fname, caplog):
for record in caplog.records:
assert record.levelno >= logging.INFO
+
+
+# Testing Configuration of Logger via run_tardis() Function
+# TODO: Move to its own Testing Module (Logger)
+@pytest.mark.parametrize(
+ ["log_state", "specific"],
+ [
+ ("Info", False),
+ ("INFO", False),
+ ("INFO", True),
+ ("DEBUG", False),
+ ("DEBUG", True),
+ ("WARNING", True),
+ ("ERROR", True),
+ ("CRITICAL", True),
+ ("NOTSET", False),
+ ],
+)
+class TestSimulationLogging:
+ """
+ Class implemented for testing the logging configuration available via run_tardis()
+ Tests Functional Arguments : log_state & specific
+ Tests YAML Parameters : logging_level & specific_logging
+ """
+
+ def test_logging_config(
+ self, atomic_data_fname, caplog, log_state, specific
+ ):
+ config = Configuration.from_yaml(
+ "tardis/io/tests/data/tardis_configv1_verysimple_logger.yml"
+ )
+ config["atom_data"] = atomic_data_fname
+
+ caplog.clear()
+ run_tardis(config=config, log_state=log_state, specific=specific)
+ for record in caplog.records:
+ if specific == True:
+ assert record.levelno == LOGGING_LEVELS[log_state.upper()]
+ else:
+ assert record.levelno >= LOGGING_LEVELS[log_state.upper()]
+
+ def test_logging_config_yaml(
+ self, atomic_data_fname, caplog, log_state, specific
+ ):
+ config = Configuration.from_yaml(
+ "tardis/io/tests/data/tardis_configv1_verysimple_logger.yml"
+ )
+ config["atom_data"] = atomic_data_fname
+ config["debug"]["log_state"] = log_state
+ config["debug"]["specific"] = specific
+
+ caplog.clear()
+ run_tardis(config=config)
+ for record in caplog.records:
+ if specific == True:
+ assert record.levelno == LOGGING_LEVELS[log_state.upper()]
+ else:
+ assert record.levelno >= LOGGING_LEVELS[log_state.upper()]
+
+ def test_logging_both_specified(
+ self, atomic_data_fname, caplog, log_state, specific
+ ):
+ config = Configuration.from_yaml(
+ "tardis/io/tests/data/tardis_configv1_verysimple_logger.yml"
+ )
+ config["atom_data"] = atomic_data_fname
+ config["debug"]["log_state"] = log_state
+ config["debug"]["specific"] = specific
+
+ caplog.clear()
+ run_tardis(config=config, log_state=log_state, specific=specific)
+ for record in caplog.records:
+ if specific == True:
+ assert record.levelno == LOGGING_LEVELS[log_state.upper()]
+ else:
+ assert record.levelno >= LOGGING_LEVELS[log_state.upper()]