Utilities¶
Utility modules
Package-wide useful routines¶
- class orion.core.utils.Factory(name, bases, namespace, **kwargs)[source]¶
Deprecated, will be removed in v0.3.0. See GenericFactory instead
Methods
__call__
(of_type, *args, **kwargs)Create an object, instance of
cls.__base__
, on first call.
- class orion.core.utils.GenericFactory(base: type[T])[source]¶
Factory to create instances of classes inheriting a given
base
class.The factory can instantiate children of the base class at any level of inheritance. The children class must have different names (capitalization insensitive). To instantiate objects with the factory, use
factory.create('name_of_the_children_class')
passing the name of the children class to instantiate.To support classes even when they are not imported, register them in the
entry_points
of the package’ssetup.py
. The factory will import all registered classes in the entry_points before looking for available children to create new objects.- Parameters
- base: class
Base class of all children that the factory can instantiate.
Methods
create
(of_type, *args, **kwargs)Create an object, instance of
self.base
get_class
(of_type)Get the class object (not instantiated)
Get children classes of
self.base
- create(of_type: str, *args, **kwargs)[source]¶
Create an object, instance of
self.base
- Parameters
- of_type: str
Name of class, subclass of
self.base
. Capitalization insensitive- args: *
Positional arguments to construct the given class.
- kwargs: **
Keyword arguments to construct the given class.
- orion.core.utils.compute_identity(size: int = 16, **sample) str [source]¶
Compute a unique hash out of a dictionary
- Parameters
- size: int
size of the unique hash
- **sample:
Dictionary to compute the hash from
- orion.core.utils.float_to_digits_list(number)[source]¶
Convert a float into a list of digits, without conserving exponent
- orion.core.utils.generate_temporary_file(basename='dump', suffix='.pkl')[source]¶
Generate a temporary file where data could be saved.
Create an empty file without collision. Return name of generated file.
- orion.core.utils.get_all_types(parent_cls, cls_name)[source]¶
Get all subclasses and lowercase subclass names