Skip to content

flixopt.config

Classes

MultilineFormatter

MultilineFormatter(*args, **kwargs)

Bases: Formatter

Custom formatter that handles multi-line messages with box-style borders.

Functions

format
format(record)

Format multi-line messages with box-style borders for better readability.

ColoredMultilineFormatter

Bases: ColoredFormatter

Colored formatter with multi-line message support.

Functions

format
format(record)

Format multi-line messages with colors and box-style borders.

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:

CONFIG.exploring()  # Start exploring interactively
CONFIG.debug()  # See everything for troubleshooting
CONFIG.production('logs/prod.log')  # Production mode

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
enable_console classmethod
enable_console(level: str | int = 'INFO', colored: bool = True, stream=None) -> None

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)
enable_file 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:

# Basic file logging
CONFIG.Logging.enable_file('INFO', 'app.log')

# With custom rotation
CONFIG.Logging.enable_file('DEBUG', 'debug.log', max_bytes=50 * 1024 * 1024, backup_count=10)
disable classmethod
disable() -> None

Disable all flixopt logging.

Examples:

CONFIG.Logging.disable()
set_colors classmethod
set_colors(log_colors: dict[str, str]) -> None

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

Optimization modeling parameters.

Attributes:

Name Type Description
big int

Large number for big-M constraints.

epsilon float

Tolerance for numerical comparisons.

big_binary_bound int

Upper bound for binary constraints.

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 show parameter in plot methods.

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
reset() -> None

Reset all configuration values to defaults.

This resets modeling, solving, and plotting settings to their default values, and disables all logging handlers (back to silent mode).

Examples:

CONFIG.debug()  # Enable debug mode
# ... do some work ...
CONFIG.reset()  # Back to defaults (silent)
to_dict classmethod
to_dict() -> dict

Convert the configuration class into a dictionary for JSON serialization.

Returns:

Type Description
dict

Dictionary representation of the current configuration.

silent classmethod
silent() -> type[CONFIG]

Configure for silent operation.

Disables all logging, solver output, and result logging for clean production runs. Does not show plots.

Examples:

CONFIG.silent()
# Now run optimizations with no output
result = optimization.solve()
debug classmethod
debug() -> type[CONFIG]

Configure for debug mode with verbose output.

Enables console logging at DEBUG level and all solver output for troubleshooting.

Examples:

CONFIG.debug()
# See detailed DEBUG logs and full solver output
optimization.solve()
exploring classmethod
exploring() -> type[CONFIG]

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:

CONFIG.exploring()
# Perfect for interactive sessions
optimization.solve()  # Shows INFO logs and solver output
result.plot()  # Opens plots in browser
production classmethod
production(log_file: str | Path = 'flixopt.log') -> type[CONFIG]

Configure for production use.

Enables file logging only (no console output), disables plots, and disables solver console output for clean production runs.

Parameters:

Name Type Description Default
log_file str | Path

Path to log file (default: 'flixopt.log')

'flixopt.log'

Examples:

CONFIG.production('production.log')
# Logs to file, no console output
optimization.solve()
browser_plotting classmethod
browser_plotting() -> type[CONFIG]

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:

CONFIG.browser_plotting()
result.plot()  # Opens in browser instead of inline

Functions

change_logging_level

change_logging_level(level_name: str | int) -> None

Change the logging level for the flixopt logger.

Parameters:

Name Type Description Default
level_name str | int

The logging level to set (DEBUG, INFO, WARNING, ERROR, CRITICAL or logging constant).

required

Examples:

>>> change_logging_level('DEBUG')  # deprecated
>>> # Use this instead:
>>> CONFIG.Logging.enable_console('DEBUG')