syne_tune.util module
- class syne_tune.util.RegularCallback(callback, call_seconds_frequency)[source]
Bases:
objectAllows to call the callback function at most once every
call_seconds_frequencyseconds.- Parameters:
callback (
callable) – Callback objectcall_seconds_frequency (
float) – Wait time between subsequent calls
- syne_tune.util.experiment_path(tuner_name=None, local_path=None)[source]
Return the path of an experiment which is used both by
Tunerand to collect results of experiments.- Parameters:
tuner_name (
Optional[str]) – Name of a tuning experimentlocal_path (
Optional[str]) –Local path where results should be saved. If not specified, then the environment variable
"SYNETUNE_FOLDER"is used if defined otherwise~/syne-tune/is used. Defining the environment variable"SYNETUNE_FOLDER"allows tooverride the default path.
- Return type:
Path- Returns:
Path where to write logs and results for Syne Tune tuner.
- syne_tune.util.name_from_base(base, max_length=63)[source]
Append a timestamp to the provided string.
This function assures that the total length of the resulting string is not longer than the specified max length, trimming the input parameter if necessary.
- Parameters:
base (
Optional[str]) – String used as prefix to generate the unique namemax_length (
int) – Maximum length for the resulting string (default: 63)
- Return type:
str- Returns:
Input parameter with appended timestamp
- syne_tune.util.repository_root_path()[source]
- Return type:
Path- Returns:
Returns path including
syne_tune,examples,benchmarking
- syne_tune.util.script_checkpoint_example_path()[source]
- Return type:
Path- Returns:
Path of checkpoint example
- syne_tune.util.script_height_example_path()[source]
- Return type:
Path- Returns:
Path of
train_heigthexample
- syne_tune.util.is_increasing(lst)[source]
- Parameters:
lst (
List[Union[float,int]]) – List of float or int entries- Return type:
bool- Returns:
Is
lststrictly increasing?
- syne_tune.util.is_positive_integer(lst)[source]
- Parameters:
lst (
List[int]) – List of int entries- Return type:
bool- Returns:
Are all entries of
lstof typeintand positive?
- syne_tune.util.is_integer(lst)[source]
- Parameters:
lst (
list) – List of entries- Return type:
bool- Returns:
Are all entries of
lstof typeint?
- syne_tune.util.dump_json_with_numpy(x, filename=None)[source]
Serializes dictionary
xin JSON, taking into account NumPy specific value types such asn.p.int64.- Parameters:
x (
dict) – Dictionary to serialize or encodefilename (
Union[str,Path,None]) – Name of file to store JSON to. Optional. If not given, the JSON encoding is returned as string
- Return type:
Optional[str]- Returns:
If
filename is None, JSON encoding is returned
- syne_tune.util.dict_get(params, key, default)[source]
Returns
params[key]if this exists and is not None, anddefaultotherwise. Note that this is not the same asparams.get(key, default). Namely, ifparams[key]is equal to None, this would return None, but this method returnsdefault.This function is particularly helpful when dealing with a dict returned by
argparse.ArgumentParser. Wheneverkeyis added as argument to the parser, but a value is not provided, this leads toparams[key] = None.- Return type:
Any
- syne_tune.util.recursive_merge(a, b, stop_keys=None)[source]
Merge dictionaries
aandb, wherebtakes precedence. We typically use this to modify a dictionarya, sobis smaller thana. Further recursion is stopped on any node with key instop_keys. Use this for dictionary-valued entries not to be merged, but to be replaced by what is inb.- Parameters:
a (
Dict[str,Any]) – Dictionaryb (
Dict[str,Any]) – Dictionary (can be empty)stop_keys (
Optional[List[str]]) – See above, optional
- Return type:
Dict[str,Any]- Returns:
Merged dictionary
- syne_tune.util.metric_name_mode(metric_names, metric_mode, metric)[source]
Retrieve the metric mode given a metric queried by either index or name. :type metric_names:
List[str] :param metric_names: metrics names defined in a scheduler :type metric_mode:Union[str,List[str]] :param metric_mode: metric mode or modes of a scheduler :type metric:Union[str,int] :param metric: Index or name of the selected metric :return the name and the mode of the queried metric- Return type:
Tuple[str,str]