flixopt.config ¶
Classes¶
MultilineFormatter ¶
ColoredMultilineFormatter ¶
CONFIG ¶
Configuration for flixopt library.
Attributes:
| Name | Type | Description |
|---|---|---|
Logging | Logging configuration (see CONFIG.Logging for details). | |
Modeling | Optimization modeling parameters. | |
Solving | Solver configuration and default parameters. | |
Plotting | Plotting configuration. | |
config_name | str | Configuration name. |
Examples:
# Quick logging setup
CONFIG.Logging.enable_console('INFO')
# Or use presets (affects logging, plotting, solver output)
CONFIG.exploring() # Interactive exploration
CONFIG.debug() # Troubleshooting
CONFIG.production() # Production deployment
CONFIG.silent() # No output
# Adjust other settings
CONFIG.Solving.mip_gap = 0.001
CONFIG.Plotting.default_dpi = 600
Classes¶
Logging ¶
Logging configuration helpers.
flixopt is silent by default (WARNING level, no handlers).
Quick Start - Use Presets
These presets configure logging along with plotting and solver output:
| Preset | Console Logs | File Logs | Plots | Solver Output | Use Case |
|---|---|---|---|---|---|
CONFIG.exploring() | INFO (colored) | No | Browser | Yes | Interactive exploration |
CONFIG.debug() | DEBUG (colored) | No | Default | Yes | Troubleshooting |
CONFIG.production('app.log') | No | INFO | No | No | Production deployments |
CONFIG.silent() | No | No | No | No | Silent operation |
Examples:
Direct Control - Logging Only
For fine-grained control of logging without affecting other settings:
Methods: - enable_console(level='INFO', colored=True, stream=None) - enable_file(level='INFO', path='flixopt.log', max_bytes=10MB, backup_count=5) - disable() - Remove all handlers - set_colors(log_colors) - Customize level colors
Examples:
# Console and file logging
CONFIG.Logging.enable_console('INFO')
CONFIG.Logging.enable_file('DEBUG', 'debug.log')
# Customize colors
CONFIG.Logging.set_colors(
{
'INFO': 'bold_white',
'SUCCESS': 'bold_green,bg_black',
'CRITICAL': 'bold_white,bg_red',
}
)
# Non-colored output
CONFIG.Logging.enable_console('INFO', colored=False)
Advanced Customization
For full control, use Python's standard logging or create custom formatters:
# Custom formatter
from flixopt.config import ColoredMultilineFormatter
import colorlog, logging
handler = colorlog.StreamHandler()
handler.setFormatter(ColoredMultilineFormatter(...))
logging.getLogger('flixopt').addHandler(handler)
# Or standard Python logging
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
Note
Default formatters (MultilineFormatter and ColoredMultilineFormatter) provide pretty output with box borders for multi-line messages.
Functions¶
classmethod ¶Enable colored console logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level | str | int | Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL or logging constant) | 'INFO' |
colored | bool | Use colored output if colorlog is available (default: True) | True |
stream | Output stream (default: sys.stdout). Can be sys.stdout or sys.stderr. | None |
Note
For full control over formatting, use logging.basicConfig() instead.
Examples:
# Colored output to stdout (default)
CONFIG.Logging.enable_console('INFO')
# Plain text output
CONFIG.Logging.enable_console('INFO', colored=False)
# Log to stderr instead
import sys
CONFIG.Logging.enable_console('INFO', stream=sys.stderr)
# Using logging constants
import logging
CONFIG.Logging.enable_console(logging.DEBUG)
classmethod ¶enable_file(level: str | int = 'INFO', path: str | Path = 'flixopt.log', max_bytes: int = 10 * 1024 * 1024, backup_count: int = 5) -> None
Enable file logging with rotation. Removes all existing file handlers!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level | str | int | Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL or logging constant) | 'INFO' |
path | str | Path | Path to log file (default: 'flixopt.log') | 'flixopt.log' |
max_bytes | int | Maximum file size before rotation in bytes (default: 10MB) | 10 * 1024 * 1024 |
backup_count | int | Number of backup files to keep (default: 5) | 5 |
Note
For full control over formatting and handlers, use logging module directly.
Examples:
classmethod ¶classmethod ¶Customize log level colors for console output.
This updates the colors for the current console handler. If no console handler exists, this does nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_colors | dict[str, str] | Dictionary mapping log levels to color names. Colors can be comma-separated for multiple attributes (e.g., 'bold_red,bg_white'). | required |
Available colors
- Basic: black, red, green, yellow, blue, purple, cyan, white
- Bold: bold_red, bold_green, bold_yellow, bold_blue, etc.
- Light: light_red, light_green, light_yellow, light_blue, etc.
- Backgrounds: bg_red, bg_green, bg_light_red, etc.
- Combined: 'bold_white,bg_red' for white text on red background
Examples:
# Enable console first
CONFIG.Logging.enable_console('INFO')
# Then customize colors
CONFIG.Logging.set_colors(
{
'DEBUG': 'cyan',
'INFO': 'bold_white',
'SUCCESS': 'bold_green',
'WARNING': 'bold_yellow,bg_black', # Yellow on black
'ERROR': 'bold_red',
'CRITICAL': 'bold_white,bg_red', # White on red
}
)
Note
Requires colorlog to be installed. Has no effect on file handlers.
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
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:
# Configure default export and color settings
CONFIG.Plotting.default_dpi = 600
CONFIG.Plotting.default_sequential_colorscale = 'plasma'
CONFIG.Plotting.default_qualitative_colorscale = 'Dark24'
Functions¶
reset classmethod ¶
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 ¶
debug classmethod ¶
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.
Examples:
production classmethod ¶
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.
Examples: