Skip to content

mkit.utils

Live

enable class-attribute instance-attribute

enable: bool = enable

records instance-attribute

records: dict[int, dict[str, Any]] = defaultdict(dict)

step property writable

step: int

__enter__

__enter__() -> Self

__exit__

__exit__(exc_type, exc_val, exc_tb) -> None

__init__

__init__(
    *,
    cache_images: bool = False,
    dir: str = "dvclive",
    dvcyaml: str | None = "dvc.yaml",
    enable: bool = True,
    exp_message: str | None = None,
    exp_name: str | None = None,
    monitor_system: bool = False,
    report: Literal["md", "notebook", "html", None] = None,
    resume: bool = False,
    save_dvc_exp: bool = True
) -> None

end

end() -> None

log_array

log_array(name: str, array: ArrayLike) -> None

log_metric

log_metric(
    name: str,
    val: Any,
    *,
    timestamp: bool = False,
    plot: bool = True
) -> None

next_step

next_step(*, milestone: bool = True) -> None

flatten

flatten(
    iterable: _T | Iterable[_T | Iterable],
    base_type: tuple[type, ...] = (str, type),
) -> Iterable[_T]

is_subsequence

is_subsequence(a: Sequence[Any], b: Sequence[Any]) -> bool

kwargs_to_positional

kwargs_to_positional(
    func: Callable[_P, _T]
) -> Callable[_P, _T]

Convert **kwargs arguments to positional.

Reference
  1. https://stackoverflow.com/a/49836730/18410348

load

load(
    fpath: StrPath, ext: str | None = None, **kwargs
) -> Any

load_json

load_json(fpath: StrPath, **kwargs) -> Any

load_pydantic

load_pydantic(
    cls: type[_C],
    fpath: StrPath,
    ext: str | None = None,
    **kwargs
) -> _C

load_toml

load_toml(fpath: StrPath) -> TOMLDocument

load_yaml

load_yaml(fpath: StrPath) -> Any

merge_mapping

merge_mapping(origin: Mapping, update: Mapping) -> dict

save

save(
    data: Any,
    fpath: StrPath,
    ext: str | None = None,
    **kwargs
) -> None

save_json

save_json(data: Any, fpath: StrPath, **kwargs) -> None

save_pydantic

save_pydantic(
    data: BaseModel,
    fpath: StrPath,
    ext: str | None = None,
    **kwargs
) -> None

save_toml

save_toml(
    data: Any, fpath: StrPath, *, sort_keys: bool = False
) -> None

save_yaml

save_yaml(data: Any, fpath: StrPath) -> None

strip_comments

strip_comments(
    text: str, comments: str = "#"
) -> Generator[str, None, None]