Creating Decision Variables¶
Decision variables are the input parameters to the black-box objective function that is subject to optimization. Amplify-BBOpt explores the search space by varying these variables to minimize the output of the objective function.
Types and definitions of decision variables¶
Amplify-BBOpt supports the following types of decision variables.
Binary variables¶
Binary Variables are variables that take binary values (0 or 1). They are defined using the BinaryVariable class.
>>> from amplify_bbopt import BinaryVariable
>>> q = BinaryVariable()
>>> print(q.possible_values)
[0, 1]
Integer variables¶
Integer variables can take integer values. They are similar to continuous variables, but their values are restricted to integers. Integer variables are defined using the IntegerVariable class. The range of possible values must be specified as the bounds argument.
>>> from amplify_bbopt import IntegerVariable
>>> n = IntegerVariable(bounds=(0, 5))
>>> print(n.possible_values)
[0, 1, 2, 3, 4, 5]
Real variables¶
Real variables can take real values. They are suitable for parameters that vary continuously within a certain range, such as between 0.0 and 1.0. Real variables are defined using the RealVariable class. The range of possible values must be specified as the bounds argument.
>>> from amplify_bbopt import RealVariable
>>> x = RealVariable(bounds=(0, 1))
>>> print(x.possible_values)
[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
Discrete variables¶
Discrete variables take values from arbitrarily defined discrete sets. Each discrete variable can have its own set of possible values. For example, a discrete variable represented by the values [0.1, 0.3, 0.5, 1.0] can be defined using the DiscreteVariable class. You need to provide the list of discrete points as the values argument.
>>> from amplify_bbopt import DiscreteVariable
>>> x = DiscreteVariable(values=[0.1, 0.3, 0.5, 1.0])
>>> print(x.possible_values)
[0.1, 0.3, 0.5, 1.0]
Hint
For integer, real, and discrete variables, internal variable transformations are applied. Specifically, encoding is performed for integer and discrete variables, while both encoding and discretization are applied for real variables.
By default, the domain-wall method is used for encoding. For discretization, 11 discrete points are considered, and the uniform (equal-interval) discretization method is applied.
You can customize the encoding method, the number of discrete points, and the discretization scheme using the EncodingMethod and DiscretizationSpec classes.
For example, to modify only the number of discrete points from the default setting, you can configure it as follows:
>>> from amplify_bbopt import RealVariable, DiscretizationSpec
>>> x = RealVariable(
... bounds=(0, 1),
... discretization_spec=DiscretizationSpec(num_bins=5), # 5 discrete points
... )
>>> print(x.possible_values)
[0.0, 0.25, 0.5, 0.75, 1.1]
For more detailed information on variable transformations, see Encoding types and settings.
Decision variables List¶
You can create multiple decision variables with the same properties at once using a list, as shown below.
>>> from amplify_bbopt import BinaryVariable
>>> q = [BinaryVariable() for _ in range(5)]
>>> print(len(q))
5
>>> print(q[0].possible_values)
[0, 1]
Properties of decision variables¶
The decision variables created as above contain various properties.
Attribute name |
Description |
|---|---|
|
Range of variable values |
|
Encoding method of the variable |
|
Variable name |
|
Possible values the variable can take |
|
Type of variable |
>>> from amplify_bbopt import RealVariable, DiscretizationSpec
>>> x = RealVariable(bounds=(0, 1))
>>> print(x.bounds)
(0.0, 1.0)
>>> print(x.encoding.method)
EncodingMethod.DomainWall
>>> print(x.name)
x_2
>>> print(x.possible_values)
[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
>>> print(x.type)
Real