concepts.utils.range.Range#

class Range[source]#

Bases: object

A range of values, handles wraparound.

Methods

contains(x)

Return whether the value is in the range.

difference(config1, config2)

Return the difference between two configurations.

make_in_range(value)

Return the value if it is in range, otherwise return None.

sample()

Sample a value from the range.

Attributes

low

The lower bound of the range.

high

The upper bound of the range.

wrap_around

Whether the range wraps around, i.e. whether the upper bound is adjacent to the lower bound.

__init__(low, high, wrap_around=False)[source]#

Initialize the range.

Parameters:
  • low (float) – The lower bound of the range.

  • high (float) – The upper bound of the range.

  • wrap_around (bool) – Whether the range wraps around, i.e. whether the upper bound is adjacent to the lower bound.

__new__(**kwargs)#
contains(x)[source]#

Return whether the value is in the range.

Parameters:

x (float) –

Return type:

bool

difference(config1, config2)[source]#

Return the difference between two configurations.

Parameters:
  • config1 (float) – The first configuration.

  • config2 (float) – The second configuration.

Returns:

The difference between the two configurations.

Return type:

float

make_in_range(value)[source]#

Return the value if it is in range, otherwise return None. When wrap_around is True, the value is wrapped around.

Parameters:

value (float) – the value to be checked.

Returns:

the value if it is in range, otherwise return None. When wrap_around is True, a value will always be returned.

Return type:

float | None

sample()[source]#

Sample a value from the range.

Return type:

float

high: float#

The upper bound of the range.

low: float#

The lower bound of the range.

wrap_around: bool#

Whether the range wraps around, i.e. whether the upper bound is adjacent to the lower bound.