lazyscribe.artifacts package#
Submodules#
Base class for new artifact handlers.
- class lazyscribe.artifacts.base.Artifact(name: str, fname: str, value: Any, writer_kwargs: dict[str, Any], created_at: datetime, expiry: datetime | None, version: int, dirty: bool)[source]#
Bases:
objectGeneric artifact handler that defines the expected interface.
Artifact handlers are not meant to be initialized directly.
Attributes#
- aliasstr
The alias for the artifact handler. This value will be supplied to
lazyscribe.experiment.Experiment.log_artifact(). (A class attribute.)- suffixstr
The standard suffix for the files written and read by this handler. (A class attribute.)
- binarybool
Whether or not the file format for the handler is binary in nature. This affects whether or not the file handler uses
worwb. (A class attribute.)- output_onlybool
Whether or not the file output by the handler is meant to be read as the orginal project. (A class attribute.)
- 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.
- alias: ClassVar[str]#
- binary: ClassVar[bool]#
- abstractmethod classmethod construct(name: str, value: Any = None, fname: str | None = None, created_at: datetime | None = None, expiry: datetime | None = None, writer_kwargs: dict[str, Any] | None = None, version: int = 0, dirty: bool = True, **kwargs: Any) Artifact[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.
- valueAny, optional (default None)
The value for the artifact.
- fnamestr, optional (default None)
The filename for the artifact. If set to
Noneor not provided, it will be derived from the name of the artifact and the suffix for the class.- created_atdatetime.datetime, optional (default
lazyscribe._utils.utcnow()) When the artifact was created.
- expirydatetime.datetime, optional (default None)
When the artifact expired.
- writer_kwargsdict, optional (default {})
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.- **kwargs
Other keyword arguments.
Returns#
- Artifact
The artifact.
- created_at: datetime#
- dirty: bool#
- expiry: datetime | None#
- fname: str#
- name: str#
- output_only: ClassVar[bool]#
- abstractmethod classmethod read(buf: IOBase, **kwargs: Any) Any[source]#
Read in the artifact.
Parameters#
- buffile-like object
The buffer from a
fsspecfilesystem.- **kwargs
Keyword arguments for the read method.
Returns#
- Any
The artifact object.
- suffix: ClassVar[str]#
- value: Any#
- version: int#
- abstractmethod classmethod write(obj: Any, buf: IOBase, **kwargs: Any) None[source]#
Write the artifact to the filesystem.
Parameters#
- objAny
The object to write to the buffer.
- buffile-like object
The buffer from a
fsspecfilesystem.- **kwargs
Keyword arguments for the write method.
- writer_kwargs: dict[str, Any]#
Artifact handler for JSON-serializable objects.
- class lazyscribe.artifacts.json.JSONArtifact(name: str, fname: str, value: Any, writer_kwargs: dict[str, Any], created_at: datetime, expiry: datetime | None, version: int, dirty: bool)[source]#
Bases:
ArtifactHandler for JSON-serializable objects.
Important
This class is not meant to be initialized directly. Please use the
constructmethod.Note
For the attributes documentation, see also “Attributes” of
lazyscribe.artifacts.base.Artifact.Attributes#
alias : str = “json” suffix : str = “json” binary : bool = False output_only : bool = False
- python_versionstr
Minor Python version (e.g.
"3.10").
- alias: ClassVar[str] = 'json'#
- binary: ClassVar[bool] = False#
- classmethod construct(name: str, value: Any = None, fname: str | None = None, created_at: datetime | None = None, expiry: datetime | None = None, writer_kwargs: dict[str, Any] | None = None, version: int = 0, dirty: bool = True, **kwargs: Any) JSONArtifact[source]#
Construct the handler class.
Parameters#
- namestr
The name of the artifact.
- valueAny, optional (default None)
The value for the artifact. The default value of
Noneis used when an experiment is loaded from the project JSON.- fnamestr, optional (default None)
The filename for the artifact. If set to
Noneor not provided, it will be derived from the name of the artifact and the suffix for the class.- created_atdatetime.datetime, optional (default
lazyscribe._utils.utcnow()) When the artifact was created.
- expirydatetime.datetime, optional (default None)
When the artifact expired.
- writer_kwargsdict[str, Any], optional (default {})
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.
Returns#
- JSONArtifact
The artifact.
- output_only: ClassVar[bool] = False#
- classmethod read(buf: IOBase, **kwargs: Any) Any[source]#
Read in the JSON file.
Parameters#
- buffile-like object
The buffer from a
fsspecfilesystem.- **kwargs
Keyword arguments for
json.load()
Returns#
- Any
The deserialized JSON file.
- suffix: ClassVar[str] = 'json'#
Pickle-based handler for binary artifacts.
- class lazyscribe.artifacts.pickle.PickleArtifact(name: str, fname: str, value: Any, writer_kwargs: dict[str, Any], created_at: datetime, expiry: datetime | None, version: int, dirty: bool, python_version: str)[source]#
Bases:
ArtifactPickle-based serialization for python objects.
Important
This class is not meant to be initialized directly. Please use the
constructmethod.Note
For the attributes documentation, please see the “Attributes” section of
lazyscribe.artifacts.base.Artifact.Attributes#
alias : str = “pickle” suffix : str = “pkl” binary : bool = False output_only : bool = False
- python_versionstr
Minor Python version (e.g.
"3.10").
- alias: ClassVar[str] = 'pickle'#
- binary: ClassVar[bool] = True#
- classmethod construct(name: str, value: Any = None, fname: str | None = None, created_at: datetime | None = None, expiry: datetime | None = None, writer_kwargs: dict[str, Any] | None = None, version: int = 0, dirty: bool = True, **kwargs: Any) PickleArtifact[source]#
Construct the handler class.
Parameters#
- namestr
The name of the artifact.
- valueAny, optional (default None)
The value for the artifact. The default value of
Noneis used when an experiment is loaded from the project JSON.- fnamestr, optional (default None)
The filename for the artifact. If set to
Noneor not provided, it will be derived from the name of the artifact and the suffix for the class.- created_atdatetime.datetime, optional (default
lazyscribe._utils.utcnow()) When the artifact was created.
- expirydatetime.datetime, optional (default None)
When the artifact expired.
- writer_kwargsdict[str, Any], optional (default {})
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.- python_versionstr, optional
Minor Python version (e.g.
"3.10").
Returns#
- JSONArtifact
The artifact.
- output_only: ClassVar[bool] = False#
- python_version: str#
- classmethod read(buf: IOBase, **kwargs: Any) Any[source]#
Read in the file.
Parameters#
- buffile-like object
The buffer from a
fsspecfilesystem.- **kwargs
Keyword arguments for
pickle.load().
Returns#
- Any
The deserialized Python object.
- suffix: ClassVar[str] = 'pkl'#
Module contents#
Import the handlers.