OpenSolve#
- class OpenSolve#
Context manager for a manually executed Solve inside a Run.
OpenSolveis returned byRun.open_solve(...). Usesolver_inputto access the backend solver model, run backend-specific APIs, decode the solver output, and record adapter options that are set directly on the backend model. The Solve entry is finalized when the context exits.Most recording uses
Run.log_solve(). Use this scope when a backend API must be called directly. Options set through the backend do not automatically become stored metadata; record them withlog_adapter_option().This complete example requires the HiGHS Adapter:
>>> from ommx import Instance >>> from ommx.experiment import Experiment >>> from ommx_highs_adapter import OMMXHighsAdapter >>> problem = Instance.minimize() >>> x = problem.new_binary("x") >>> problem.objective = x >>> with Experiment.with_temp_local_registry() as experiment: ... with experiment.run() as run: ... with run.open_solve(OMMXHighsAdapter, problem, verbose=False) as solve: ... model = solve.solver_input ... _ = model.setOptionValue("time_limit", 10.0) ... solve.log_adapter_option("time_limit", 10.0) ... _ = model.run() ... solution = solve.decode(model) ... assert solution.feasible >>> recorded = experiment.runs[0].solves[0] >>> recorded.output.objective 0.0 >>> recorded.adapter_options["time_limit"] 10.0
decode()stores the decoded Solution as the Solve’s output. The context manager finalizes the record on exit; the individual methods document terminal states, diagnostics, tracing, and exceptional exits. A finished recording scope is distinct from a guarantee of candidate feasibility or optimality.- __exit__(exc_type: Optional[Any] = None, exc_value: Optional[Any] = None, traceback: Optional[Any] = None) bool#
- __repr__() str#
- decode(data: Any) Solution#
Decode backend solver output through the adapter.
The decoded Solution is kept as this scope’s finished output candidate. The Solve entry is recorded when the
OpenSolvecontext exits, so diagnostics and annotations can still be recorded after this call and before the end of thewithblock.
- log_adapter_option(name: str, value: Any) None#
Record an adapter option set through direct backend model access.
- property diagnostics: Optional[DiagnosticCollector]#
Read-only property.
Diagnostics collector stored with this Solve, or
Nonewhen disabled.
- property solve_id: int#
Read-only property.
Reserved Solve ID for this manual Solve.
- property terminal_state: Optional[dict[str, Any]]#
Read-only property.
Terminal state recorded when this manual Solve scope closes.
Returns
Noneuntil the context has closed. After closing, this exposes the recorded Solve outcome together with trace and diagnostics finalization states for advanced debugging.