Getting Started

– Warming up –

Let us import the library first:

[1]:
import perturb_lib as plib

The first thing you will notice is that the random seed is set to some default value (13 here for arbitrary reasons). This is done for all the random number libraries that are a part of Perturb-lib. If for some reason you wish to experiment with a different random seed, for instance 17, you can do the following:

[22]:
plib.set_all_seeds(17)
15:08:37 | INFO | Fixing random seeds of numpy, pytorch, random, and perturb-lib to 17.

The temporary files such as raw and cached data, saved models, intermediate products of model training, etc. are stored in a cache folder. The cache folder can be accessed (read and modified) through the corresponding environmental variable. Modify the default path to cache as follows:

[23]:
plib.set_path_to_cache("my_project/my_cache")
plib.get_path_to_cache()
[23]:
PosixPath('my_project/my_cache')

Perturb-lib also offers access to internal logger. While it may not be necessary to use the same logger in your own scripts, it is useful to control the internal logging level (by default set to logging.INFO).

[2]:
plib.logger
[2]:
<Logger perturb_lib (INFO)>
[3]:
plib.logger.debug("I am a logger in the debug mode.")
plib.logger.info("I am a logger in the info mode.")
13:57:33 | INFO | I am a logger in the info mode.

In the DEBUG mode, the debugging log is now visible:

[4]:
import logging

plib.logger.setLevel(logging.DEBUG)
plib.logger.debug("I am a logger in the debug mode.")
plib.logger.info("I am a logger in the info mode.")
13:58:14 | DEBUG | I am a logger in the debug mode.
13:58:14 | INFO | I am a logger in the info mode.