calix.common.algorithms.BinarySearch

class calix.common.algorithms.BinarySearch

Bases: calix.common.base.Algorithm

Perform a binary search within the parameter range of a calibration.

Using the class requires basic settings, which come from an instance of a Calib class. Therefore it is required to hook the algorithm to a calibration before calling run(). Calling run(connection, target_result) then performs the calibration. The algorithm starts with the usual binary search algorithms and adds two additional steps in the end. This aims to explore the value above as well as below the last tested value of the normal binary search algorithm. The best-suited parameter tested during the last few steps is returned.

Variables
  • calibration – Class derived from base class Calib implementing functions for configuring parameters and measuring results as well as yielding important parameters for the algorithm to run.

  • n_steps – Number of steps to use during calibration.

  • step_increments – Amount to change parameter with each step.

  • initial_parameters – Parameters to start calibration with.

  • n_steps_best – Number of steps (counted from last) to take into account when finding the best parameters in the end.

__init__()

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__()

Initialize self.

hook_to_calibration(calibration)

Make an instance of a calibration known to the algorithm, allowing to use parameters set there.

run(connection, target_result)

Perform a binary search within given parameter range.

Attributes

n_steps_best

hook_to_calibration(calibration: calix.common.base.Calib)

Make an instance of a calibration known to the algorithm, allowing to use parameters set there.

Parameters

calibration – Instance of calibration class that will be run with this algorithm.

n_steps_best: ClassVar[int] = 3
run(connection: pyhxcomm_vx.ConnectionHandle, target_result: Union[int, float, numpy.ndarray])numpy.ndarray

Perform a binary search within given parameter range. In the end, the parameter is moved by 1 additionally. This way, the result of the binary search and the two neighboring settings are tested and the best-suitable parameter is returned.

Parameters
  • connection – Connection that will be used when setting up parameters and measuring results.

  • target_result – Target for the calibration. The parameters will be set up such that the results match the target as close as possible. The target can be either a single value that will be used for all instances of parameters or an array containing a specific target for each instance. When using an array, its length has to match n_instances.

Returns

Best suited parameters to reach given targets.

Raises
  • ValueError – if the measure_parameters() function of the provided calibration class returns an array with bad length.

  • ValueError – if the number of steps to take into account when finding the best parameters in the end is smaller than 3. A value of 3 is required for the additional step to make sense.