gtopt::SolverRegistry class

Singleton registry for dynamically loaded solver plugins.

Usage:

auto& reg = SolverRegistry::instance();
auto backend = reg.create("highs");  // loads plugin on demand

Public static variables

static std::chrono::milliseconds default_validation_timeout

Public static functions

static auto arm_child_parent_death_signal(pid_t parent_pid) -> bool noexcept
Child-side hardening right after fork() in the validation probe: arm PR_SET_PDEATHSIG(SIGKILL) so the child dies with its parent, then compare getppid() with parent_pid (captured BEFORE the fork) to close the race where the parent died before the prctl.
static auto effective_plugin_check() -> std::pair<PluginCheckMode, PluginCheckSource>
Effective mode and where it came from (CLI, environment or compiled-in default).
static auto instance() -> SolverRegistry&
Get the global singleton registry.
static auto plugin_check_policy() -> PluginIntegrityPolicy
Effective policy: CLI override, else GTOPT_PLUGIN_CHECK, else the compiled-in default.
static void reset_default_logger_after_fork() noexcept
Re-establish a safe synchronous default logger after fork().
static void set_plugin_check_mode(std::optional<PluginCheckMode> mode) noexcept
Override the plugin check mode for this process (CLI --plugin-check). std::nullopt clears the override, falling back to GTOPT_PLUGIN_CHECK, then to the compiled-in default k_default_plugin_check_mode (CMake GTOPT_PLUGIN_CHECK_DEFAULT). Applies to plugins loaded after the call.
static auto wait_child_with_timeout(pid_t pid, std::chrono::milliseconds timeout) -> std::optional<int> noexcept
Wait for child pid for at most timeout (polls waitpid(WNOHANG)). On timeout the child is sent SIGKILL and reaped.

Constructors, destructors, conversion operators

SolverRegistry(const SolverRegistry&) deleted
SolverRegistry(SolverRegistry&&) deleted
~SolverRegistry()

Public functions

auto available_solvers() const -> std::vector<std::string>
List all available solver names across loaded plugins.
auto create(std::string_view solver_name) -> std::unique_ptr<SolverBackend>
Create a solver backend by name.
auto default_solver() -> std::string_view
Return the best available solver name by priority.
void discover_plugins(const std::filesystem::path& dir)
Discover plugin files in a directory (no dlopen).
auto has_mip_solver() -> bool
True if at least one loaded backend can solve MIP problems.
auto has_solver(std::string_view name) const -> bool
Check whether a solver name is available.
auto is_gpu_backed(std::string_view solver_name = {}) -> bool
True when the solver's declared resource class is gpu.
void load_all_plugins()
Force all discovered plugins to be loaded.
auto load_errors() const -> const std::vector<std::string>&
Return diagnostic messages for plugins that failed to load.
auto load_plugin(const std::filesystem::path& path) -> bool
Load a single plugin shared library.
auto operator=(const SolverRegistry&) -> SolverRegistry& deleted
auto operator=(SolverRegistry&&) -> SolverRegistry& deleted
auto plugin_infinity(std::string_view solver_name = {}) -> std::optional<double>
Return the solver's +infinity value WITHOUT instantiating a SolverBackend.
auto plugin_reports() const -> std::vector<PluginReport>
Integrity / identity report of every loaded plugin.
auto resource_descriptor(std::string_view solver_name = {}) -> std::optional<SolverResourceDescriptor>
Return the solver's resource descriptor WITHOUT instantiating a SolverBackend.
auto searched_directories() const -> const std::vector<std::string>&
Return the directories that were searched for plugins.
auto supports_mip(std::string_view name) -> bool
Check whether the named solver can solve MIP problems.

Function documentation

static bool gtopt::SolverRegistry::arm_child_parent_death_signal(pid_t parent_pid) noexcept

Child-side hardening right after fork() in the validation probe: arm PR_SET_PDEATHSIG(SIGKILL) so the child dies with its parent, then compare getppid() with parent_pid (captured BEFORE the fork) to close the race where the parent died before the prctl.

Returns true when the child may proceed, false when it has already been reparented (caller should _exit).

static SolverRegistry& gtopt::SolverRegistry::instance()

Get the global singleton registry.

On first call, discovers plugin files from standard paths (but does not dlopen them yet — loading is deferred until needed).

static void gtopt::SolverRegistry::reset_default_logger_after_fork() noexcept

Re-establish a safe synchronous default logger after fork().

fork() copies the address space but not threads, so an inherited async default logger has a queue with no worker thread: logging into it deadlocks (block policy) or is silently dropped. This installs a fresh synchronous stderr logger as the default and detaches the inherited registry handles — in that order. spdlog::drop_all() resets the default logger to null (see spdlog registry::drop_all), so the fresh logger MUST be installed after it; the reverse order leaves a null default and the next spdlog::*() call dereferences it (SIGSEGV). noexcept and idempotent — safe to call across the fork barrier. Public so the post-fork logging contract can be unit-tested.

The fresh sink writes straight to fd 2 with a null_mutex: it does NOT use spdlog's process-wide static console mutex (shared by every stdout/stderr[_color]_sink_mt) nor the stderr FILE* lock. Either lock may have been held by another parent thread at fork() time and would then stay locked forever in the single-threaded child.

static std::optional<int> gtopt::SolverRegistry::wait_child_with_timeout(pid_t pid, std::chrono::milliseconds timeout) noexcept

Wait for child pid for at most timeout (polls waitpid(WNOHANG)). On timeout the child is sent SIGKILL and reaped.

Returns the waitpid status when the child finished in time, std::nullopt on timeout (child killed and reaped). If waitpid fails (e.g. ECHILD) the status is reported as 0.

std::unique_ptr<SolverBackend> gtopt::SolverRegistry::create(std::string_view solver_name)

Create a solver backend by name.

Parameters
solver_name Solver identifier: "clp", "cbc", "cplex", "highs"
Returns Owning pointer to the created backend
Exceptions
std::runtime_error if the solver is not available

Loads the matching plugin if it has not been loaded yet.

std::string_view gtopt::SolverRegistry::default_solver()

Return the best available solver name by priority.

Exceptions
std::runtime_error if no solver plugins are loaded, or $GTOPT_SOLVER's plugin was refused.

Loads plugins on demand until a suitable solver is found. $GTOPT_SOLVER names the solver to use; when it is unavailable the registry falls back to the priority order, except when its plugin was refused by an integrity check (see env_solver_must_fail()). Priority order: cplex, highs, mindopt, cbc, clp.

void gtopt::SolverRegistry::discover_plugins(const std::filesystem::path& dir)

Discover plugin files in a directory (no dlopen).

Scans dir for files matching libgtopt_solver_*.so and records them for later loading. Already-recorded paths are skipped.

bool gtopt::SolverRegistry::has_mip_solver()

True if at least one loaded backend can solve MIP problems.

Calls load_all_plugins() to ensure every available solver has been inspected. Use this to gate test cases that require a MIP-capable solver — when it returns false, the test should skip.

bool gtopt::SolverRegistry::has_solver(std::string_view name) const

Check whether a solver name is available.

Only checks already-loaded plugins. If you need an exhaustive check, call load_all_plugins() first.

bool gtopt::SolverRegistry::is_gpu_backed(std::string_view solver_name = {})

True when the solver's declared resource class is gpu.

Convenience over resource_descriptor(); false when the plugin exports no descriptor (CPU solvers) or the solver is unavailable.

void gtopt::SolverRegistry::load_all_plugins()

Force all discovered plugins to be loaded.

Call this before available_solvers() or has_solver() when you need to enumerate every solver (e.g. for –solvers).

bool gtopt::SolverRegistry::load_plugin(const std::filesystem::path& path)

Load a single plugin shared library.

Parameters
path Full path to the .so file
Returns true if the plugin was loaded successfully

std::optional<double> gtopt::SolverRegistry::plugin_infinity(std::string_view solver_name = {})

Return the solver's +infinity value WITHOUT instantiating a SolverBackend.

Parameters
solver_name Solver to query (e.g. "cplex", "highs"). Empty string defaults to default_solver().
Returns Solver's +infinity value, or std::nullopt if the plugin doesn't export the entry point or no plugin provides this solver.

Loads the plugin if not already loaded, then queries its gtopt_solver_infinity entry point (introduced in this revision). Plugins built before that entry existed return std::nullopt — the caller must fall back to creating a backend instance and reading infinity() directly. CPLEX returns 1e+20; HiGHS / OSI / MindOpt / Gurobi return 1e+30.

Used by PlanningLP::auto_scale_* to skip "no bound" sentinel values (e.g. Reservoir.fmax = 1e30) without paying the cost of an extra backend allocation per planning construction.

std::vector<PluginReport> gtopt::SolverRegistry::plugin_reports() const

Integrity / identity report of every loaded plugin.

One entry per loaded plugin: its path, ELF build-id and manifest check, build tag vs the host's, and per solver the compiled vs runtime solver-library version, the loaded library path and its build-id. Only solvers still available (after validation) are listed. Does not load anything — call load_all_plugins() first for a full listing.

std::optional<SolverResourceDescriptor> gtopt::SolverRegistry::resource_descriptor(std::string_view solver_name = {})

Return the solver's resource descriptor WITHOUT instantiating a SolverBackend.

Parameters
solver_name Solver to query. Empty defaults to default_solver().

Loads the plugin if needed, then queries its optional gtopt_solver_resource_descriptor entry point. Plugins that do not export the symbol (all CPU solvers today) return std::nullopt and the caller must treat the solver as CPU-class — today's behaviour, zero regression. The work-pool admission layer uses this to classify solve tasks (CPU fan-out vs per-GPU-device token bucket) before dispatch.

bool gtopt::SolverRegistry::supports_mip(std::string_view name)

Check whether the named solver can solve MIP problems.

Loads the plugin on demand if necessary, then queries the backend's supports_mip() method. Returns false if the solver is not available or does not support integer variables (e.g. CLP).

Variable documentation

static std::chrono::milliseconds gtopt::SolverRegistry::default_validation_timeout

Upper bound on how long the parent waits for one solver-validation child (validate_solver_subprocess). GPU backends (cuOpt) may take several seconds to initialise, hence the generous default. This is an administrative startup probe ONLY — it never bounds a real solve.