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.

Parameters:
logger

Underlying Python logger instance

Type:

logging.Logger

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:
  • name (str) – Logger name for identification. Defaults to “lumix”. Use different names to distinguish between multiple models.

  • level (int) – Logging level from Python’s logging module. Defaults to logging.INFO. Common values: logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR.

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:
  • name (str) – Logger name for identification. Defaults to “lumix”. Use different names to distinguish between multiple models.

  • level (int) – Logging level from Python’s logging module. Defaults to logging.INFO. Common values: logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR.

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:
  • name (str) – Name of the model being created

  • num_vars (int) – Total number of decision variables in the model

  • num_constraints (int) – Total number of constraints in the model

Return type:

None

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:
  • var_name (str) – Name or identifier of the variable family

  • var_type (str) – Type of variable (“continuous”, “integer”, “binary”)

  • count (int) – Number of variables created in this family. Defaults to 1.

Return type:

None

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:
  • constraint_name (str) – Name or identifier of the constraint family

  • sense (str) – Constraint sense (“<=”, “>=”, “==”)

  • count (int) – Number of constraints created in this family. Defaults to 1.

Return type:

None

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:

None

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:
  • status (str) – Solve status (“Optimal”, “Infeasible”, “Unbounded”, “TimeLimit”, etc.)

  • objective_value (Optional[float]) – Optimal objective value if available. Defaults to None.

  • solve_time (Optional[float]) – Explicit solve time in seconds. Used if start time was not recorded. Defaults to None.

Return type:

None

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:
  • num_nonzero (int) – Number of variables with non-zero values in the solution

  • total_vars (int) – Total number of variables in the model

Return type:

None

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:
  • term_type (str) – Type of non-linear term (“bilinear”, “absolute”, “min/max”, etc.)

  • method (str) – Linearization method used (“McCormick”, “big-M”, “piecewise”, etc.)

  • aux_vars (int) – Number of auxiliary variables added during linearization

Return type:

None

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:
  • scenario_name (str) – Name or identifier of the scenario being analyzed

  • modifications (int) – Number of parameter modifications in this scenario

Return type:

None

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:
  • var_name (str) – Name of the variable being analyzed

  • reduced_cost (float) – Reduced cost (shadow price) of the variable

Return type:

None

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.

Parameters:

message (str) – Message to log at INFO level

Return type:

None

Examples

Log custom info message:

logger.info("Model preprocessing completed")
debug(message)[source]

Log a debug message.

Parameters:

message (str) – Message to log at DEBUG level

Return type:

None

Examples

Log debug details:

logger.debug("Checking constraint matrix sparsity")
warning(message)[source]

Log a warning message.

Parameters:

message (str) – Message to log at WARNING level

Return type:

None

Examples

Log warning:

logger.warning("Model contains unbounded variables")
error(message)[source]

Log an error message.

Parameters:

message (str) – Message to log at ERROR level

Return type:

None

Examples

Log error:

logger.error("Solver failed to find feasible solution")