RealVariable

class RealVariable

Bases: Variable

Represents a real-valued variable with specified bounds, discretization and encoding method.

Methods

__init__

Initializes a real-valued variable with specified bounds, discretization and encoding method.

to_poly

Converts the variable to the Amplify SDK's polynomial representation.

Attributes

bounds

Returns the bounds of the variable.

encoding

Returns the encoding method for the variable.

name

Returns the name of the variable.

possible_values

Returns a list of possible values for a discrete variable, or a pair of boundary values for a continuous variable.

type

Returns the type of the variable.

__add__(other: Variable | Poly | float) Poly
__eq__(other: object) bool

Return self==value.

__hash__() int

Return hash(self).

__init__(
bounds: tuple[float, float],
encoding: EncodingMethod = EncodingMethod.DomainWall,
discretization_spec: DiscretizationSpec | None = None,
) None

Initializes a real-valued variable with specified bounds, discretization and encoding method.

Parameters:
  • bounds (tuple[float, float]) – The lower and upper bounds for the variable.

  • encoding (EncodingMethod, optional) – The encoding method to use. Defaults to EncodingMethod.DomainWall.

  • discretization_spec (DiscretizationSpec | None, optional) – The discretization specification to use. Defaults to None (DiscretizationSpec()).

Raises:
  • ValueError – If the discretization is specified with Amplify encoding.

  • ValueError – If the bounds are invalid.

  • TypeError – If the bounds are not float values.

  • ValueError – If the number of bins is invalid.

  • ValueError – If the non-uniform discretization method is specified with Amplify encoding.

  • ValueError – If the lower bound is not greater than 0 for LogUniform discretization.

  • TypeError – If the encoding method is invalid.

__mul__(other: Variable | Poly | float) Poly
__ne__(other: object) bool

Return self!=value.

__neg__() Poly
__pos__() Poly
__pow__(other: int) Poly
__radd__(other: Poly | float) Poly
__repr__() str

Return repr(self).

__rmul__(other: Poly | float) Poly
__rsub__(other: Poly | float) Poly
__str__() str

Return str(self).

__sub__(other: Variable | Poly | float) Poly
__truediv__(other: float) Poly
to_poly() Poly

Converts the variable to the Amplify SDK’s polynomial representation.

Returns:

The Amplify SDK’s polynomial representation of the variable.

Return type:

amplify.Poly

__dict__ = mappingproxy({'__module__': 'amplify_bbopt.variable', '__doc__': 'Represents a real-valued variable with specified bounds, discretization and encoding method.', '__init__': <function RealVariable.__init__>, '__annotations__': {}})
__weakref__

list of weak references to the object (if defined)

property bounds: tuple[float | None, float | None] | None

Returns the bounds of the variable.

property encoding: _EncodingMethodBase

Returns the encoding method for the variable.

property name: str

Returns the name of the variable.

property possible_values: list[float | int] | tuple[float, float]

Returns a list of possible values for a discrete variable, or a pair of boundary values for a continuous variable.

Returns:

The possible values or bounds.

Return type:

list[float | int] | tuple[float, float]

property type: VariableType

Returns the type of the variable.