flixopt.config ¶
Classes¶
CONFIG ¶
Configuration for flixopt library.
Always call CONFIG.apply() after changes.
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', 'WARNING', 'ERROR', 'CRITICAL']  |    Logging level.  |  
file |   str | None  |    Log file path for file logging.  |  
console |   bool | Literal['stdout', 'stderr']  |    Enable console output.  |  
rich |   bool  |    Use Rich library for enhanced output.  |  
max_file_size |   int  |    Max file size before rotation.  |  
backup_count |   int  |    Number of backup files to keep.  |  
date_format |   str  |    Date/time format string.  |  
format |   str  |    Log message format string.  |  
console_width |   int  |    Console width for Rich handler.  |  
show_path |   bool  |    Show file paths in messages.  |  
show_logger_name |   bool  |    Show logger name in messages.  |  
Colors |   bool  |    ANSI color codes for log levels.  |  
Examples:
# File logging with rotation
CONFIG.Logging.file = 'app.log'
CONFIG.Logging.max_file_size = 5_242_880  # 5MB
CONFIG.apply()
# Rich handler with stdout
CONFIG.Logging.console = True  # or 'stdout'
CONFIG.Logging.rich = True
CONFIG.apply()
# Console output to stderr
CONFIG.Logging.console = 'stderr'
CONFIG.apply()
Classes¶
ANSI color codes for log levels.
Attributes:
| Name | Type | Description | 
|---|---|---|
DEBUG |   str  |    ANSI color for DEBUG level.  |  
INFO |   str  |    ANSI color for INFO level.  |  
WARNING |   str  |    ANSI color for WARNING level.  |  
ERROR |   str  |    ANSI color for ERROR level.  |  
CRITICAL |   str  |    ANSI color for CRITICAL level.  |  
Examples:
CONFIG.Logging.Colors.INFO = '\033[32m'  # Green
CONFIG.Logging.Colors.ERROR = '\033[1m\033[31m'  # Bold red
CONFIG.apply()
Common ANSI codes
- '\033[30m' - Black
 - '\033[31m' - Red
 - '\033[32m' - Green
 - '\033[33m' - Yellow
 - '\033[34m' - Blue
 - '\033[35m' - Magenta
 - '\033[36m' - Cyan
 - '\033[37m' - White
 - '\033[90m' - Bright Black/Gray
 - '\033[0m' - Reset to default
 - '\033[1m\033[3Xm' - Bold (replace X with color code 0-7)
 - '\033[2m\033[3Xm' - Dim (replace X with color code 0-7)
 
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 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.
MultilineFormatter ¶
ColoredMultilineFormatter ¶
ColoredMultilineFormatter(fmt: str | None = None, datefmt: str | None = None, colors: dict[str, str] | None = None, show_logger_name: bool = False)
 Bases: MultilineFormatter
Formatter that adds ANSI colors to multi-line log messages.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
 fmt  |   str | None  |    Log message format string.  |   None  |  
 datefmt  |   str | None  |    Date/time format string.  |   None  |  
 colors  |   dict[str, str] | None  |    Dictionary of ANSI color codes for each log level.  |   None  |  
 show_logger_name  |   bool  |    Show logger name in log messages.  |   False  |  
Functions¶
change_logging_level ¶
Change the logging level for the flixopt logger and all its handlers.
.. 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', 'WARNING', 'ERROR', 'CRITICAL']  |    The logging level to set.  |  required | 
Examples: