flixopt.config ¶
Classes¶
MultilineFormatter ¶
Bases: Formatter
Custom formatter that handles multi-line messages with box-style borders.
Uses Unicode box-drawing characters for prettier output, with a fallback to simple formatting if any encoding issues occur.
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
Log Levels: Standard levels plus custom SUCCESS level (between INFO and WARNING): - DEBUG (10): Detailed debugging information - INFO (20): General informational messages - SUCCESS (25): Success messages (custom level) - WARNING (30): Warning messages - ERROR (40): Error messages - CRITICAL (50): Critical error messages
Examples:
import logging
from flixopt.config import CONFIG, SUCCESS_LEVEL
# Console and file logging
CONFIG.Logging.enable_console('INFO')
CONFIG.Logging.enable_file('DEBUG', 'debug.log')
# Use SUCCESS level with logger.log()
logger = logging.getLogger('flixopt')
CONFIG.Logging.enable_console('SUCCESS') # Shows SUCCESS, WARNING, ERROR, CRITICAL
logger.log(SUCCESS_LEVEL, 'Operation completed successfully!')
# Or use numeric level directly
logger.log(25, 'Also works with numeric level')
# 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_console(level: str | int = 'INFO', colored: bool = True, stream: TextIO | None = None) -> None
Enable colored console logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level | str | int | Log level (DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL or numeric level) | 'INFO' |
colored | bool | Use colored output if colorlog is available (default: True) | True |
stream | TextIO | None | 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, encoding: str = 'utf-8') -> None
Enable file logging with rotation. Removes all existing file handlers!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level | str | int | Log level (DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL or numeric level) | '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 |
encoding | str | File encoding (default: 'utf-8'). Use 'utf-8' for maximum compatibility. | 'utf-8' |
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. |
compute_infeasibilities | bool | Whether to compute infeasibility analysis when the model is infeasible. |
capture_solver_log | bool | Whether to route solver output through the .. note:: If |
Examples:
# Capture solver output to file only (no double console logging)
CONFIG.Solving.capture_solver_log = True
CONFIG.Solving.log_to_console = False # avoid double console output
CONFIG.Logging.enable_file('INFO', 'flixopt.log')
# Capture through logger to console (disable native solver console)
CONFIG.Solving.capture_solver_log = True
CONFIG.Solving.log_to_console = False
CONFIG.Logging.enable_console('INFO')
# Native solver console only (no Python logger capture)
CONFIG.Solving.capture_solver_log = False
CONFIG.Solving.log_to_console = True
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'
Carriers ¶
Default carrier definitions for common energy types.
Provides convenient defaults for carriers. Colors are from D3/Plotly palettes.
Predefined: electricity, heat, gas, hydrogen, fuel, biomass
Examples:
import flixopt as fx
# Access predefined carriers
fx.CONFIG.Carriers.electricity # Carrier with color '#FECB52'
fx.CONFIG.Carriers.heat.color # '#D62728'
# Use with buses
bus = fx.Bus('Grid', carrier='electricity')
Classes¶
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 routes solver output through the flixopt.solver Python logger. 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:
use_theme classmethod ¶
Activate the flixopt plotly theme as the default template.
Sets plotly.io.templates.default = 'plotly_white+flixopt'.
The 'flixopt' template is registered automatically on import with colorscales from CONFIG.Plotting. Call this method to make it the default for all plots.
Returns:
| Type | Description |
|---|---|
type[CONFIG] | The CONFIG class for method chaining. |
Examples:
notebook classmethod ¶
Configure for Jupyter notebook environments.
Optimizes settings for notebook usage: - Sets plotly renderer to 'notebook' for inline display (unless PLOTLY_RENDERER env var is set) - Disables automatic plot.show() calls (notebooks display via repr_html) - Enables SUCCESS-level console logging - Disables solver console output for cleaner notebook cells
Note
The plotly renderer can be overridden by setting the PLOTLY_RENDERER environment variable (e.g., 'notebook_connected' for CDN-based rendering).
Examples:
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 |
Returns:
| Type | Description |
|---|---|
type[CONFIG] | The CONFIG class for method chaining. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If the config file does not exist. |
Examples:
Example YAML file: