calix.common.algorithms.LinearSearch

class calix.common.algorithms.LinearSearch(initial_parameters: Optional[Union[int, numpy.ndarray]] = None, step_size: int = 1, max_steps: int = 50)

Bases: calix.common.base.Algorithm

Perform a linear search within the given parameter range to calibrate. From an initial guess, the parameter is moved in constant steps until the calibration target is crossed.

Initializing the class requires basic settings, which come from an instance of a Calib class. Calling run(connection, target_result) then performs the calibration. The parameters are sweeped until the results crosses the target, or the maximum number of steps is exceeded.

Variables
  • calibration – Instance of calibration class used to provide settings and functions.

  • max_steps – Maximum number of steps to use. If set too low, it can limit the available range if the step_size during the calibration is set low. When having reached the target value with all instances, the calibration stops early.

  • initial_parameters – Initial (guessed) parameters to start algorithm with.

  • step_size – Amount by which the parameters are moved in every step.

Raises

ValueError – If step_size is not a positive number.

__init__(initial_parameters: Optional[Union[int, numpy.ndarray]] = None, step_size: int = 1, max_steps: int = 50)

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

Methods

__init__([initial_parameters, step_size, …])

Initialize self.

run(connection, target_result)

Performs the calibration sweeping the parameter by step_size.

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

Performs the calibration sweeping the parameter by step_size.

The algorithm starts with the parameters supplied in the argument as a guess. It then moves in steps of step_size towards the target until the result crosses the target. The calibration then stops and returns the parameter that yields the results closest to the target in the last 2 steps, i.e. while testing the values around crossing the threshold.

Note that this function can be called multiple times with different step_sizes in order to approach the target step-wise. Doing so it is important to supply the results of the previous run as parameters.

Parameters
  • connection – Connection to use during configuring and measuring.

  • target_result – Target result for calibration.

Returns

Best suited parameters to reach given targets.

Raises
  • TypeError – if step_size does not allow addition.

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