Model developer API¶
The Plums Model Format main API is in the Model class which allows loading, saving and dynamic
creation through a high-level python API.
The following classes and functions exposes the inner workings of the main Model API. It is deemed the developer API
because it should not be used directly by end-users or model producers/consumers.
Producer version handling¶
-
plums.model.components.version.version(format, value)[source]¶ Construct a valid
Versioninstance with the correct format.
-
plums.model.components.version.register(cls, hook=None)[source]¶ Register a
Versionclass to theversionfunction with an optional initialisation hook.
-
class
plums.model.components.version.MetaVersion(name, bases, namespace)[source]¶ Bases:
abc.ABCMetaBase meta-class for all
version.It inherits
abc.ABCMetaand adds a class property format which give the name of theversionformat from the class name.
-
class
plums.model.components.version.Version[source]¶ Bases:
objectAbstract base class for all
Producerversion.Subclasses are expected to override the
__init__(),__str__(),__eq__()and__lt__()magic method to make the version format ‘registerable’ to theversionfactory function.-
format= 'version'¶
-
-
class
plums.model.components.version.PyPA(version)[source]¶ Bases:
plums.model.components.version.VersionA
Producerversion following the standard PyPA versioning scheme.It follows the rules defined in PEP 440 which are grossly similar to Semantic Versioning with a few notable differences and generalisation.
- Parameters
version (str) – A valid PEP 440 version representation string.
-
format= 'py_pa'¶
-
plums.model.components.version.version(format, value)[source]¶ Construct a valid
Versioninstance with the correct format.
-
plums.model.components.version.register(cls, hook=None)[source]¶ Register a
Versionclass to theversionfunction with an optional initialisation hook.
-
class
plums.model.components.version.MetaVersion(name, bases, namespace)[source]¶ Bases:
abc.ABCMetaBase meta-class for all
version.It inherits
abc.ABCMetaand adds a class property format which give the name of theversionformat from the class name.
-
class
plums.model.components.version.Version[source]¶ Bases:
objectAbstract base class for all
Producerversion.Subclasses are expected to override the
__init__(),__str__(),__eq__()and__lt__()magic method to make the version format ‘registerable’ to theversionfactory function.-
format= 'version'¶
-
-
class
plums.model.components.version.PyPA(version)[source]¶ Bases:
plums.model.components.version.VersionA
Producerversion following the standard PyPA versioning scheme.It follows the rules defined in PEP 440 which are grossly similar to Semantic Versioning with a few notable differences and generalisation.
- Parameters
version (str) – A valid PEP 440 version representation string.
-
format= 'py_pa'¶
Utils¶
-
plums.model.components.utils.is_duplicate(file_1, file_2, hash_1=None, hash_2=None, checksum=<function md5_checksum>)[source]¶ Compare two files and return wether their are duplicates.
For efficiency, a first decision is taken based on the two files size.
If it is not enough, their content checksum are used.
- Parameters
file_1 (PathLike) – The first file to compare.
file_2 (PathLike) – The second file to compare.
hash_1 (str) – Optional. Default to
None. If provided, it is used in place of the first file checksum to compare content.hash_2 (str) – Optional. Default to
None. If provided, it is used in place of the second file checksum to compare content.checksum (Callable) – A function which computes a checksum from a
Path.
- Returns
Trueif both files have the same content.- Return type
-
plums.model.components.utils.copy(source, destination, lazy=True, src_hash=None, dst_hash=None, checksum=<function md5_checksum>)[source]¶ Copy file from source to destination.
If
lazyis set toTrueanddestinationexists, the file will be copied if and only if destination is a different file (content-wise) than source.- Parameters
source (PathLike) – The first file to compare.
destination (PathLike) – The second file to compare.
lazy (bool) – Optional. Default to
True. If set toTrue, actual copy performed if destination exists and has a different content than source.src_hash (str) – Optional. Default to
None. If provided, it is used in place of the first file checksum to compare content.dst_hash (str) – Optional. Default to
None. If provided, it is used in place of the second file checksum to compare content.checksum (Callable) – A function which computes a checksum from a
Path.
- Raises
OSError – If something went wrong during copy.
-
plums.model.components.utils.rmtree(path, ignore_errors=False, rm_all=False, black_list=())[source]¶ Partial removal of a filesystem tree from a black list entry point and PMF-trees specific directory entry rules.
For example, to remove a PMF model located at
pathwith a configuration file nameconfiguration, one would use:rmtree(path, black_list=('metadata', configuration))
- Parameters
path (PathLike) – A
Pathto a PMFModelto erase.ignore_errors (bool) – Optional. Default to
False. IfTrue, any error arising when trying to delete or list elements will be silently swallowed.rm_all (bool) – Optional. Default to
False. IfTrue, the entire filesystem tree descending from path will be deleted, independent on whether it looks PMF related.black_list (tuple) – A tuple of filename (with or without extensions) to be deleted from path.
Warning
rm_allis to be used with caution, especially coupled withignore_errorsas it may lead to irreversible and indifferenciated data loss.
-
class
plums.model.components.utils.TrainingStatus(status='pending')[source]¶ Bases:
objectHelper component class to handle
Trainingstatus logic.- Parameters
status (str) – Optional. Default to ‘pending’. An optional initial status.
-
property
status¶ The current
Trainingstatus.The setter checks that the given value is authorized given the current value.
- Raises
ValueError – If the value given to the setter is deemed unauthorized.
- Type
-
class
plums.model.components.utils.Checkpoint(name, path=None, epoch=None, hash=None)[source]¶ Bases:
objectDefine a checkpoint Python representation.
A
Checkpointmight be defined by the following parameters:Note that although the
epochis never needed to strictly define aCheckpoint, it is compulsory to inject it into aCheckpointCollection.- Parameters
name (hashable) – The
Checkpointunique identifier.path (Pathlike) – Optional. default to
None. The path to theCheckpointdata file.epoch (int) – Optional. default to
None. TheCheckpointepoch, if known.hash (str) – Optional. default to
None. TheCheckpointdata file checksum.
-
name¶ The
Checkpointunique identifier.- Type
hashable
-
path¶ The path to the
Checkpointdata file.- Type
Pathlike
-
epoch¶ The
Checkpointepoch, if known.- Type
-
hash¶ The
Checkpointdata file checksum.- Type
-
class
plums.model.components.utils.Mock[source]¶ Bases:
objectMock class which return itself for all attribute access.
-
plums.model.components.utils.is_duplicate(file_1, file_2, hash_1=None, hash_2=None, checksum=<function md5_checksum>)[source]¶ Compare two files and return wether their are duplicates.
For efficiency, a first decision is taken based on the two files size.
If it is not enough, their content checksum are used.
- Parameters
file_1 (PathLike) – The first file to compare.
file_2 (PathLike) – The second file to compare.
hash_1 (str) – Optional. Default to
None. If provided, it is used in place of the first file checksum to compare content.hash_2 (str) – Optional. Default to
None. If provided, it is used in place of the second file checksum to compare content.checksum (Callable) – A function which computes a checksum from a
Path.
- Returns
Trueif both files have the same content.- Return type
-
plums.model.components.utils.copy(source, destination, lazy=True, src_hash=None, dst_hash=None, checksum=<function md5_checksum>)[source]¶ Copy file from source to destination.
If
lazyis set toTrueanddestinationexists, the file will be copied if and only if destination is a different file (content-wise) than source.- Parameters
source (PathLike) – The first file to compare.
destination (PathLike) – The second file to compare.
lazy (bool) – Optional. Default to
True. If set toTrue, actual copy performed if destination exists and has a different content than source.src_hash (str) – Optional. Default to
None. If provided, it is used in place of the first file checksum to compare content.dst_hash (str) – Optional. Default to
None. If provided, it is used in place of the second file checksum to compare content.checksum (Callable) – A function which computes a checksum from a
Path.
- Raises
OSError – If something went wrong during copy.
-
plums.model.components.utils.rmtree(path, ignore_errors=False, rm_all=False, black_list=())[source]¶ Partial removal of a filesystem tree from a black list entry point and PMF-trees specific directory entry rules.
For example, to remove a PMF model located at
pathwith a configuration file nameconfiguration, one would use:rmtree(path, black_list=('metadata', configuration))
- Parameters
path (PathLike) – A
Pathto a PMFModelto erase.ignore_errors (bool) – Optional. Default to
False. IfTrue, any error arising when trying to delete or list elements will be silently swallowed.rm_all (bool) – Optional. Default to
False. IfTrue, the entire filesystem tree descending from path will be deleted, independent on whether it looks PMF related.black_list (tuple) – A tuple of filename (with or without extensions) to be deleted from path.
Warning
rm_allis to be used with caution, especially coupled withignore_errorsas it may lead to irreversible and indifferenciated data loss.
-
class
plums.model.components.utils.TrainingStatus(status='pending')[source]¶ Bases:
objectHelper component class to handle
Trainingstatus logic.- Parameters
status (str) – Optional. Default to ‘pending’. An optional initial status.
-
property
status¶ The current
Trainingstatus.The setter checks that the given value is authorized given the current value.
- Raises
ValueError – If the value given to the setter is deemed unauthorized.
- Type
-
class
plums.model.components.utils.Checkpoint(name, path=None, epoch=None, hash=None)[source]¶ Bases:
objectDefine a checkpoint Python representation.
A
Checkpointmight be defined by the following parameters:Note that although the
epochis never needed to strictly define aCheckpoint, it is compulsory to inject it into aCheckpointCollection.- Parameters
name (hashable) – The
Checkpointunique identifier.path (Pathlike) – Optional. default to
None. The path to theCheckpointdata file.epoch (int) – Optional. default to
None. TheCheckpointepoch, if known.hash (str) – Optional. default to
None. TheCheckpointdata file checksum.
-
name¶ The
Checkpointunique identifier.- Type
hashable
-
path¶ The path to the
Checkpointdata file.- Type
Pathlike
-
epoch¶ The
Checkpointepoch, if known.- Type
-
hash¶ The
Checkpointdata file checksum.- Type