Variables¶
- class Variables¶
Bases:
object
A class for variables with different types.
Methods
Constructor.
Convert from Amplify-BBOpt's solution dict to Amplify SDK's solution dict.
Decodes an encoded value vector to an input value vector.
Encode an input value vector to an the Amplify SDK's variable value vector.
Constructs one_hot/domain_wall constraints required for non-binary decision variables.
Generates random value vector compatible with self.
Issue the Amplify SDK's variables (
amplify.PolyArray
) for all elemental variables.Make
poly_array = None
for all variables involved.Set
amplify.PolyArray
(issued inVariables.issue_amplify_variable
) of all elemental variables toVariables.poly_array
.Unify duplicate variables in different
Variables
class instances associated with thisBlackBoxFuncList
class.Attributes
The Amplify SDK's variables (
amplify.PolyArray
) in dictionary form that represents the variables in thisVariables
.Return names of the variables.
Return names of the variables.
A number of encoded variables for [
num_elemental_variables
] variables.A number of instances of
VariableBase
andVariableBase
in theVariableListBase
instances.The Amplify SDK's variables (
amplify.PolyArray
) that represents the variables in thisVariables
.The Amplify SDK's variable generator.
- __getattr__(name: str) VariableBase | VariableListBase ¶
Get a variable in var_dict.
- Parameters:
name (str) – The variable name.
- Raises:
ValueError – If variable with a given name is not found.
- Returns:
A variable or variable list.
- Return type:
- __getitem__(i: int) VariableBase | VariableListBase ¶
- __init__(**kwargs: VariableBase | VariableListBase) None ¶
Constructor.
- __str__() str ¶
Return a human-readable information of the variables.
- Returns:
The human-readable information of the variables.
- Return type:
- convert_to_amplify_solution_dict(
- solution_dict: StructuredSolutionDict,
Convert from Amplify-BBOpt’s solution dict to Amplify SDK’s solution dict.
- Parameters:
solution_dict (StructuredSolutionDict) – Amplify-BBOpt’s solution dict. This can be entire solution in case of multiple-objective optimization (keys other than this
Variables
’ keys can exist in the solution dict).- Returns:
The converted Amplify SDK’;’s solution dict.
- Return type:
- decode(encoded_values: list[int | float]) StructuredSolution ¶
Decodes an encoded value vector to an input value vector.
- Parameters:
encoded_values (list[int | float]) – A primitive value vector (as in the Amplify SDK’s variables).
- Raises:
RuntimeError – The number of encoded variables does not match with the length of the encoded value vector.
- Returns:
The resulting input value vector.
- Return type:
- encode(x: StructuredSolution) list[int | float] ¶
Encode an input value vector to an the Amplify SDK’s variable value vector.
- Parameters:
x (StructuredSolution) – The input value vector.
- Raises:
RuntimeError – If the length of the input value vector does not match with the number of variables.
- Returns:
A list of the resulting encoded value vector.
- Return type:
- generate_amplify_constraint() ConstraintList ¶
Constructs one_hot/domain_wall constraints required for non-binary decision variables.
- Returns:
The resulting constraints.
- Return type:
amplify.ConstraintList
- generate_random_value(
- rng: Generator,
- ref_value: StructuredSolution | None = None,
- find_neighbour: bool = False,
Generates random value vector compatible with self. If ref_value is specified, only one element in ref_value will be randomly modified so that the return value vector yields close values to the ref_value. Note that ref_value will not be modified.
- Parameters:
rng (np.random.Generator) – NumPy’s random generator.
ref_value (StructuredSolution | None, optional) – A reference input value vector. Defaults to None.
find_neighbour (bool, optional) – True to generate a random value neighbour to the reference value. Defaults to False.
- Returns:
The resulting input value vector of the variables.
- Return type:
- issue_amplify_variable() None ¶
Issue the Amplify SDK’s variables (
amplify.PolyArray
) for all elemental variables.
- set_elemental_poly_array() None ¶
Set
amplify.PolyArray
(issued inVariables.issue_amplify_variable
) of all elemental variables toVariables.poly_array
.- Raises:
RuntimeError – If poly_array is not set for the variable.
- unify_variables(
- var_dict_universe: dict[str, VariableBase | VariableListBase],
- variable_generator: VariableGenerator,
Unify duplicate variables in different
Variables
class instances associated with thisBlackBoxFuncList
class.- Parameters:
var_dict_universe (dict[str, VariableBase | VariableListBase]) – A variable dictionary containing all the variables with their names in the multiple
Variables
class instances.variable_generator (amplify.VariableGenerator) – A variable generator instantiated in the Amplify SDK.
- Raises:
RuntimeError – If unknown variable name is found.
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.variables', '__doc__': 'A class for variables with different types.', '__init__': <function Variables.__init__>, 'variable_generator': <property object>, 'unify_variables': <function Variables.unify_variables>, 'issue_amplify_variable': <function Variables.issue_amplify_variable>, 'set_elemental_poly_array': <function Variables.set_elemental_poly_array>, 'num_elemental_variables': <property object>, 'num_amplify_variables': <property object>, '__len__': <function Variables.__len__>, '__getitem__': <function Variables.__getitem__>, '__getattr__': <function Variables.__getattr__>, '_set_variable': <function Variables._set_variable>, '_del_variable': <function Variables._del_variable>, 'nullify_poly_array': <function Variables.nullify_poly_array>, 'poly_array': <property object>, 'amplify_variables': <property object>, 'convert_to_amplify_solution_dict': <function Variables.convert_to_amplify_solution_dict>, 'names': <property object>, 'flat_names': <property object>, '__str__': <function Variables.__str__>, 'encode': <function Variables.encode>, 'decode': <function Variables.decode>, 'generate_random_value': <function Variables.generate_random_value>, 'generate_amplify_constraint': <function Variables.generate_amplify_constraint>, '__dict__': <attribute '__dict__' of 'Variables' objects>, '__weakref__': <attribute '__weakref__' of 'Variables' objects>, '__annotations__': {'var_dict': 'dict[str, VariableBase | VariableListBase]', '_poly_array': 'amplify.PolyArray | None'}})¶
- __weakref__¶
list of weak references to the object (if defined)
- property amplify_variables: dict[str, Poly | PolyArray]¶
The Amplify SDK’s variables (
amplify.PolyArray
) in dictionary form that represents the variables in thisVariables
.
- property flat_names: list[str]¶
Return names of the variables. The variable names for a variable list is expanded.
(the names of elemental variables in a variable list are returned instead of the name of the variable list).
- Raises:
RuntimeError – If the variable name is not set.
- Returns:
A list of the variable names in a ‘flat’ manner.
- Return type:
- property names: list¶
Return names of the variables.
- Returns:
A list of the variable names.
- Return type:
- property num_amplify_variables: int¶
A number of encoded variables for [
num_elemental_variables
] variables.
- property num_elemental_variables: int¶
A number of instances of
VariableBase
andVariableBase
in theVariableListBase
instances.
- property poly_array: PolyArray¶
The Amplify SDK’s variables (
amplify.PolyArray
) that represents the variables in thisVariables
.
- property variable_generator: VariableGenerator¶
The Amplify SDK’s variable generator.