el1xr_opt.Modules.oM_SolverSetup

el1xr_opt.Modules.oM_SolverSetup#

el1xr_opt.Modules.oM_SolverSetup.ensure_ampl_solvers(targets=('highs',), quiet=False)[source]#

Check for and automatically install a list of AMPL solver modules if missing.

Parameters:
  • targets (Iterable[str]) – An iterable of solver names to check/install (e.g., [“highs”, “cbc”]).

  • quiet (bool) – If True, suppress warnings about failed installations.

Return type:

Dict[str, bool]

Returns:

A dictionary mapping each solver name to a boolean indicating its availability after the check/installation process.

el1xr_opt.Modules.oM_SolverSetup.pick_solver(preferred, *, allow_fallback=False)[source]#

Select and configure a solver, prioritizing AMPL modules for performance.

This function provides a standardized way to select a solver. It checks for the availability of a high-performance AMPL module first. If the preferred solver’s module is found, it configures Pyomo to use it via the ‘nl’ interface.

The selection is strict by default: if the AMPL module is not available, the function will raise a RuntimeError unless allow_fallback is True.

Parameters:
  • preferred (Optional[str]) – The desired solver’s name (e.g., “highs”). Defaults to “highs” if None.

  • allow_fallback (bool) – If True, the function can be extended to support other solver configurations (e.g., Pyomo’s built-in appsi solvers) when the AMPL module is unavailable. Currently, this will still result in an error if the module is not found.

Returns:

A dictionary containing the solver configuration for Pyomo’s SolverFactory, including the factory name, I/O method, and executable path.

Raises:
  • ValueError – If the preferred solver is not in the supported list.

  • RuntimeError – If the corresponding AMPL module is not found and allow_fallback is False.