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, version: int, dirty: bool)[source]

Bases: object

Generic 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 w or wb. (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() or lazyscribe.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, 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 None or 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.

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() or lazyscribe.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
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 fsspec filesystem.

**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 fsspec filesystem.

**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, 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.

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, 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 None is used when an experiment is loaded from the project JSON.

fnamestr, optional (default None)

The filename for the artifact. If set to None or 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.

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() or lazyscribe.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 JSON file.

Parameters

buffile-like object

The buffer from a fsspec filesystem.

**kwargs

Keyword arguments for json.load()

Returns

Any

The deserialized JSON file.

suffix: ClassVar[str] = 'json'
classmethod write(obj: Any, buf: IOBase, **kwargs: Any) None[source]

Write the content to a JSON file.

Parameters

objobject

The JSON-serializable object.

buffile-like object

The buffer from a fsspec filesystem.

**kwargs

Keyword arguments for json.dump().

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, version: int, dirty: bool, python_version: str)[source]

Bases: Artifact

Pickle-based serialization for python objects.

Important

This class is not meant to be initialized directly. Please use the construct method.

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, 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 None is used when an experiment is loaded from the project JSON.

fnamestr, optional (default None)

The filename for the artifact. If set to None or 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.

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() or lazyscribe.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 fsspec filesystem.

**kwargs

Keyword arguments for pickle.load().

Returns

Any

The deserialized Python object.

suffix: ClassVar[str] = 'pkl'
classmethod write(obj: Any, buf: IOBase, **kwargs: Any) None[source]

Write the content to a pickle file.

Parameters

objobject

The serializable object.

buffile-like object

The buffer from a fsspec filesystem.

**kwargs

Keyword arguments for pickle.dump().

Module contents

Import the handlers.