Runs the generated model.py (or solve.py, written by
write_pyomo(split = TRUE)) in solvers/pyomo/ with the configured Python
interpreter, and returns basic status information together with the status
the script writes to solution/status.json. With load_results = TRUE the
variable values the script exports are read back into model.
Usage
solve_pyomo(
model = NULL,
model_dir,
solver_dir = "pyomo",
env_name = "multimod",
ensure_env = FALSE,
packages = NULL,
python_version = NULL,
ensure_miniconda = TRUE,
reinstall_env = FALSE,
python = NULL,
solver = NULL,
env = NULL,
load_results = FALSE,
verbose = c("buffer", "stream", "quiet"),
timeout = NULL,
...
)Arguments
- model
Optional multimod model. Required when
load_results = TRUE: the solution of each variable is stored inmodel$variables[[name]]$solution.- model_dir
Path to the saved model directory created by
save_model(). Must containsolvers/<solver_dir>/model.py(generated viawrite_pyomo()).- solver_dir
Name of the solver sub-directory inside
model_dir/solvers. Defaults to "pyomo" to matchwrite_pyomo().- env_name
Name of the Conda environment handled by
mm_setup_python(). Defaults to "multimod".- ensure_env
Logical; when
TRUEthe environment is checked withmm_check_python()andmm_setup_python()runs if it is not usable. DefaultFALSE: the configured interpreter is used as it is, and nothing is installed.- packages
Character vector of Python packages to request when the helper runs.
NULL(default) usesmm_setup_python()'s own list, so the environment contents have a single owner.- python_version
Optional Python version passed through to
mm_setup_python().- ensure_miniconda
Forwarded to
mm_setup_python().- reinstall_env
When
TRUE, asks the helper to recreate the Conda environment before solving.- python
Optional path to a Python executable. When omitted the Python binary reported by
reticulate::py_config()for the activated environment is used.- solver
Optional solver name that is exported to the Python process via the
PYOMO_SOLVERenvironment variable.- env
Named character vector of additional environment variables to pass to the Python process.
- load_results
Logical; when
TRUE, readsolution/variables.jsonintomodeland return the model asresult$model. The file is written by the generated script only when the scaffold was produced withwrite_pyomo(export_vars = TRUE).- verbose
Controls solver logging capture. Logical (
TRUE= buffer output,FALSE= quiet) or one of"buffer","stream","quiet".- timeout
Optional timeout (in seconds). Requires the
processxpackage.- ...
Additional arguments forwarded to
mm_setup_python().
Value
A list describing the solver run (exit code, success flag, elapsed
time, raw output, parsed status metadata when available, and environment
details). With load_results = TRUE, also model, the input model with a
solution data frame on every variable the solver reported. objective
is the objective value the script records in status.json.
Details
The Python environment is created once with mm_setup_python(). With
ensure_env = TRUE, solve_pyomo() checks the environment and creates it
when it is not usable, which may install Miniconda and Python packages.
