RealVariableList¶
- class RealVariableList¶
Bases:
VariableListBase
A class for the real variable array with uniform discretization.
Methods
Constructor.
Convert a Amplify SDK's variable value vector (i.e. binary variable) to value indices of the variable list.
Discretization information.
Decodes values of the Amplify SDK variables (i.e. binary variables) to a list of values of this variable list.
Encode the values to values of the Amplify SDK variables (i.e. binary variables) if necessary.
Generate the Amplify SDK's constraints related to the conversion of non-binary variable.
Generate a random value compatible with the variable.
Convert value indices of the variable array to a Amplify SDK's variable value vector.
Convert value indices to values of the variable list.
Issue the Amplify SDK variables (amplify.PolyArray) relevant to the variables contained in this variable list, only when VariableListBase.poly_array is None.
Make poly_array = None for the elemental variables in the variable list.
Convert the variable to a Amplify SDK's polynomial.
Return the polynomial that represents the sum of all the variables in the variable list class.
Convert values of the variable list to value indices.
Attributes
Return the lower and upper bounds that the variable can take.
Return the distance between discretization points.
Return the number of the variables.
Return the encoding method.
Return the name of the variable.
Return the number of discretization bins.
Return the number of the Amplify SDK variables encoded from the variable.
Return the Amplify SDK's PolyArray that represents all elemental variables existing in this variable list.
Return the type of the variable.
Return the list of elemental variables in the variable list.
- __add__(other: Any) Poly ¶
Add the variable to another variable or a polynomial.
- Parameters:
other – A variable or a polynomial to add.
- Raises:
ValueError – If other is not a variable or a polynomial.
- Returns:
The resulting polynomial.
- Return type:
- __getitem__(i: int) VariableBase ¶
- __init__(bounds: tuple[float, float], nbins: int, length: int, method: str = 'domain_wall') None ¶
Constructor.
- Parameters:
bounds (tuple) – The lower and upper bounds that the variable can take.
nbins (int) – The number of distretization points.
length (int) – The length of the array.
method (str, optional) – Encoding method. ‘dw’: domain-wall. ‘one_hot’: one-hot.
'dw'. ('amplify' is not available as of now. Defaults to)
- Raises:
ValueError – If ‘amplify’ is specified as the method.
ValueError – If nbins is less than 2.
- __iter__() Iterator[VariableBase] ¶
- __len__() int ¶
Return the number of the variables.
- Returns:
The number of the variables.
- Return type:
- __mul__(other: Any) Poly ¶
Return the polynomial that represents the sum of all the variables multiplied by a value.
- Parameters:
other – A value to multiply.
- Returns:
The resulting polynomial.
- Return type:
- __radd__(other: Any) Poly ¶
Add the variable to another variable or a polynomial.
- Parameters:
other – A variable or a polynomial to add.
- Raises:
ValueError – If other is not a variable or a polynomial.
- Returns:
The resulting polynomial.
- Return type:
- __rmul__(other: Any) Poly ¶
Return the polynomial that represents the sum of all the variables multiplied by a value.
- Parameters:
other – A value to multiply.
- Returns:
The resulting polynomial.
- Return type:
- __rsub__(other: Any) Poly ¶
Subtract another variable or a polynomial from the variable.
- Parameters:
other – A variable or a polynomial to subtract.
- Raises:
ValueError – If other is not a variable or a polynomial.
- Returns:
The resulting polynomial.
- Return type:
- __str__() str ¶
Returns a human-readable information of the variables.
- Returns:
The human-readable information of the variables.
- Return type:
- __sub__(other: Any) Poly ¶
Subtract another variable or a polynomial from the variable.
- Parameters:
other – A variable or a polynomial to subtract.
- Raises:
ValueError – If other is not a variable or a polynomial.
- Returns:
The resulting polynomial.
- Return type:
- binary_to_idx(binary: list[int]) list[int] ¶
Convert a Amplify SDK’s variable value vector (i.e. binary variable) to value indices of the variable list.
- Parameters:
binary (list[int]) – The Amplify SDK’s variable value vector.
- Raises:
RuntimeError – If “amplify” is specified as the encoding method.
- Returns:
A list of the resulting value indices of the variable list.
- Return type:
- construct_discretize_table() ndarray ¶
Discretization information.
- Returns:
The variable list.
- Return type:
np.ndarray
- decode(amplify_value_vector: list[int | Any]) list[Any] ¶
Decodes values of the Amplify SDK variables (i.e. binary variables) to a list of values of this variable list.
- encode(value_list: list[Any]) list[int | Any] ¶
Encode the values to values of the Amplify SDK variables (i.e. binary variables) if necessary.
- generate_amplify_constraint() ConstraintList ¶
Generate the Amplify SDK’s constraints related to the conversion of non-binary variable.
- Returns:
The resulting constraints.
- Return type:
amplify.ConstraintList
- generate_random_value( ) Any ¶
Generate a random value compatible with the variable.
If ref_value specified, only one element from ref_value is randomly modified so that values != ref_value. User-defined constraints (if there’s any) are not considered in this value.
- Parameters:
- Returns:
A list of the resulting values of the variable array.
- Return type:
Any
- idx_to_binary(idx_list: list[int]) list[int] ¶
Convert value indices of the variable array to a Amplify SDK’s variable value vector.
- Parameters:
- Raises:
RuntimeError – If “amplify” is specified as the encoding method.
- Returns:
The resulting Amplify SDK’s variable value vector.
- Return type:
- idx_to_value(idx_list: list[int]) list[Any] ¶
Convert value indices to values of the variable list.
- Parameters:
- Raises:
RuntimeError – If “amplify” is specified as the encoding method.
- Returns:
A list of the resulting values of the variable list.
- Return type:
list[Any]
- issue_amplify_variable(
- generator: VariableGenerator,
- var_counter: dict[VariableType, int],
- var_name: dict[VariableType, str],
Issue the Amplify SDK variables (amplify.PolyArray) relevant to the variables contained in this variable list, only when VariableListBase.poly_array is None.
- Parameters:
generator (amplify.VariableGenerator) – A variable generator.
var_counter (dict[amplify.VariableType, int]) – Counter counts how many amplify variables of each amplify.VariableType are issued.
var_name (dict[amplify.VariableType, str]) – Name prefix of amplify variables of each amplify.VariableType.
- nullify_poly_array() None ¶
Make poly_array = None for the elemental variables in the variable list.
- to_amplify_poly() Poly ¶
Convert the variable to a Amplify SDK’s polynomial. The sum of all variables in the list is considered.
- Returns:
The resulting polynomials.
- Return type:
amplify.Poly
- to_poly() Poly ¶
Return the polynomial that represents the sum of all the variables in the variable list class.
- Returns:
The polynomial.
- Return type:
- value_to_idx(value_list: list[Any]) list[int] ¶
Convert values of the variable list to value indices.
- Parameters:
value_list (list[Any]) – A list of the values to convert.
- Raises:
RuntimeError – If “amplify” is specified as the encoding method.
- Returns:
The resulting value index list.
- Return type:
- __abstractmethods__ = frozenset({})¶
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.variable', '__doc__': 'A class for the real variable array with uniform discretization.', '__init__': <function RealVariableList.__init__>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_variable_list': 'list[VariableBase]', '_name': 'str | None', '_poly_array': 'amplify.PolyArray | None'}})¶
- __slots__ = ()¶
- __weakref__¶
list of weak references to the object (if defined)
- property bounds: tuple¶
Return the lower and upper bounds that the variable can take.
- Returns:
The lower and upper bounds that the variable can take.
- property delta: float¶
Return the distance between discretization points.
- Returns:
The distance between discretization points.
- property len: int¶
Return the number of the variables. This is significant for variable list classes.
- Returns:
The number of the variables.
- Return type:
- property method: str | None¶
Return the encoding method.
- Returns:
The encoding method. None is no encoding is necessary.
- Return type:
str | None
- property name: str | None¶
Return the name of the variable.
- Returns:
The variable name.
- Return type:
- property nbins: int¶
Return the number of discretization bins.
- Returns:
The number of discretization bins.
- Return type:
- property num_amplify_variables: int¶
Return the number of the Amplify SDK variables encoded from the variable.
- Returns:
The number of the Amplify SDK variables.
- Return type:
- property poly_array: PolyArray | None¶
Return the Amplify SDK’s PolyArray that represents all elemental variables existing in this variable list.
- Returns:
The Amplify SDK’s PolyArray.
- Return type:
amplify.PolyArray
- property variable_list: list[VariableBase]¶
Return the list of elemental variables in the variable list.
- Returns:
The list of the variables.
- Return type: