ommx.adapter#
Attributes#
Exceptions#
Raised when an instance is not applicable to an adapter. |
|
Raised when no solution was returned. |
|
Raised when the problem is proven to be unbounded. |
Classes#
Adapter diagnostic report convertible with |
|
Receiver for adapter-defined diagnostics emitted during a solve. |
|
An abstract interface for OMMX Sampler Adapters, defining how samplers should be used with OMMX. |
|
An abstract interface for OMMX Solver Adapters, defining how solvers should be used with OMMX. |
Module Contents#
- exception AdapterNotApplicableError(adapter: str, report: InstanceClassMembershipReport)#
Raised when an instance is not applicable to an adapter.
- report: InstanceClassMembershipReport#
- exception NoSolutionReturned#
Raised when no solution was returned.
This indicates that the solver did not return any solution (whether feasible or not) (e.g., due to time limits). This does not prove that the mathematical model itself is infeasible.
- exception UnboundedDetected#
Raised when the problem is proven to be unbounded.
This corresponds to
Optimality.OPTIMALITY_UNBOUNDEDand indicates that the mathematical model itself is unbounded. Should not be used when unboundedness cannot be proven (e.g., heuristic solvers).
- class DiagnosticReport#
Adapter diagnostic report convertible with
dataclasses.asdict.
- class DiagnosticsSink#
Receiver for adapter-defined diagnostics emitted during a solve.
Adapters may call
recordwhile the backend solver is still running, including from backend callbacks. Sink implementations should keeprecordappend-only, defer validation or serialization until after the solve, and preserve the order in which diagnostics are received.A conforming sink must not raise from
record. If recording fails, the sink should log the failure and return normally. Ifrecorddoes raise, that is a sink contract violation; adapters may let the exception propagate and do not need to recover from it.- record(diagnostic: DiagnosticReport) None#
Record one adapter-defined dataclass diagnostic report or event.
This method must not raise under normal sink failures. Custom sinks should log failures and return instead.
- class SamplerAdapter#
An abstract interface for OMMX Sampler Adapters, defining how samplers should be used with OMMX.
See the implementation guide for more details.
- classmethod check_applicability(ommx_instance: Instance) InstanceClassMembershipReport#
Check
INPUT_CLASSmembership without mutation.
- classmethod recommended_preparation_policy() PreparationPolicy#
Return a fresh policy recommended for this Adapter's
INPUT_CLASS.The easy APIs apply it to an isolated copy. Advanced callers may edit and apply it explicitly before using a preparation-free API. This method itself neither prepares an instance nor guarantees applicability. The default policy is empty.
- classmethod require_applicable(ommx_instance: Instance) InstanceClassMembershipReport#
Return the membership report or raise
AdapterNotApplicableError.
- classmethod sample(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) SampleSet#
Prepare and sample an isolated copy of an OMMX instance.
The input
ommx_instanceis never modified. The copy is prepared forINPUT_CLASSwithrecommended_preparation_policy(), then passed tosample_without_preparation().Run.log_sampleowns the reserveddiagnosticskeyword and uses it the same way asRun.log_solve.Nonemeans diagnostics are disabled.
- classmethod sample_without_preparation(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) SampleSet#
- Abstractmethod:
Sample an exact Adapter input without running
Instance.prepare.ommx_instancemust belong toINPUT_CLASS. Implementations must reject non-members withAdapterNotApplicableErrorand must not prepare or otherwise modify the input instance.
- classmethod solve(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) Solution#
Prepare and solve an isolated copy of an OMMX instance.
The input
ommx_instanceis never modified. The copy is prepared forINPUT_CLASSwithrecommended_preparation_policy(), then passed tosolve_without_preparation().Run.log_solveowns the reserveddiagnosticskeyword. When called withstore_diagnostics=True, it passes a sink to the adapter and stores recorded diagnostics with the Solve entry. Adapters may record adapter-defined dataclass diagnostics into the sink during the solve;Nonemeans diagnostics are disabled. Adapters do not need to catch exceptions raised by a non-conforming diagnostics sink.
- classmethod solve_without_preparation(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) Solution#
Return the best feasible result from
sample_without_preparation().
- INPUT_CLASS: ClassVar[InstanceClass]#
Required condition for an exact Adapter input.
- property sampler_input: SamplerInput#
- Abstractmethod:
- property solver_input: SolverInput#
Expose
sampler_inputthrough the SolverAdapter interface.
- class SolverAdapter#
An abstract interface for OMMX Solver Adapters, defining how solvers should be used with OMMX.
See the implementation guide for more details.
Concrete subclasses define applicability with
INPUT_CLASS. The easysolve()API prepares an isolated copy with the Adapter's recommended policy. Usesolve_without_preparation()when the caller owns preparation and wants the Adapter to require an exact input without modifying it.- classmethod check_applicability(ommx_instance: Instance) InstanceClassMembershipReport#
Check
INPUT_CLASSmembership without mutation.
- classmethod recommended_preparation_policy() PreparationPolicy#
Return a fresh policy recommended for this Adapter's
INPUT_CLASS.The easy APIs apply it to an isolated copy. Advanced callers may edit and apply it explicitly before using a preparation-free API. This method itself neither prepares an instance nor guarantees applicability. The default policy is empty.
- classmethod require_applicable(ommx_instance: Instance) InstanceClassMembershipReport#
Return the membership report or raise
AdapterNotApplicableError.
- classmethod solve(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) Solution#
Prepare and solve an isolated copy of an OMMX instance.
The input
ommx_instanceis never modified. The copy is prepared forINPUT_CLASSwithrecommended_preparation_policy(), then passed tosolve_without_preparation().Run.log_solveowns the reserveddiagnosticskeyword. When called withstore_diagnostics=True, it passes a sink to the adapter and stores recorded diagnostics with the Solve entry. Adapters may record adapter-defined dataclass diagnostics into the sink during the solve;Nonemeans diagnostics are disabled. Adapters do not need to catch exceptions raised by a non-conforming diagnostics sink.
- classmethod solve_without_preparation(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) Solution#
- Abstractmethod:
Solve an exact Adapter input without running
Instance.prepare.ommx_instancemust belong toINPUT_CLASS. Implementations must reject non-members withAdapterNotApplicableErrorand must not prepare or otherwise modify the input instance.
- INPUT_CLASS: ClassVar[InstanceClass]#
Required condition for an exact Adapter input.
- property solver_input: SolverInput#
- Abstractmethod:
- SamplerInput#
- SamplerOutput#
- SolverInput#
- SolverOutput#