ommx_fixstars_amplify_adapter

Submodules

Exceptions

OMMXFixstarsAmplifyAdapterError

Common base class for all non-exit exceptions.

Classes

OMMXFixstarsAmplifyAdapter

An abstract interface for OMMX Solver Adapters, defining how solvers should be used with OMMX.

Functions

model_to_instance(→ ommx.v1.Instance)

The function to create an ommx.v1.Instance from the Fixstars Amplify model.

Package Contents

exception ommx_fixstars_amplify_adapter.OMMXFixstarsAmplifyAdapterError

Bases: Exception

Common base class for all non-exit exceptions.

class ommx_fixstars_amplify_adapter.OMMXFixstarsAmplifyAdapter(ommx_instance: ommx.v1.Instance)

Bases: ommx.adapter.SolverAdapter

An abstract interface for OMMX Solver Adapters, defining how solvers should be used with OMMX.

See the implementation guide for more details.

_function_to_poly(func: ommx.v1.Function) amplify.Poly
_set_constraints()
_set_decision_variables()
_set_objective()
decode(data: amplify.Result) ommx.v1.Solution

Convert optimized Python-MIP model and ommx.v1.Instance to ommx.v1.Solution.

This method is intended to be used if the model has been acquired with solver_input for futher 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.v1 import Instance, DecisionVariable, Linear
>>>
>>> x1 = DecisionVariable.integer(1, lower=0, upper=5)
>>> ommx_instance = Instance.from_components(
...     decision_variables=[x1],
...     objective=x1,
...     constraints=[],
...     sense=Instance.MINIMIZE,
... )
>>>
>>> adapter = OMMXFixstarsAmplifyAdapter(ommx_instance)
>>> model = adapter.solver_input
>>> # ... some modification of model's parameters
>>> client = amplify.FixstarsClient()
>>> client.token = "YOUR API TOKEN" # Set your API token
>>> client.parameters.timeout = 1000
>>> result = amplify.solve(model, client)  
>>> solution = adapter.decode(result)  
decode_to_state(data: amplify.Result) ommx.v1.State

Create an ommx.v1.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.v1 import Instance, DecisionVariable, Linear
>>>
>>> x1 = DecisionVariable.integer(1, lower=0, upper=5)
>>> ommx_instance = Instance.from_components(
...     decision_variables=[x1],
...     objective=x1,
...     constraints=[],
...     sense=Instance.MINIMIZE,
... )
>>>
>>> adapter = OMMXFixstarsAmplifyAdapter(ommx_instance)
>>> model = adapter.solver_input
>>> # ... some modification of model's parameters
>>> client = amplify.FixstarsClient()
>>> client.token = "YOUR API TOKEN" # Set your API token
>>> client.parameters.timeout = 1000
>>> result = amplify.solve(model, client)  
>>> state = adapter.decode_to_state(result)  
classmethod solve(ommx_instance: ommx.v1.Instance, *, amplify_token: str = '', timeout: int = 1000) ommx.v1.Solution

Solve the given ommx.v1.Instance using Fixstars Amplify, returning an ommx.v1.Solution.

NOTE The amplify_token parameter _must_ be passed to properly

instantiate the Fixstars Client. Using the default value will result in an error.

Parameters:
  • ommx_instance – The ommx.v1.Instance to solve.

  • amplify_token – Token for instantiating the Fixstars Client, obtained from your Fixstars Amplify account.

  • timeout – Timeout passed the client

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.v1 import Instance, DecisionVariable, Linear
>>>
>>> x1 = DecisionVariable.integer(1, lower=0, upper=5)
>>> ommx_instance = Instance.from_components(
...     decision_variables=[x1],
...     objective=x1,
...     constraints=[],
...     sense=Instance.MINIMIZE,
... )
>>> token = "YOUR API TOKEN" # Set your API token
>>> solution = OMMXFixstarsAmplifyAdapter.solve(ommx_instance, amplify_token=token) 
instance
model
property solver_input: amplify.Model

The Amplify model generated from this OMMX instance

ommx_fixstars_amplify_adapter.model_to_instance(model: amplify.Model) ommx.v1.Instance

The function to create an ommx.v1.Instance from the Fixstars Amplify model.

Example:

The following example shows how to create an ommx.v1.Instance from a Fixstars Amplify model.

>>> import amplify
>>> from ommx_fixstars_amplify_adapter import model_to_instance
>>>
>>> gen = amplify.VariableGenerator()
>>> x = gen.scalar("Binary", name="x")
>>> model = amplify.Model(x)
>>>
>>> ommx_instance = model_to_instance(model)