Model

class Model

Combinatorial optimization model containing objective and constraints.

Methods

__init__

Construct a model.

copy

Return a copy of the model.

get_variables

Return the variables appearing in the model.

to_intermediate_model

Convert the model to an intermediate model according to degree and encoding settings.

to_unconstrained_poly

Convert model constraints into penalty form and return an unconstrained objective polynomial.

Attributes

constraints

Constraints held by the model.

objective

Objective function held by the model.

variables

List of variables in the model.

__add__(self, arg: Poly | Constraint | ConstraintList, /) Model

__add__

Parameters:

arg (Poly | Constraint | ConstraintList)

Return type:

Model

__eq__(self, arg: object, /) bool

__eq__

Parameters:

arg (object)

Return type:

bool

__iadd__(self, arg: Poly | Constraint | ConstraintList, /) Model

__iadd__

Parameters:

arg (Poly | Constraint | ConstraintList)

Return type:

Model

__init__(self) None
__init__(self, objective: Poly | Matrix) None
__init__(self, constraint: Constraint | ConstraintList) None
__init__(self, objective: Poly | Matrix, constraint: Constraint | ConstraintList) None

Construct a model. If no arguments are given, create an empty model with zero objective and no constraints. If a polynomial is given, construct a model with the polynomial as the objective. If constraints are given, Construct a model with the constraints. __init__

Overload 2.

Args:
  • objective (amplify.Poly | amplify.Matrix): Objective function.

Overload 3.

Args:
  • constraint (amplify.Constraint | amplify.ConstraintList): Constraints to include.

Overload 4.

Args:
  • objective (amplify.Poly | amplify.Matrix): Objective function.

  • constraint (amplify.Constraint | amplify.ConstraintList): Constraints to include.

__isub__(self, arg: Poly, /) Model

__isub__

Parameters:

arg (Poly)

Return type:

Model

__ne__(self, arg: object, /) bool

__ne__

Parameters:

arg (object)

Return type:

bool

__radd__(self, arg: Poly | Constraint | ConstraintList, /) Model

__radd__

Parameters:

arg (Poly | Constraint | ConstraintList)

Return type:

Model

__repr__(self) str

Return a developer-friendly string representation of the model.

Return type:

str

__str__(self) str

Return a human-readable string representation of the model.

Return type:

str

__sub__(self, arg: Poly, /) Model

__sub__

Parameters:

arg (Poly)

Return type:

Model

copy(self) Model

Return a copy of the model.

Returns:

Copy of the model.

Return type:

Model

get_variables(self, with_penalty: bool = False) list[Variable]

Return the variables appearing in the model.

When with_penalty is True, this may trigger penalty construction for constraints and include auxiliary variables introduced by the penalty formulation.

Parameters:

with_penalty (bool) – Whether to include auxiliary variables introduced by penalty formulation. Defaults to False.

Returns:

Variables that appear in the model.

Return type:

list[Variable]

to_intermediate_model(
self,
acceptable_degrees: AcceptableDegrees,
integer_encoding_method: Literal['Unary', 'Linear', 'Binary', 'Default'] | IntegerEncodingMethod = IntegerEncodingMethod.Default,
real_encoding_method: Literal['Random4', 'Random8', 'Random16', 'Random32'] | RealEncodingMethod = RealEncodingMethod.Random16,
quadratization_method: Literal['IshikawaKZFD', 'Substitute'] | QuadratizationMethod = QuadratizationMethod.Substitute,
substitution_multiplier: float = 1.0,
) tuple[Model, IntermediateMapping]

Convert the model to an intermediate model according to degree and encoding settings.

Performs variable conversion (integer/real to binary as needed), optional degree reduction, and variable remapping based on the required degrees.

Parameters:
  • acceptable_degrees (AcceptableDegrees) – Acceptable degree settings.

  • integer_encoding_method (Literal['Unary', 'Linear', 'Binary', 'Default'] | amplify.IntegerEncodingMethod) – Integer variable conversion method. Defaults to IntegerEncodingMethod.Default.

  • real_encoding_method (Literal['Random4', 'Random8', 'Random16', 'Random32'] | amplify.RealEncodingMethod) – Real variable conversion method. Defaults to RealEncodingMethod.Random16.

  • quadratization_method (Literal['IshikawaKZFD', 'Substitute'] | amplify.QuadratizationMethod) – Quadratization method. Defaults to QuadratizationMethod.Substitute.

  • substitution_multiplier (float) – Multiplier for substitution penalty scaling (used only with QuadratizationMethod.Substitute). Defaults to 1.0.

Returns:

Converted model and mapping information.

Return type:

tuple[Model, IntermediateMapping]

to_unconstrained_poly(self) Poly

Convert model constraints into penalty form and return an unconstrained objective polynomial.

Returns:

Unconstrained objective polynomial.

Return type:

Poly

property constraints

Constraints held by the model.

Return type:

ConstraintList

property objective

Objective function held by the model.

Return type:

Poly | Matrix

property variables

List of variables in the model.

Equivalent to get_variables() with with_penalty=False.

Return type:

list[Variable]