Specs
Спецификации параметров для экспорта и сериализации
from svetlanna.specs import ...Классы
ParameterSaveContext
Generates different context managers that can be used to write a parameter data to output stream or file.
Методы
__init__ constructor
__init__(self, parameter_name: str, directory: Path)📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
parameter_name | str | the human-readable name for the parameter |
directory | str | the directory where the generated file will be saved, if any |
stream | TextIO | stream where the generated text will be written, if any |
get_new_filepath
get_new_filepath(self, extension: str) -> PathCreate a new filepath for a specific extension.
The generated filename of a specific extension will have a unique name
ending with _<n>.<extension>, where <n> is auto-incrementing index.
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
extension | str | filename extension |
📤 Возвращает
Path
relative path to the file
rel_filepath
rel_filepath(self, filepath: Path) -> PathGet relative to specs file filepath
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
filepath | Path | absolute path |
📤 Возвращает
Path
relative path
file
file(self, filepath: Path) -> Generator[BufferedWriter, Any, None]Context manager for the output file
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
filepath | Path | filepath |
Yields
- Generator[BufferedWriter, Any, None] — Buffer
Representation
Наследует:Generic[ParameterSaveContext_]
Base class for a parameter representation
MarkdownRepresentation
Наследует:Representation[ParameterSaveContext_]
Representation that can be exported to markdown file
Методы
to_markdown
to_markdown(self, out: TextIO, context: ParameterSaveContext_) -> NoneWrite the parameter related data to be shown in a markdown file.
The text should be written to the out stream.
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
out | TextIO | output text stream |
context | ParameterSaveContext_ | the parameter save context |
StrRepresentation
Наследует:Representation[ParameterSaveContext_]
Representation that can be exported in the text format
Методы
to_str
to_str(self, out: TextIO, context: ParameterSaveContext_) -> NoneWrite the parameter related data to be shown as a plain text.
The text should be written to the out stream.
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
out | TextIO | output text stream |
context | ParameterSaveContext_ | the parameter save context |
HTMLRepresentation
Наследует:Representation[ParameterSaveContext_]
Representation that can be exported to the HTML
Методы
to_html
to_html(self, out: TextIO, context: ParameterSaveContext_) -> NoneWrite the parameter related data to be shown in a HTML file.
The text should be written to the out stream.
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
out | TextIO | output text stream |
context | ParameterSaveContext_ | the parameter save context |
ImageRepr
Наследует:StrRepresentation MarkdownRepresentation HTMLRepresentation
Representation of the parameter as an image.
Image generation is based on the pillow package.
Методы
__init__ constructor
__init__(self, value: Any, mode: Literal['1', 'L', 'LA', 'I', 'P', 'RGB', 'RGBA'] = 'L', format: str = 'png', show_image: bool = True)📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
value | Any | The image data. See matplotlib.pyplot.imshow docs. |
mode | Literal['1', 'L', 'LA', 'I', 'P', 'RGB', 'RGBA'], optional | the mode of the image, see https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes . By default L |
format | str, optional | the image format, by default ‘png’ |
draw_image
draw_image(self, context: ParameterSaveContext, filepath: Path) -> Image.ImageDraw image into the file, using pillow package.
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
context | ParameterSaveContext | the parameter save context |
filepath | Path | path to the image file to be created |
to_str
to_str(self, out: TextIO, context: ParameterSaveContext)to_markdown
to_markdown(self, out: TextIO, context: ParameterSaveContext)to_html
to_html(self, out: TextIO, context: ParameterSaveContext)ReprRepr
Наследует:StrRepresentation MarkdownRepresentation HTMLRepresentation
Representation of the parameter as a plain text.
The __repr__ method is used to generate the text.
Методы
__init__ constructor
__init__(self, value: Any)📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
value | Any | object with defined __repr__ method that will be used to generate plain text. |
to_str
to_str(self, out: TextIO, context: ParameterSaveContext)to_markdown
to_markdown(self, out: TextIO, context: ParameterSaveContext)to_html
to_html(self, out: TextIO, context: Any)NpyFileRepr
Наследует:StrRepresentation MarkdownRepresentation
Representation of the parameter as a .npy file.
Методы
__init__ constructor
__init__(self, value: ArrayLike)📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
value | ArrayLike | parameter data. |
save_to_file
save_to_file(self, context: ParameterSaveContext, filepath: Path)Save the parameter related data to npy file.
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
context | ParameterSaveContext | the parameter save context |
filepath | Path | path to the file to be created |
to_str
to_str(self, out: TextIO, context: ParameterSaveContext)to_markdown
to_markdown(self, out: TextIO, context: ParameterSaveContext)PrettyReprRepr
Наследует:ReprRepr HTMLRepresentation
Same as ReprRepr but with better handling of Parameters and BoundedParameter
Методы
__init__ constructor
__init__(self, value: Any, units: str | None = None)Representation of the parameter as a plain text.
The __repr__ method is used to generate the
text if the value is not torch.Tensor or Parameter.
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
value | Any | object to generate plain text of. |
units | `str | None, optional` |
to_str
to_str(self, out: TextIO, context: ParameterSaveContext)to_markdown
to_markdown(self, out: TextIO, context: ParameterSaveContext)to_html
to_html(self, out: TextIO, context: ParameterSaveContext)ParameterSpecs
Container with all representations for the parameter.
Методы
__init__ constructor
__init__(self, parameter_name: str, representations: Iterable[Representation]) -> None📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
name | str | the parameter’s name. |
representations | Iterable[ParameterRepr] | all representations of the parameter. |
SubelementSpecs
Container for named subelement
Методы
__init__ constructor
__init__(self, subelement_type: str, subelement: 'Specsable')📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
subelement_type | str | human-readable type of the subelement. |
subelement | Specsable | the subelement. |
Specsable
Наследует:Protocol
Represents any specsable object
Методы
to_specs
to_specs(self) -> Iterable[ParameterSpecs | SubelementSpecs]_IndexedObject
Наследует:Generic[_T]
_WriterContext
Storage for additional info within ParameterSaveContext
_ElementInTree
Методы
create_copy
create_copy(self, subelement_type: str | None) -> '_ElementInTree'_ElementsIterator
Свойства
treeGet a tree of all elements iterated
Методы
__init__ constructor
__init__(self, *iterables: Specsable) -> NoneФункции
context_generator(element: Specsable, element_index: int, directory: str | Path, subelements: list[SubelementSpecs]) -> _WriterContextGenerator
Generate _WriterContext for the element
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
element | Specsable | Element |
element_index | int | Index of the element. It is used to create unique directory for element specs. |
directory | `str | Path` |
Yields
- _WriterContext — context