qom.loopers.base module¶
Module to interface loopers.
- class qom.loopers.base.BaseLooper(func, params: dict, params_system: dict, cb_update, parallel: bool, p_index: int, p_start: float)¶
Bases:
object
Class to interface loopers.
Initializes
func
,params
,axes
,results
andupdater
.- Parameters:
func (callable) – Function to loop, formatted as
func(system_params)
, wheresystem_params
is a dictionary of the updated parameters for the system for that iteration of the looper.params (dict) – Parameters of the looper containing the key
'X'
, each with the keys'var'
and'val'
(or'min'
,'max'
and'dim'
) for the name of the parameter to loop and its corresponding values (or minimum and maximum values along with dimension). Refer to Notes below for all available options.params_system (dict) – Parameters of the system. If not provided, new keys are created for the looper variables.
cb_update (callable) – Callback function to update status and progress, formatted as
cb_update(status, progress, reset)
, wherestatus
is a string,progress
is a float andreset
is a boolean.parallel (bool) – Option to format outputs when running in parallel.
p_index (int) – Index of the process.
p_start (float) – Time at which the process was started. If not provided, the value is initialized to current time.
Notes
- The
params
dictionary currently supports the following keys: key
value
‘show_progress’
(bool) option to display the progress for the looper. Default is
False
.‘file_path_prefix’
(str) prefix for the file path to save the looper results. If not provided, the results are not saved.
‘prefix_with_system’
(bool) option to append the system parameters in the file path. Default is
False
.‘grad’
(bool) option to calculate gradients with respect to the X-axis. Default is
False
.‘grad_position’
(int or float or str) a value denoting the position or a mode to calculate the position. Options are
'mean'
for the mean of the axis values and'all'
to output all positions. Default is'all'
.‘threshold_mode’
(str) Mode of calculation of threshold values. Options are
'minmax'
for minimum value at which maximum is reached and'minmin'
for minimmum value at which minimum is reached. Default is'minmax'
.‘X’
(dict) parameters of the X-axis.
‘Y’
(dict) parameters of the Y-axis.
‘Z’
(dict) parameters of the Z-axis.
- Each axis dictionary (
'X'
,'Y'
or'Z'
) can contain the following keys (arranged in the descending order of their priorities): key
value
‘var’
(str) name of the parameter to loop. Its value defaults to the axis name in lower case if the axis is a sequence of values and not a dictionary.
‘idx’
(int) index of the parameter if the parameter is a sequence of values.
‘val’
(list or numpy.ndarray) values of the parameter. The remaining keys are not checked if its value is given. Otherwise, the values of
'min'
,'max'
,'dim'
and'scale'
are used to obtain'val'
.‘min’
(float) minimum value of the parameter. Default is
-5.0
.‘max’
(float) maximum value of the parameter. Default is
5.0
.‘dim’
(int) number of values from ‘min’ to ‘max’, both inclusive. Default is
101
.‘scale’
(str) step scale of the values. Options are
'log'
for logarithmic and'linear'
for linear. Default is'linear'
- get_X_results()¶
Method to obtain results for variation in X-axis.
- Returns:
xs (numpy.ndarray) – Values of the X-axis.
vs (numpy.ndarray) – Calculated values.
- get_full_file_path()¶
Method to obtain the full file path.
- Returns:
file_path – Full file path.
- Return type:
str
- get_grad_index(axis_values: list)¶
Method to obtain the index of a particular position to calculate the gradients.
- Parameters:
axis_values (numpy.ndarray) – Values of the axis.
- Returns:
idx – Index of the required position.
- Return type:
int
- get_params_str(axis: str)¶
Method to obtain a string containing the parameters used in the looper.
- Parameters:
axis ({
'X'
,'Y'
,'Z'
}) – Name of the axis.- Returns:
params_str – String containing the parameters used in the looper.
- Return type:
str
- get_thresholds()¶
Method to calculate the threshold values for the results.
- Returns:
thresholds – Threshold values. Keys are
'X'
,'Y'
,'Z'
and'V'
.- Return type:
dict
- load_results()¶
Method to load the results from a .npz file.
- Returns:
loaded – Boolean denoting whether results were successfully loaded.
- Return type:
bool
- looper_defaults = {'X': None, 'Y': None, 'Z': None, 'file_path_prefix': None, 'grad': False, 'grad_position': 'all', 'prefix_with_system': False, 'show_progress': False, 'threshold_mode': 'minmax'}¶
Default parameters of the looper.
- Type:
dict
- save_results()¶
Method to save the results to a .npz file.
- Returns:
saved – Boolean denoting whether results were successfully saved.
- Return type:
bool
- set_axis(axis: str)¶
Method to set the list of axis values.
- Parameters:
axis (str) – Name of the axis (
'X'
,'Y'
or'Z'
).
- set_params(params: dict)¶
Method to validate and set the looper parameters.
- Parameters:
params (dict) – Parameters for the looper.