Utilities

Module contents

exception olympus.utils.CircularDependencies[source]

Bases: Exception

class olympus.utils.HyperParameters(space, **kwargs)[source]

Bases: object

Keeps track of mandatory hyper parameters

Parameters:
space: Dict[str, Space]

A dictionary defining each parameters and their respective space/dim

kwargs:

A dictionary of defined hyper parameters

Methods

add_parameters([strict]) Insert a new parameter value
missing_parameters() Returns a dictionary of missing parameters
parameters([strict]) Returns all the parameters and checks if any are missing
add_parameters(strict=True, **kwargs)[source]

Insert a new parameter value

Parameters:
strict: bool

control if an exception is raised or not when an unknown parameter is encountered

Returns:
a dictionary of unknown parameter
missing_parameters()[source]

Returns a dictionary of missing parameters

parameters(strict=False)[source]

Returns all the parameters and checks if any are missing

class olympus.utils.LazyCall(fun, *args, **kwargs)[source]

Bases: object

Save the call parameters of a function for it can be invoked at a later date

Methods

__call__(*args, **kwargs) Call self as a function.
add_arguments  
invoke  
was_invoked  
add_arguments(*args, **kwargs)[source]
invoke(**kwargs)[source]
was_invoked()[source]
exception olympus.utils.MissingArgument[source]

Bases: Exception

exception olympus.utils.MissingParameters[source]

Bases: Exception

class olympus.utils.TimeThrottler(fun: Callable[[A], R], every=10, callback=None)[source]

Bases: object

Limit how often the function fun is called in seconds

Parameters:
fun:

function to throttle

every: int

Time in second in between each calls

callback:

function called when throttled

Examples

throttled_print = TimeThrottler(print, every=1)

# Only prints 0
for i in range(0, 10):
    throttled_print(i)

# Prints 0 to 9
for i in range(0, 10):
    throttled_print(i)
    time.sleep(1)

Methods

__call__(*args, **kwargs) Call self as a function.
exception olympus.utils.WrongParameter[source]

Bases: Exception

olympus.utils.compress_dict(state: Dict[KT, VT]) → Dict[KT, VT][source]

Compress a state dictionary and return a json friendly compressed state

olympus.utils.decode_rng_state(state)[source]
olympus.utils.decompress_dict(state: Dict[KT, VT]) → Dict[KT, VT][source]

Decompress a state dictionary and return its json

olympus.utils.encode_rng_state(state)[source]
olympus.utils.fetch_device()[source]

Set the default device to CPU if cuda is not available

olympus.utils.find_batch_size(model, shape, low, high, dtype=torch.float32)[source]

Find the highest batch size that can fit in memory using binary search

olympus.utils.get_rng_states()[source]
olympus.utils.get_seeds()[source]

Returns a set of seed that are used by the program

olympus.utils.get_value(item: Union[float, torch.Tensor]) → float[source]
olympus.utils.missing_params(space, kwargs, missing)[source]
olympus.utils.new_seed(**kwargs)[source]

Global seed management

olympus.utils.parse_uri(uri: str) → Dict[KT, VT][source]
olympus.utils.parse_uri_options(options: str) → Dict[KT, VT][source]
olympus.utils.set_rng_states(state)[source]
olympus.utils.set_seeds(seed)[source]

Set most commonly used global seeds

olympus.utils.show_dict(dictionary: Dict[KT, VT], indent: int = 0, print_fun=<built-in function print>) → NoReturn[source]
olympus.utils.update_params(space, kwargs, params, strict=True, unknown_params=None)[source]