Configuration
astromodels
includes a configuration that allows users to set certain variables from the beginning
[1]:
from astromodels import astromodels_config, show_configuration
21:46:35 WARNING The naima package is not available. Models that depend on it will not be functions.py:47 available
WARNING The GSL library or the pygsl wrapper cannot be loaded. Models that depend on it functions.py:68 will not be available.
[2]:
show_configuration()
[2]:
config ┣━━ logging ┃ ┣━━ path: ~/.astromodels/log ┃ ┣━━ developer: False ┃ ┣━━ usr: True ┃ ┣━━ console: True ┃ ┣━━ level: 20 ┃ ┣━━ startup_warnings: True ┃ ┣━━ info_style: medium_spring_green ┃ ┣━━ warn_style: medium_orchid ┃ ┣━━ error_style: blink bold bright_red ┃ ┣━━ debug_style: blue_violet ┃ ┗━━ message_style: bold grey78 ┣━━ absorption_models ┃ ┣━━ tbabs_table: AbsTables.WILM ┃ ┣━━ phabs_table: AbsTables.AG89 ┃ ┗━━ ebl_table: EBLTable.dominguez ┗━━ modeling ┣━━ use_memoization: True ┣━━ use_parameter_transforms: True ┗━━ ignore_parameter_bounds: False
The configuration can be accessed and altered during runtime:
[3]:
astromodels_config.modeling.use_memoization = False
[4]:
show_configuration()
[4]:
config ┣━━ logging ┃ ┣━━ path: ~/.astromodels/log ┃ ┣━━ developer: False ┃ ┣━━ usr: True ┃ ┣━━ console: True ┃ ┣━━ level: 20 ┃ ┣━━ startup_warnings: True ┃ ┣━━ info_style: medium_spring_green ┃ ┣━━ warn_style: medium_orchid ┃ ┣━━ error_style: blink bold bright_red ┃ ┣━━ debug_style: blue_violet ┃ ┗━━ message_style: bold grey78 ┣━━ absorption_models ┃ ┣━━ tbabs_table: AbsTables.WILM ┃ ┣━━ phabs_table: AbsTables.AG89 ┃ ┗━━ ebl_table: EBLTable.dominguez ┗━━ modeling ┣━━ use_memoization: False ┣━━ use_parameter_transforms: True ┗━━ ignore_parameter_bounds: False
The user can create a configuration YAML file with any name and the extension .yml
and place it in the ~/.config/astromodels/
folder. An example file:
logging:
developer: False # do not store debug log file
usr: True # store a log file
console: True # print logs to screen
level: DEBUG # turn on debug message
modeling:
use_parameter_transforms: no # turn off parameter transforms
ignore_parameter_bounds: yes # ignore parameter bounds
Not all options are required to be set and the defaults will be applied to anything not set.
Configuration options
There are a few special configuration options
use_memoization
By default, astromodels functions memoize or cache their output. This is useful for various processes like optimization as speeds of the evaluation of repeated function calls with the same values. However, there is a slight overhead when caching values and when performing Bayesian fits, this can slow down the evaluation as chance of hitting the exact same values more than once should be low. Thus, it is possible to turn of memoization directly in the configuration.
use_parameter_transforms
Parameters can have transforms assigned to them. These transforms are used during optimization to transform the parameter into a different space, such as log10. However, this may not be desirable and is not needed (or used) during Bayesian fits. There is also a small overhead in computing these transforms. Thus, this can be turned off via the configuration.
ignore_parameter_bounds
The bounds of parameters can be used in during optimization but are not used during Bayesian fits (the prior on a parameter controls its bounds if any). Thus, it is possible to turn off errors occuring from trying to set parameters outside of thier bounds in the configuration.