Skip to content

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:

Python
CONFIG.Logging.console = True
CONFIG.Logging.level = 'DEBUG'
CONFIG.apply()

Load from YAML file:

YAML
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:

Python
# 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
Colors

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:

Python
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

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:

Python
# 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 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:

Python
# 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

reset classmethod
Python
reset()

Reset all configuration values to defaults.

apply classmethod
Python
apply()

Apply current configuration to logging system.

load_from_file classmethod
Python
load_from_file(config_file: str | Path)

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
Python
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
Python
silent() -> type[CONFIG]

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
Python
debug() -> type[CONFIG]

Configure for debug mode with verbose output.

Enables console logging at DEBUG level and all solver output for troubleshooting. Automatically calls apply().

exploring classmethod
Python
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

browser_plotting classmethod
Python
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.

MultilineFormatter

Python
MultilineFormatter(fmt: str = '%(message)s', datefmt: str | None = None, show_logger_name: bool = False)

Bases: Formatter

Formatter that handles multi-line messages with consistent prefixes.

Parameters:

Name Type Description Default
fmt str

Log message format string.

'%(message)s'
datefmt str | None

Date/time format string.

None
show_logger_name bool

Show logger name in log messages.

False

ColoredMultilineFormatter

Python
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

Python
change_logging_level(level_name: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'])

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:

Python Console Session
>>> change_logging_level('DEBUG')  # deprecated
>>> # Use this instead:
>>> CONFIG.Logging.level = 'DEBUG'
>>> CONFIG.apply()