tarexp.base module#

The base module contains classes and functions that are inherited by other TARexp classes.

class tarexp.base.Eventable[source]#

Bases: object

Deprecated since version 0.1.3: The Eventable class is plan to be removed in the future. It is not currently used by any classes. The event dispatcher of the tarexp.experiments.Experiment is implemented in itself.

fire(event: str, *args, **kwargs)[source]#
on(event: str, f: callable)[source]#
updateCallbacks(callbacks)[source]#
class tarexp.base.Savable[source]#

Bases: object

Default Savable Class Mixin

Classes inheriting this class by default save itself has a gzipped pickle file. The files can be read by tarexp.util.readObj.

However, this is designed to be a catch-all method. Each class potentially would implement its own set of save and load methods, such as tarexp.workflow.Workflow.save() and tarexp.workflow.Workflow.load().

save(path: Path | str, overwrite=False) Path[source]#

Saving the object

Parameters:
  • path – Path to the output directory or filename. If a directory is provided, the filename is set to be the name of the class with extention .pgz.

  • overwrite – Whether to overwrite an existing file.

Return type:

The path to the saved file.

classmethod load(path: Path)[source]#

Class method for loading the saved file.

The method should be used as {Class}.load(filename) which loads the saved content as a {Class} instance with type checking.

Parameters:

path – Path to the output directory or filename. If a directory is provided, it looks for a name of the class with extention .pgz.

Return type:

An instance of the evoked class.

class tarexp.base.space(data={})[source]#

Bases: Namespace

Hashable Namespace for Parameters.

It is an extension of argparse.Namespace that supports better __repr__ method and being hashable with a stable hash function based on the content.

This class support direct access to the key-value content by attributes and items. Common dictionary interfaces such as .keys() and .items() are also implemented.

Caution

The content should all be hashable or at least the representation (.__repr__()) should uniquely identify the object. It is being used to distinguish experiment runs in tarexp.experiments.Experiment by comparing the identifier of the tarexp.component.Component.

keys()[source]#
Returns:

Sorted tuple of the existing keys in the instance. Similar to the built-in .keys() method for Python dictionaries.

Return type:

Tuple[Any]

items()[source]#
Returns:

Iterator of the item tuples in sorted order. Similar to the built-in .items() method for Python dictionaries.

Return type:

Tuple[Any]

values()[source]#
Returns:

Tuple of values in the content sorted by the key. Similar to the built-in .values() method for Python dictionaries.

Return type:

Tuple[Any]

tarexp.base.easy_repr(cls)[source]#

Decorator for class to have a better __repr__

If attribute config exists, it is used as the representation (unique identifier of the instance). If not, it creates a py:class:tarexp.util.space instance for the non-callable attributes for building the representation. Attributes starts with _ are ignored.