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. |
|
config_name |
str
|
Configuration name. |
Examples:
Load from YAML file:
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
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. |
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. |
MultilineFormatter
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
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: