amplify.IsingIntQuadraticModel
- class IsingIntQuadraticModel
Is the quadratic model which represents the Ising model with integer coefficients.
The class abstracts a "logical model" from multivariate polynomial, matrix, and constraints. The "logical model" is a formulation for inputting into the ising machines. This class generates a logical model by reducing the order of multivariate polynomial to quadratic and reallocating variable index.
The class converts to a logical model from the below objects.
Multivariate polynomial
Includes polynomial with the order greater than three.
Matrix
Constraint
Includes multiple constraints
注釈
For more details of the conversion source, see
__init__()
and its examples.Through attributes of this class, you can get a raw input model, a converted logical model, and mapping from an input model to a logical model.
注釈
- The following operators are defined for the class.
Addition:
a + b
(__add__()
,__radd__()
,__iadd__()
)
- __init__(*args, **kwargs)
Returns the Ising quadratic model initialized by input and constraints.
Overloads:
- __init__(poly, constraints)
- __init__(matrix, constant, constraints)
- パラメータ:
poly (
IsingIntPoly
) --polynomial of the Ising model.
matrix (
IsingIntMatrix
) --the Ising matrix of the Ising model
constant (
int
, optional) --a constant term of the Ising model
constraints (
IsingIntConstraint
,IsingIntConstraints
, optional) --constraints of the Ising model
Example
>>> from amplify import (gen_symbols, ... IsingIntQuadraticModel) >>> from amplify.constraint import equal_to >>> s = gen_symbols(IsingIntQuadraticModel, 3) >>> model = IsingIntQuadraticModel(s[0] + s[1] + s[2], equal_to(s[0], 1)) >>> model.input_poly s_0 + s_1 + s_2
>>> from amplify import (IsingIntMatrix, ... IsingIntQuadraticModel) >>> mat = IsingIntMatrix(3) >>> mat[0, 1] = 1 >>> mat[0, 2] = 2 >>> mat[1, 2] = 3 >>> model = IsingIntQuadraticModel(mat, 4) >>> model.input_matrix ([[0, 1, 2], [0, 0, 3], [0, 0, 0]], 4)
Methods
__init__
(*args, **kwargs)Returns the Ising quadratic model initialized by input and constraints.
check_constraints
(*args, **kwargs)Overloaded function.
Attributes
Returns the constraints of the Ising quadratic model.
Equivalent to
logical_matrix
.Returns the input
IsingIntPoly
.Returns the mapping from input varieties to logical varieties.
Returns the pair of
IsingIntMatrix
and the constant term of the Ising quadratic model.Is almost same as
logical_matrix
, but includes the constraint terms.Is almost same as
logical_poly
, but includes the constraint terms.Returns
IsingIntPoly
, which represents the Ising quadratic model.Returns the number of variables in the input Ising quadratic model.
Returns the number of variables in the converted Ising quadratic model.
substituion_multiplier
- check_constraints(*args, **kwargs)
Overloaded function.
check_constraints(self: amplify.IsingIntQuadraticModel, arg0: List[int]) -> List[Tuple[amplify.IsingIntConstraintTermRef, bool]]
no docstring
check_constraints(self: amplify.IsingIntQuadraticModel, arg0: Dict[int, int]) -> List[Tuple[amplify.IsingIntConstraintTermRef, bool]]
check_constraints(self: amplify.IsingIntQuadraticModel, arg0: function) -> List[Tuple[amplify.IsingIntConstraintTermRef, bool]]
- property input_constraints
Returns the constraints of the Ising quadratic model.
Example
>>> from amplify import (gen_symbols, ... IsingIntPoly, ... IsingIntQuadraticModel) >>> from amplify.constraint import equal_to >>> s = gen_symbols(IsingIntPoly, 1) >>> model = IsingIntQuadraticModel(equal_to(s[0], 1)) >>> eq = model.input_constraints.pop() >>> eq.is_satisfied([-1]) False >>> eq.is_satisfied([1]) True
- property input_matrix
Equivalent to
logical_matrix
.
- property input_poly
Returns the input
IsingIntPoly
.Example
>>> from amplify import (IsingIntPoly, ... IsingIntQuadraticModel) >>> poly = IsingIntPoly({(0, 1, 2) : 1}) >>> model = IsingIntQuadraticModel(poly) >>> model.input_poly s_0 s_1 s_2
- property logical_mapping
Returns the mapping from input varieties to logical varieties.
Example
>>> from amplify import (IsingIntMatrix, ... IsingIntQuadraticModel) >>> mat = IsingIntMatrix(3) >>> model = IsingIntQuadraticModel(mat) >>> model.logical_mapping {2: 2, 0: 0, 1: 1}
- property logical_matrix
Returns the pair of
IsingIntMatrix
and the constant term of the Ising quadratic model.Example
>>> from amplify import (IsingIntMatrix, ... IsingIntQuadraticModel) >>> mat = IsingIntMatrix(3) >>> mat[0, 1] = 1 >>> mat[0, 2] = 2 >>> mat[1, 2] = 3 >>> poly = mat.to_Poly() >>> poly += 4 >>> model = IsingIntQuadraticModel(poly) >>> model.logical_matrix ([[0, 1, 2], [0, 0, 3], [0, 0, 0]], 4)
- property logical_model_matrix
Is almost same as
logical_matrix
, but includes the constraint terms.Example
>>> from amplify import (IsingIntMatrix, ... IsingIntQuadraticModel) >>> from amplify.constraint import equal_to >>> mat = IsingIntMatrix(3) >>> mat[0, 1] = 1 >>> mat[0, 2] = 2 >>> mat[1, 2] = 3 >>> poly = mat.to_Poly() >>> poly += 4 >>> model = IsingIntQuadraticModel(poly, equal_to(s[0], 1)) >>> model.logical_model_matrix ([[-2, 1, 2], [0, 0, 3], [0, 0, 0]], 6)
- property logical_model_poly
Is almost same as
logical_poly
, but includes the constraint terms.Example
>>> from amplify import (gen_symbols, ... IsingIntQuadraticModel) >>> from amplify.constraint import equal_to >>> s = gen_symbols(IsingIntQuadraticModel, 3) >>> model = IsingIntQuadraticModel(s[0] + s[1] + s[2], equal_to(s[0], 1)) >>> model.logical_model_poly s_0 + s_1 - s_2 + 2
- property logical_poly
Returns
IsingIntPoly
, which represents the Ising quadratic model.Note
The
logical_poly
variables don't always correspond to theinput_poly
variables, even ifinput_poly
is quadratic.Example
>>> from amplify import (IsingIntPoly, ... IsingIntQuadraticModel) >>> poly = IsingIntPoly({(0, 1, 2) : 1}) >>> model = IsingIntQuadraticModel(poly) >>> model.logical_poly s_0 s_1 + s_0 s_2 - 2 s_0 s_3 + s_1 s_2 - 2 s_1 s_3 - 2 s_2 s_3 + s_0 + s_1 + s_2 - 2 s_3 + 3
- property num_input_vars
Returns the number of variables in the input Ising quadratic model.
Example
>>> from amplify import (IsingIntPoly, ... IsingIntQuadraticModel) >>> poly = IsingIntPoly({(0, 1, 2) : 1}) >>> model = IsingIntQuadraticModel(poly) >>> model.num_input_vars 3
- property num_logical_vars
Returns the number of variables in the converted Ising quadratic model.
Example
>>> from amplify import (IsingIntPoly, ... IsingIntQuadraticModel) >>> poly = IsingIntPoly({(0, 1, 2) : 1}) >>> model = IsingIntQuadraticModel(poly) >>> model.num_logical_vars 4