Running a Macro Model

run_case

MacroEnergy.run_caseFunction
run_case(case_path; kwargs...) -> (systems::Vector{System}, solution::Any)

Load, solve, and write results for a Macro case. This is the main entry point for running a complete Macro workflow.

Arguments

  • case_path::AbstractString: Path to the case directory containing system_data.json. Defaults to @__DIR__ (the directory of the calling script).

Keyword Arguments

Data Loading

  • lazy_load::Bool=true: Whether to delay loading the input data until needed.

Logging

  • log_level::LogLevel=Logging.Info: Logging verbosity level (e.g., Logging.Debug, Logging.Info, Logging.Warn, Logging.Error). Note: you need to import the Logging module to change this parameter.
  • log_to_console::Bool=true: Whether to print log messages to the console.
  • log_to_file::Bool=true: Whether to write log messages to a file.
  • log_file_path::AbstractString: Path to the log file. Defaults to <case_path>/<case_name>.log.
  • log_file_attribution::Bool=true: Whether to include source file attribution in log messages.

Optimizer (Monolithic/Myopic)

  • optimizer::DataType=HiGHS.Optimizer: Optimizer constructor for Monolithic or Myopic algorithms.
  • optimizer_env::Any=nothing: Optional optimizer environment.
  • optimizer_attributes::Tuple: Solver-specific settings. Default: ("BarConvTol" => 1e-3, "Crossover" => 0, "Method" => 2).

Optimizer (Benders)

  • planning_optimizer::DataType=HiGHS.Optimizer: Optimizer constructor for the planning problem.
  • subproblem_optimizer::DataType=HiGHS.Optimizer: Optimizer constructor for the subproblems.
  • planning_optimizer_attributes::Tuple: Solver settings for the planning problem.
  • subproblem_optimizer_attributes::Tuple: Solver settings for the subproblems.

Returns

  • systems::Vector{System}: Vector of solved system objects (one per period).
  • solution: The solution object (type depends on the solution algorithm: Model for Monolithic, MyopicResults for Myopic, BendersResults for Benders).

Examples

Basic usage with HiGHS (default)

using MacroEnergy

(systems, solution) = run_case(@__DIR__);

Using Gurobi optimizer

using MacroEnergy
using Gurobi

(systems, solution) = run_case(
    @__DIR__;
    optimizer=Gurobi.Optimizer,
    optimizer_attributes=("Method" => 2, "Crossover" => 0, "BarConvTol" => 1e-3)
);

Benders decomposition with custom settings

using MacroEnergy
using Gurobi

(systems, solution) = run_case(
    @__DIR__;
    planning_optimizer=Gurobi.Optimizer,
    subproblem_optimizer=Gurobi.Optimizer,
    planning_optimizer_attributes=("Method" => 2, "Crossover" => 0, "BarConvTol" => 1e-3),
    subproblem_optimizer_attributes=("Method" => 2, "Crossover" => 0, "BarConvTol" => 1e-3)
);

Suppressing console output when running a case

using MacroEnergy
using Logging

(systems, solution) = run_case(
    case_path;
    log_to_console=false,
    log_level=Logging.Warn
);

Notes

  • The solution algorithm (Monolithic, Myopic, or Benders) is determined by the SolutionAlgorithm setting in the case's settings/case_settings.json file.
  • For Myopic runs, results are written during iteration; no additional output writing occurs after solving.
  • For Benders with distributed processing enabled, worker processes are automatically created and cleaned up.
source