simpleml.save_patterns.decorators module¶
functions and decorators to extend default save patterns
-
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: str) → Callable[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)
-
static
register_artifact
(artifact_name: str, save_attribute: str, restore_attribute: str) → Callable[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
-
static
-
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: Optional[str] = None, save: Optional[bool] = True, load: Optional[bool] = True) → Callable[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 – 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; default true; whether to drop the decorated class as the save method for the registered save pattern
- load – optional bool; default true; whether to drop the decorated class as the load method for the registered save pattern
-
static
register_save_pattern
(cls_or_save_pattern: Union[str, Type[CT_co], None] = None, save: Optional[bool] = True, load: Optional[bool] = True, overwrite: Optional[bool] = False) → Callable[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 – 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; default true; whether to use the decorated class as the save method for the registered save pattern
- load – optional bool; default true; whether to use the decorated class as the load method for the registered save pattern
- overwrite – optional bool; default false; whether to overwrite the the registered class for the save pattern, if it exists. Otherwise throw an error
-
static
-
simpleml.save_patterns.decorators.
deregister_artifact
(cls: Type[CT_co], artifact_name: str) → None[source]¶ Deregister the artifact from being able to be persisted for this class
-
simpleml.save_patterns.decorators.
deregister_save_pattern
(cls: Optional[Type[CT_co]] = None, save_pattern: Optional[str] = None, save: Optional[bool] = True, load: Optional[bool] = True) → None[source]¶ Deregister the class to use for saving and loading for the particular pattern
Parameters: - save_pattern – the optional string denoting the pattern this class implements (e.g. disk_pickled). Checks class attribute cls.SAVE_PATTERN if null
- save – optional bool; default true; whether to remove the class as the save method for the registered save pattern
- load – optional bool; default true; whether to remove the class as the load method for the registered save pattern
-
simpleml.save_patterns.decorators.
register_artifact
(cls: Type[CT_co], artifact_name: str, save_attribute: str, restore_attribute: str) → None[source]¶ Register the artifact for potential persistence by a save pattern
-
simpleml.save_patterns.decorators.
register_save_pattern
(cls: Type[CT_co], save_pattern: Optional[str] = None, save: Optional[bool] = True, load: Optional[bool] = True, overwrite: Optional[bool] = False) → None[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 – the optional string denoting the pattern this class implements (e.g. disk_pickled). Checks class attribute cls.SAVE_PATTERN if null
- save – optional bool; default true; whether to use the decorated class as the save method for the registered save pattern
- load – optional bool; default true; whether to use the decorated class as the load method for the registered save pattern
- overwrite – optional bool; default false; whether to overwrite the the registered class for the save pattern, if it exists. Otherwise throw an error