lumix.utils.logger.LXModelLogger¶
- class lumix.utils.logger.LXModelLogger(name='lumix', level=20)[source]¶
Enhanced logging for optimization models.
Provides specialized logging methods for tracking optimization model construction, solving progress, and solution analysis. Automatically handles timing and formatting for optimization-specific events.
- logger¶
Underlying Python logger instance
- Type:
- start_time¶
Timestamp when solve started (for timing)
- Type:
Optional[datetime]
Examples
Create and use a model logger:
from lumix.utils import LXModelLogger import logging logger = LXModelLogger(name="my_model", level=logging.INFO) logger.log_model_creation("ProductionModel", 100, 50) logger.log_solve_start("Gurobi") # ... solving happens ... logger.log_solve_end("Optimal", objective_value=42500.0)
Note
The logger automatically creates a console handler if none exists. Multiple instances with the same name will share the same underlying Python logger.
- __init__(name='lumix', level=20)[source]¶
Initialize model logger with specified name and logging level.
- Parameters:
Examples
Create logger with default settings:
logger = LXModelLogger()
Create logger with custom name and debug level:
logger = LXModelLogger(name="my_model", level=logging.DEBUG)
Methods
__init__([name, level])Initialize model logger with specified name and logging level.
debug(message)Log a debug message.
error(message)Log an error message.
info(message)Log an informational message.
log_constraint_creation(constraint_name, sense)Log the creation of constraints.
log_linearization(term_type, method, aux_vars)Log automatic linearization applied to non-linear terms.
log_model_creation(name, num_vars, ...)Log the creation of an optimization model.
log_scenario(scenario_name, modifications)Log scenario analysis execution.
log_sensitivity(var_name, reduced_cost)Log sensitivity analysis results for a variable.
log_solution_summary(num_nonzero, total_vars)Log a summary of the solution.
log_solve_end(status[, objective_value, ...])Log the completion of model solving with results.
log_solve_start(solver_name)Log the start of model solving and begin timing.
log_variable_creation(var_name, var_type[, ...])Log the creation of decision variables.
warning(message)Log a warning message.
- __init__(name='lumix', level=20)[source]¶
Initialize model logger with specified name and logging level.
- Parameters:
Examples
Create logger with default settings:
logger = LXModelLogger()
Create logger with custom name and debug level:
logger = LXModelLogger(name="my_model", level=logging.DEBUG)
- log_model_creation(name, num_vars, num_constraints)[source]¶
Log the creation of an optimization model.
- Parameters:
- Return type:
Examples
Log model creation after building:
logger.log_model_creation("ProductionPlan", num_vars=150, num_constraints=75) # Output: Created model 'ProductionPlan' with 150 variables and 75 constraints
- log_variable_creation(var_name, var_type, count=1)[source]¶
Log the creation of decision variables.
- Parameters:
- Return type:
Examples
Log single variable creation:
logger.log_variable_creation("profit", "continuous")
Log variable family creation:
logger.log_variable_creation("production", "continuous", count=50) # Output: Created 50 continuous variable(s): production
- log_constraint_creation(constraint_name, sense, count=1)[source]¶
Log the creation of constraints.
- Parameters:
- Return type:
Examples
Log single constraint:
logger.log_constraint_creation("budget", "<=")
Log constraint family:
logger.log_constraint_creation("capacity", "<=", count=20) # Output: Created 20 constraint(s): capacity (<=)
- log_solve_start(solver_name)[source]¶
Log the start of model solving and begin timing.
Records the current timestamp for automatic solve time calculation.
- Parameters:
solver_name (
str) – Name of the solver being used (“Gurobi”, “CPLEX”, “OR-Tools”, etc.)- Return type:
Examples
Start solve logging:
logger.log_solve_start("Gurobi") # Output: Starting solve with Gurobi...
- log_solve_end(status, objective_value=None, solve_time=None)[source]¶
Log the completion of model solving with results.
Automatically calculates elapsed time if log_solve_start was called. Otherwise, uses the provided solve_time parameter.
- Parameters:
- Return type:
Examples
Log successful solve with objective:
logger.log_solve_end("Optimal", objective_value=42500.75) # Output: Solve completed: Optimal | Objective: 42500.7500 | Time: 2.35s
Log solve without objective:
logger.log_solve_end("Infeasible") # Output: Solve completed: Infeasible | Time: 0.15s
- log_solution_summary(num_nonzero, total_vars)[source]¶
Log a summary of the solution.
- Parameters:
- Return type:
Examples
Log solution sparsity:
logger.log_solution_summary(num_nonzero=25, total_vars=100) # Output: Solution has 25/100 non-zero variables
- log_linearization(term_type, method, aux_vars)[source]¶
Log automatic linearization applied to non-linear terms.
- Parameters:
- Return type:
Examples
Log bilinear linearization:
logger.log_linearization("bilinear", "McCormick", aux_vars=4) # Output: Linearized bilinear using McCormick (added 4 auxiliary variables)
- log_scenario(scenario_name, modifications)[source]¶
Log scenario analysis execution.
- Parameters:
- Return type:
Examples
Log scenario run:
logger.log_scenario("high_demand", modifications=5) # Output: Running scenario 'high_demand' with 5 modifications
- log_sensitivity(var_name, reduced_cost)[source]¶
Log sensitivity analysis results for a variable.
- Parameters:
- Return type:
Examples
Log variable sensitivity:
logger.log_sensitivity("production[Widget_A]", reduced_cost=-2.5) # Output: Sensitivity: production[Widget_A] reduced cost = -2.500000
- info(message)[source]¶
Log an informational message.
Examples
Log custom info message:
logger.info("Model preprocessing completed")
- debug(message)[source]¶
Log a debug message.
Examples
Log debug details:
logger.debug("Checking constraint matrix sparsity")