flixopt.config ¶
Classes¶
CONFIG ¶
Configuration for flixopt library.
Always call CONFIG.apply() after changes.
Note
flixopt uses loguru <https://loguru.readthedocs.io/>_ for logging.
Attributes:
| Name | Type | Description |
|---|---|---|
Logging | Logging configuration. | |
Modeling | Optimization modeling parameters. | |
Solving | Solver configuration and default parameters. | |
Plotting | Plotting configuration. | |
config_name | str | Configuration name. |
Examples:
Load from YAML file:
logging:
level: DEBUG
console: true
file: app.log
solving:
mip_gap: 0.001
time_limit_seconds: 600
Classes¶
Logging ¶
Logging configuration.
Silent by default. Enable via console=True or file='path'.
Attributes:
| Name | Type | Description |
|---|---|---|
level | Literal['DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'] | Logging level (DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL). |
file | str | None | Log file path for file logging (None to disable). |
console | bool | Literal['stdout', 'stderr'] | Enable console output (True/'stdout' or 'stderr'). |
max_file_size | int | Max file size in bytes before rotation. |
backup_count | int | Number of backup files to keep. |
verbose_tracebacks | bool | Show detailed tracebacks with variable values. |
Examples:
# Enable console logging
CONFIG.Logging.console = True
CONFIG.Logging.level = 'DEBUG'
CONFIG.apply()
# File logging with rotation
CONFIG.Logging.file = 'app.log'
CONFIG.Logging.max_file_size = 5_242_880 # 5MB
CONFIG.apply()
# Console to stderr
CONFIG.Logging.console = 'stderr'
CONFIG.apply()
Note
For advanced formatting or custom loguru configuration, use loguru's API directly after calling CONFIG.apply():
Modeling ¶
Solving ¶
Solver configuration and default parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
mip_gap | float | Default MIP gap tolerance for solver convergence. |
time_limit_seconds | int | Default time limit in seconds for solver runs. |
log_to_console | bool | Whether solver should output to console. |
log_main_results | bool | Whether to log main results after solving. |
Examples:
# Set tighter convergence and longer timeout
CONFIG.Solving.mip_gap = 0.001
CONFIG.Solving.time_limit_seconds = 600
CONFIG.Solving.log_to_console = False
CONFIG.apply()
Plotting ¶
Plotting configuration.
Configure backends via environment variables: - Matplotlib: Set MPLBACKEND environment variable (e.g., 'Agg', 'TkAgg') - Plotly: Set PLOTLY_RENDERER or use plotly.io.renderers.default
Attributes:
| Name | Type | Description |
|---|---|---|
default_show | bool | Default value for the |
default_engine | Literal['plotly', 'matplotlib'] | Default plotting engine. |
default_dpi | int | Default DPI for saved plots. |
default_facet_cols | int | Default number of columns for faceted plots. |
default_sequential_colorscale | str | Default colorscale for heatmaps and continuous data. |
default_qualitative_colorscale | str | Default colormap for categorical plots (bar/line/area charts). |
Examples:
# Set consistent theming
CONFIG.Plotting.plotly_template = 'plotly_dark'
CONFIG.apply()
# Configure default export and color settings
CONFIG.Plotting.default_dpi = 600
CONFIG.Plotting.default_sequential_colorscale = 'plasma'
CONFIG.Plotting.default_qualitative_colorscale = 'Dark24'
CONFIG.apply()
Functions¶
load_from_file classmethod ¶
Load configuration from YAML file and apply it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file | str | Path | Path to the YAML configuration file. | required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If the config file does not exist. |
to_dict classmethod ¶
Convert the configuration class into a dictionary for JSON serialization.
Returns:
| Type | Description |
|---|---|
dict | Dictionary representation of the current configuration. |
silent classmethod ¶
Configure for silent operation.
Disables console logging, solver output, and result logging for clean production runs. Does not show plots. Automatically calls apply().
debug classmethod ¶
Configure for debug mode with verbose output.
Enables console logging at DEBUG level, verbose tracebacks, and all solver output for troubleshooting. Automatically calls apply().
exploring classmethod ¶
Configure for exploring flixopt
Enables console logging at INFO level and all solver output. Also enables browser plotting for plotly with showing plots per default
browser_plotting classmethod ¶
Configure for interactive usage with plotly to open plots in browser.
Sets plotly.io.renderers.default = 'browser'. Useful for running examples and viewing interactive plots. Does NOT modify CONFIG.Plotting settings.
Respects FLIXOPT_CI environment variable if set.
Functions¶
change_logging_level ¶
change_logging_level(level_name: Literal['DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'])
Change the logging level for the flixopt logger.
.. deprecated:: 2.1.11 Use CONFIG.Logging.level = level_name and CONFIG.apply() instead. This function will be removed in version 3.0.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level_name | Literal['DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL'] | The logging level to set. | required |
Examples: