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#
Combined input-class and adapter-specific applicability result. |
|
One adapter-owned condition that an OMMX input class cannot express. |
|
Constraint identity qualified by its independently scoped family. |
|
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(report: AdapterApplicabilityReport)#
Raised when an instance is not applicable to an adapter.
- report: AdapterApplicabilityReport#
- 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 AdapterApplicabilityReport#
Combined input-class and adapter-specific applicability result.
- input_membership: InstanceClassMembershipReport#
- precondition_violations: tuple[AdapterPreconditionViolation, Ellipsis]#
- class AdapterPreconditionViolation#
One adapter-owned condition that an OMMX input class cannot express.
- actual: PreconditionValue = None#
- constraint_refs: frozenset[ConstraintRef]#
- limit: PreconditionValue = None#
- class ConstraintRef#
Constraint identity qualified by its independently scoped family.
- 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) AdapterApplicabilityReport#
Inspect applicability without mutating or preparing
ommx_instance.Adapter-specific preconditions run only after at least one complete input-class clause contains the instance. The hook receives an isolated copy so it cannot mutate the caller’s instance. Any explicitly transformed value is a different input and must be checked separately.
- classmethod require_applicable(ommx_instance: Instance) AdapterApplicabilityReport#
Return the report or raise
AdapterNotApplicableError.
- classmethod sample(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) SampleSet#
- Abstractmethod:
Sample an OMMX instance.
Run.log_sampleowns the reserveddiagnosticskeyword and uses it the same way asRun.log_solve.Nonemeans diagnostics are disabled.
- classmethod solve(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) Solution#
- Abstractmethod:
Solve an OMMX instance.
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.
- INPUT_CLASS: ClassVar[InstanceClass | None] = None#
- property sampler_input: SamplerInput#
- Abstractmethod:
- property solver_input: SolverInput#
- Abstractmethod:
- class SolverAdapter#
An abstract interface for OMMX Solver Adapters, defining how solvers should be used with OMMX.
See the implementation guide for more details.
Subclasses declare
INPUT_CLASSas the OMMX-defined structural class used by the first applicability condition.check_applicabilitydoes not mutate the input and combines class membership with the adapter’s_check_preconditionshook.INPUT_CLASSdescribes only which exact inputs an adapter accepts; it does not prescribe how the subclass processes them. The base class never lowers or otherwise mutates the input instance.- classmethod check_applicability(ommx_instance: Instance) AdapterApplicabilityReport#
Inspect applicability without mutating or preparing
ommx_instance.Adapter-specific preconditions run only after at least one complete input-class clause contains the instance. The hook receives an isolated copy so it cannot mutate the caller’s instance. Any explicitly transformed value is a different input and must be checked separately.
- classmethod require_applicable(ommx_instance: Instance) AdapterApplicabilityReport#
Return the report or raise
AdapterNotApplicableError.
- classmethod solve(ommx_instance: Instance, *, diagnostics: DiagnosticsSink | None = None) Solution#
- Abstractmethod:
Solve an OMMX instance.
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.
- INPUT_CLASS: ClassVar[InstanceClass | None] = None#
- property solver_input: SolverInput#
- Abstractmethod:
- PreconditionValue#
- SamplerInput#
- SamplerOutput#
- SolverInput#
- SolverOutput#