lazyscribe.artifacts package¶
Submodules¶
Base class for new artifact handlers.
- class lazyscribe.artifacts.base.Artifact(name: str, fname: str, value: Any, writer_kwargs: dict, created_at: datetime, version: int, dirty: bool)[source]¶
Bases:
object
Generic artifact handler that defines the expected interface.
Artifact handlers are not meant to be initialized directly.
Parameters¶
- namestr
The name of the artifact.
- fnamestr
The filename of the artifact.
- valueAny
The value for the artifact.
- writer_kwargsdict
User provided keyword arguments for writing an artifact. Provided when the artifact is logged to an experiment.
- versionint
Version of the artifact.
- dirtybool
Whether or not this artifact should be saved when
lazyscribe.project.Project.save()
orlazyscribe.repository.Repository.save()
is called. This decision is based on whether the artifact is new or has been updated.
Attributes¶
- aliasstr
The alias for the artifact handler. This value will be supplied to
lazyscribe.Experiment.log_artifact()
.- suffixstr
The standard suffix for the files written and read by this handler.
- binarybool
Whether or not the file format for the handler is binary in nature. This affects whether or not the file handler uses
w
orwb
.- output_onlybool
Whether or not the file output by the handler is meant to be read as the orginal project.
- namestr
The name of the artifact.
- fnamestr
The filename for the artifact.
- valueobject
The value for the artifact.
- alias: ClassVar[str]¶
- binary: ClassVar[bool]¶
- abstractmethod classmethod construct(name: str, value: Any = None, fname: str | None = None, created_at: datetime | None = None, writer_kwargs: dict | None = None, version: int = 0, dirty: bool = True, **kwargs)[source]¶
Construct the artifact handler.
This method should use environment variables to capture information that is relevant to compatibility between runtime environments.
Parameters¶
- namestr
The name of the artifact.
- valueobject, optional (default None)
The value for the artifact. The default value of
None
is used when an experiment is loaded from the project JSON.- fnamestr, optional (default None)
The filename of the artifact. If not provided, this value will be derived from the name of the artifact and the suffix for the class.
- created_atdatetime, optional (default None)
When the artifact was created. If not supplied,
datetime.now()
will be used.- writer_kwargsdict, optional (default None)
Keyword arguments for writing an artifact to the filesystem. Provided when an artifact is logged to an experiment.
- versionint, optional (default 0)
Integer version to be used for versioning artifacts.
- dirtybool, optional (default True)
Whether or not this artifact should be saved when
lazyscribe.project.Project.save()
orlazyscribe.repository.Repository.save()
is called. This decision is based on whether the artifact is new or has been updated.- **kwargsdict
Other keyword arguments. Usually class attributes obtained from a project JSON.
- created_at: datetime¶
- dirty: bool¶
- fname: str¶
- name: str¶
- output_only: ClassVar[bool]¶
- abstractmethod classmethod read(buf, **kwargs)[source]¶
Read in the artifact.
Parameters¶
- buffile-like object
The buffer from a
fsspec
filesystem.- **kwargsdict
Keyword arguments for the read method.
Returns¶
- Any
The artifact.
- suffix: ClassVar[str]¶
- value: Any¶
- version: int¶
- abstractmethod classmethod write(obj, buf, **kwargs)[source]¶
Write the artifact to the filesystem.
Parameters¶
- objobject
The object to write to the buffer.
- buffile-like object
The buffer from a
fsspec
filesystem.- **kwargsdict
Keyword arguments for the write method.
- writer_kwargs: dict¶
Joblib-based handler for pickle-serializable objects.
- class lazyscribe.artifacts.joblib.JoblibArtifact(name: str, fname: str, value: Any, writer_kwargs: dict, created_at: datetime, version: int, dirty: bool, package: str, package_version: str, joblib_version: str)[source]¶
Bases:
Artifact
Handler for pickle-serializable objects through
joblib
package.Important
joblib
package should be installed to use this handler.This handler will store the
joblib
version and the package (or the root module of thevalue
) name and version as attributes to ensure compatibility between the runtime environment and the artifacts.Important
This class is not meant to be initialized directly. Please use the
construct
method.Parameters¶
- packagestr
The root module name of the python object to be serialized.
- package_versionstr
The installed version of the package pertaining to the python object to be serialized.
- joblib_versionstr
The version of
joblib
installed.
- alias: ClassVar[str] = 'joblib'¶
- binary: ClassVar[bool] = True¶
- classmethod construct(name: str, value: Any = None, fname: str | None = None, created_at: datetime | None = None, writer_kwargs: dict | None = None, version: int = 0, dirty: bool = True, package: str | None = None, **kwargs)[source]¶
Construct the class with the version information.
Parameters¶
- namestr
The name of the artifact.
- valueobject, optional (default None)
The value for the artifact. The default value of
None
is used when an experiment is loaded from the project JSON.- fnamestr, optional (default None)
The filename of the artifact. If not provided, this value will be derived from the name of the artifact and the suffix for the class.
- created_atdatetime, optional (default None)
When the artifact was created. If not supplied,
datetime.now()
will be used.- package: str, optional (default None)
The package name or root module name of the serializable python object. Note: this may be different from the distribution name. e.g
scikit-learn
is a distribution name, where assklearn
is the corresponding package name.- writer_kwargsdict, optional (default None)
Keyword arguments for writing an artifact to the filesystem. Provided when an artifact is logged to an experiment.
- versionint, optional (default 0)
Integer version to be used for versioning artifacts.
- dirtybool, optional (default True)
Whether or not this artifact should be saved when
lazyscribe.project.Project.save()
orlazyscribe.repository.Repository.save()
is called. This decision is based on whether the artifact is new or has been updated.- **kwargsdict
Other keyword arguments. Usually class attributes obtained from a project JSON.
- joblib_version: str¶
- output_only: ClassVar[bool] = False¶
- package: str¶
- package_version: str¶
- classmethod read(buf, **kwargs)[source]¶
Read the python object.
Parameters¶
- buffile-like object
The buffer from the
fsspec
filesystem.- **kwargsdict
Keyword arguments for
joblib.load
.
Returns¶
- Any
The python object.
- suffix: ClassVar[str] = 'joblib'¶
Artifact handler for JSON-serializable objects.
- class lazyscribe.artifacts.json.JSONArtifact(name: str, fname: str, value: Any, writer_kwargs: dict, created_at: datetime, version: int, dirty: bool, python_version: str)[source]¶
Bases:
Artifact
Handler for JSON-serializable objects.
Important
This class is not meant to be initialized directly. Please use the
construct
method.- alias: ClassVar[str] = 'json'¶
- binary: ClassVar[bool] = False¶
- classmethod construct(name: str, value: Any = None, fname: str | None = None, created_at: datetime | None = None, writer_kwargs: dict | None = None, version: int = 0, dirty: bool = True, **kwargs)[source]¶
Construct the handler class.
Parameters¶
- namestr
The name of the artifact.
- valueobject, optional (default None)
The value for the artifact. The default value of
None
is used when an experiment is loaded from the project JSON.- fnamestr, optional (default None)
The filename of the artifact. If not provided, this value will be derived from the name of the artifact and the suffix for the class.
- created_atdatetime, optional (default None)
When the artifact was created. If not supplied,
datetime.now()
will be used.- writer_kwargsdict, optional (default None)
Keyword arguments for writing an artifact to the filesystem. Provided when an artifact is logged to an experiment.
- versionint, optional (default 0)
Integer version to be used for versioning artifacts.
- dirtybool, optional (default True)
Whether or not this artifact should be saved when
lazyscribe.project.Project.save()
orlazyscribe.repository.Repository.save()
is called. This decision is based on whether the artifact is new or has been updated.- **kwargsdict
Other keyword arguments. Usually class attributes obtained from a project JSON.
- output_only: ClassVar[bool] = False¶
- python_version: str¶
- classmethod read(buf, **kwargs)[source]¶
Read in the JSON file.
Parameters¶
- buffile-like object
The buffer from a
fsspec
filesystem.- **kwargsdict
Keyword arguments for
json.load()
Returns¶
- Any
The deserialized JSON file.
- suffix: ClassVar[str] = 'json'¶
PyYAML-based handler for YAML-serializable artifacts.
- class lazyscribe.artifacts.yaml.YAMLArtifact(name: str, fname: str, value: Any, writer_kwargs: dict, created_at: datetime, version: int, dirty: bool)[source]¶
Bases:
Artifact
Handler for YAML artifacts.
- alias: ClassVar[str] = 'yaml'¶
- binary: ClassVar[bool] = False¶
- classmethod construct(name: str, value: Any = None, fname: str | None = None, created_at: datetime | None = None, writer_kwargs: dict | None = None, version: int = 0, dirty: bool = True, **kwargs)[source]¶
Construct the handler class.
- output_only: ClassVar[bool] = False¶
- classmethod read(buf, **kwargs)[source]¶
Read in the artifact.
Parameters¶
- buffile-like object
The buffer from a
fsspec
filesystem.- **kwargs
Keyword arguments for the read method.
Returns¶
- Any
The artifact.
- suffix: ClassVar[str] = 'yaml'¶
Module contents¶
Import the handlers.