syne_tune.util module
- class syne_tune.util.RegularCallback(callback, call_seconds_frequency)[source]
Bases:
object
Allows to call the callback function at most once every
call_seconds_frequency
seconds.- 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
Tuner
and 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 when running locally outside of SageMaker. 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 to override the default path.
- Return type:
Path
- Returns:
Path where to write logs and results for Syne Tune tuner. On SageMaker, results are written to
"/opt/ml/checkpoints/"
so that files are persisted continuously to S3 by SageMaker.
- syne_tune.util.s3_experiment_path(s3_bucket=None, experiment_name=None, tuner_name=None)[source]
Returns S3 path for storing results and checkpoints.
- Parameters:
s3_bucket (
Optional
[str
]) – If not given, the default bucket for the SageMaker session is usedexperiment_name (
Optional
[str
]) – If given, this is used as first directorytuner_name (
Optional
[str
]) – If given, this is used as second directory
- Return type:
str
- Returns:
S3 path, ending on “/”
- syne_tune.util.name_from_base(base, default, 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 namedefault (
str
) – String used ifbase is None
max_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_heigth
example
- syne_tune.util.is_increasing(lst)[source]
- Parameters:
lst (
List
[Union
[float
,int
]]) – List of float or int entries- Return type:
bool
- Returns:
Is
lst
strictly 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
lst
of typeint
and positive?
- syne_tune.util.is_integer(lst)[source]
- Parameters:
lst (
list
) – List of entries- Return type:
bool
- Returns:
Are all entries of
lst
of typeint
?
- syne_tune.util.dump_json_with_numpy(x, filename=None)[source]
Serializes dictionary
x
in 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, anddefault
otherwise. 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
. Wheneverkey
is 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
a
andb
, whereb
takes precedence. We typically use this to modify a dictionarya
, sob
is 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
]