ommx_fixstars_amplify_adapter.adapter
Attributes
Classes
An abstract interface for OMMX Solver Adapters, defining how solvers should be used with OMMX. |
Functions
|
Module Contents
- class ommx_fixstars_amplify_adapter.adapter.OMMXFixstarsAmplifyAdapter(ommx_instance: ommx.Instance)
Bases:
ommx.adapter.SolverAdapterAn 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.- _function_to_poly(func: ommx.Function) amplify.Poly
- _set_constraints()
- _set_decision_variables()
- _set_objective()
- decode(data: amplify.Result) ommx.Solution
Convert Amplify result and ommx.Instance to ommx.Solution.
This method is intended to be used if the model has been acquired with solver_input for further adjustment of the solver parameters, and separately optimizing the model.
Note that alterations to the model may make the decoding process incompatible – decoding will only work if the model still describes effectively the same problem as the OMMX instance used to create the adapter.
Example:
The following example shows how to solve an unconstrained linear optimization problem with x as the objective function.
>>> from ommx_fixstars_amplify_adapter import OMMXFixstarsAmplifyAdapter >>> from ommx import Instance >>> >>> ommx_instance = Instance.minimize() >>> x1 = ommx_instance.new_integer("x1", lower=0, upper=5) >>> ommx_instance.objective = x1 >>> >>> adapter = OMMXFixstarsAmplifyAdapter(ommx_instance) >>> model = adapter.solver_input >>> # ... some modification of model's parameters >>> client = amplify.AmplifyAEClient() >>> client.token = "YOUR API TOKEN" # Set your API token >>> client.parameters.time_limit_ms = 1000 >>> result = amplify.solve(model, client) >>> solution = adapter.decode(result)
- decode_to_state(data: amplify.Result) ommx.State
Create an ommx.State from an amplify.Result.
Example:
The following example shows how to solve an unconstrained linear optimization problem with x as the objective function.
>>> from ommx_fixstars_amplify_adapter import OMMXFixstarsAmplifyAdapter >>> from ommx import Instance >>> >>> ommx_instance = Instance.minimize() >>> x1 = ommx_instance.new_integer("x1", lower=0, upper=5) >>> ommx_instance.objective = x1 >>> >>> adapter = OMMXFixstarsAmplifyAdapter(ommx_instance) >>> model = adapter.solver_input >>> # ... some modification of model's parameters >>> client = amplify.AmplifyAEClient() >>> client.token = "YOUR API TOKEN" # Set your API token >>> client.parameters.time_limit_ms = 1000 >>> result = amplify.solve(model, client) >>> state = adapter.decode_to_state(result)
- classmethod recommended_preparation_policy() ommx.PreparationPolicy
Recommend lowering unsupported special constraints before using Amplify.
Amplify accepts OneHot constraints directly, so this recommendation preserves them and lowers only Indicator and SOS1 constraints. The returned policy is fresh and caller-editable.
- classmethod solve(ommx_instance: ommx.Instance, *, amplify_token: str = '', timeout: int = 1000, diagnostics: ommx.adapter.DiagnosticsSink | None = None) ommx.Solution
Solve the given ommx.Instance using Fixstars Amplify AE, returning an ommx.Solution.
diagnosticsare not available through this Adapter. The reserveddiagnosticsargument is accepted for compatibility with the OMMX SolverAdapter interface.- NOTE The amplify_token parameter _must_ be passed to properly
instantiate the Fixstars Amplify AE Client. Using the default value will result in an error.
- Parameters:
ommx_instance – The ommx.Instance to prepare and solve.
amplify_token – Token for instantiating the Fixstars Amplify AE Client, obtained from your Fixstars Amplify account.
timeout – Timeout passed to the client.
diagnostics – Reserved for OMMX SolverAdapter compatibility; currently unused.
Example:
The following example shows how to solve an unconstrained linear optimization problem with x as the objective function.
>>> from ommx_fixstars_amplify_adapter import OMMXFixstarsAmplifyAdapter >>> from ommx import Instance >>> >>> ommx_instance = Instance.minimize() >>> x1 = ommx_instance.new_integer("x1", lower=0, upper=5) >>> ommx_instance.objective = x1 >>> token = "YOUR API TOKEN" # Set your API token >>> solution = OMMXFixstarsAmplifyAdapter.solve(ommx_instance, amplify_token=token)
- classmethod solve_without_preparation(ommx_instance: ommx.Instance, *, amplify_token: str = '', timeout: int = 1000, diagnostics: ommx.adapter.DiagnosticsSink | None = None) ommx.Solution
Solve an exact Fixstars Amplify Adapter input without preparing it.
Use this method when the input instance has already been prepared, possibly with a custom policy, or already belongs to
INPUT_CLASS.diagnosticsare not available through this Adapter. The reserveddiagnosticsargument is accepted for compatibility with the OMMX SolverAdapter interface.- NOTE The
amplify_tokenparameter must be passed to properly instantiate the Fixstars Amplify AE Client. Using the default value will result in an error.
- Parameters:
ommx_instance – The exact Fixstars Amplify Adapter input to solve.
amplify_token – Token for instantiating the Fixstars Amplify AE Client, obtained from your Fixstars Amplify account.
timeout – Timeout passed to the client.
diagnostics – Reserved for OMMX SolverAdapter compatibility; currently unused.
- NOTE The
- INPUT_CLASS: ClassVar[ommx.InstanceClass]
Required condition for an exact Adapter input.
- instance
- model
- property solver_input: amplify.Model
The Amplify model generated from this OMMX instance
- ommx_fixstars_amplify_adapter.adapter._make_variable_label(variable: ommx.DecisionVariable) str
- ommx_fixstars_amplify_adapter.adapter.ABSOLUTE_TOLERANCE = 1e-06