simpleml.save_patterns.decorators
functions and decorators to extend default save patterns
Module Contents
Classes
Decorators for artifact de/registration |
|
Decorators that can be used for registering methods for loading |
Functions
|
Deregister the artifact from being able to be persisted for this class |
|
Deregister the class to use for saving and |
|
Register the artifact for potential persistence by a save pattern |
|
Register the class to use for saving and |
Attributes
- class simpleml.save_patterns.decorators.ExternalArtifactDecorators[source]
Bases:
object
Decorators for artifact de/registration Expected to be applied at the class level to add class attributes indicating registered artifacts
- static deregister_artifact(artifact_name)[source]
Class level decorator to deregister artifacts produced. Expects each class to implement as many as needed to accomodate. Expected to be used by subclasses that redefine artifacts but dont want to expose the possibility of a developer accessing them. (By default registering artifacts only exposes them to be persisted if declared in save_methods)
- Parameters
artifact_name (str) –
- Return type
Callable
- static register_artifact(artifact_name, save_attribute, restore_attribute)[source]
Class level decorator to define artifacts produced. Expects each class to implement as many as needed to accomodate.
Format: ``` @register_artifact(artifact_name=’model’, save_attribute=’wrapper_attribute’, restore_attribute=’_internal_attribute’) class NewPersistable(Persistable):
@property def wrapper_attribute(self):
- if not hasattr(self, _internal_attribute):
self._internal_attribute = self.create_attribute()
return self._internal_attribute
``` Intentionally specify different attributes for saving and restoring to allow developer to wrap attribute in property decorator for lazy caching
- class simpleml.save_patterns.decorators.SavePatternDecorators[source]
Bases:
object
Decorators that can be used for registering methods for loading and saving.
- static deregister_save_pattern(cls_or_save_pattern=None, save=True, load=True)[source]
Class level decorator to deregister allowed save patterns. Doesnt actually make use of the class but included for completeness. Recommended to use importable deregister_save_pattern function directly
- Parameters
cls_or_save_pattern (Optional[str]) – the optional string or class denoting the pattern this class implements (e.g. disk_pickled). Checks class attribute cls.SAVE_PATTERN if null cls is automatically passed when calling decorator without parameters (@SavePatternDecorators.deregister_save_pattern)
save (Optional[bool]) – optional bool; default true; whether to drop the decorated class as the save method for the registered save pattern
load (Optional[bool]) – optional bool; default true; whether to drop the decorated class as the load method for the registered save pattern
- Return type
Callable
- static register_save_pattern(cls_or_save_pattern=None, save=True, load=True, overwrite=False)[source]
Decorates a class to register the method(s) to use for saving and/or loading for the particular pattern
IT IS ALLOWABLE TO HAVE DIFFERENT CLASSES HANDLE SAVING AND LOADING FOR THE SAME REGISTERED PATTERN
- Parameters
cls_or_save_pattern (Optional[Union[str, Type]]) – the optional string or class denoting the pattern this class implements (e.g. disk_pickled). Checks class attribute cls.SAVE_PATTERN if null cls is automatically passed when calling decorator without parameters (@SavePatternDecorators.register_save_pattern)
save (Optional[bool]) – optional bool; default true; whether to use the decorated class as the save method for the registered save pattern
load (Optional[bool]) – optional bool; default true; whether to use the decorated class as the load method for the registered save pattern
overwrite (Optional[bool]) – optional bool; default false; whether to overwrite the the registered class for the save pattern, if it exists. Otherwise throw an error
- Return type
Callable
- simpleml.save_patterns.decorators.deregister_artifact(cls, artifact_name)[source]
Deregister the artifact from being able to be persisted for this class
- Parameters
cls (Type) –
artifact_name (str) –
- Return type
None
- simpleml.save_patterns.decorators.deregister_save_pattern(cls=None, save_pattern=None, save=True, load=True)[source]
Deregister the class to use for saving and loading for the particular pattern
- Parameters
save_pattern (Optional[str]) – the optional string denoting the pattern this class implements (e.g. disk_pickled). Checks class attribute cls.SAVE_PATTERN if null
save (Optional[bool]) – optional bool; default true; whether to remove the class as the save method for the registered save pattern
load (Optional[bool]) – optional bool; default true; whether to remove the class as the load method for the registered save pattern
cls (Optional[Type]) –
- Return type
None
- simpleml.save_patterns.decorators.register_artifact(cls, artifact_name, save_attribute, restore_attribute)[source]
Register the artifact for potential persistence by a save pattern
- simpleml.save_patterns.decorators.register_save_pattern(cls, save_pattern=None, save=True, load=True, overwrite=False)[source]
Register the class to use for saving and loading for the particular pattern
IT IS ALLOWABLE TO HAVE DIFFERENT CLASSES HANDLE SAVING AND LOADING FOR THE SAME REGISTERED PATTERN
- Parameters
save_pattern (Optional[str]) – the optional string denoting the pattern this class implements (e.g. disk_pickled). Checks class attribute cls.SAVE_PATTERN if null
save (Optional[bool]) – optional bool; default true; whether to use the decorated class as the save method for the registered save pattern
load (Optional[bool]) – optional bool; default true; whether to use the decorated class as the load method for the registered save pattern
overwrite (Optional[bool]) – optional bool; default false; whether to overwrite the the registered class for the save pattern, if it exists. Otherwise throw an error
cls (Type) –
- Return type
None