mllogs 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mllogs-0.1.3/LICENSE +21 -0
- mllogs-0.1.3/PKG-INFO +66 -0
- mllogs-0.1.3/README.md +53 -0
- mllogs-0.1.3/pyproject.toml +23 -0
- mllogs-0.1.3/setup.cfg +4 -0
- mllogs-0.1.3/src/mllogs/__init__.py +0 -0
- mllogs-0.1.3/src/mllogs/client.py +59 -0
- mllogs-0.1.3/src/mllogs/run.py +88 -0
- mllogs-0.1.3/src/mllogs/storage.py +72 -0
- mllogs-0.1.3/src/mllogs.egg-info/PKG-INFO +66 -0
- mllogs-0.1.3/src/mllogs.egg-info/SOURCES.txt +15 -0
- mllogs-0.1.3/src/mllogs.egg-info/dependency_links.txt +1 -0
- mllogs-0.1.3/src/mllogs.egg-info/requires.txt +3 -0
- mllogs-0.1.3/src/mllogs.egg-info/top_level.txt +1 -0
- mllogs-0.1.3/tests/test_client.py +57 -0
- mllogs-0.1.3/tests/test_run.py +69 -0
- mllogs-0.1.3/tests/test_storage.py +66 -0
mllogs-0.1.3/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Finn Walsh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mllogs-0.1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mllogs
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Local experiment logging for machine learning
|
|
5
|
+
Author: Finn Walsh
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# mllogs
|
|
15
|
+
|
|
16
|
+
Local experiment logging for machine learning.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install mllogs
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from mllogs import MLLogsClient
|
|
28
|
+
|
|
29
|
+
client = MLLogsClient()
|
|
30
|
+
|
|
31
|
+
client.start_run(
|
|
32
|
+
name="baseline",
|
|
33
|
+
run_type="training",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
client.log_param("learning_rate", 0.01)
|
|
37
|
+
client.log_metric("accuracy", 0.92)
|
|
38
|
+
client.set_tag("model", "logistic_regression")
|
|
39
|
+
|
|
40
|
+
client.end_run()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- Start and end experiment runs
|
|
46
|
+
- Log parameters, metrics, and tags
|
|
47
|
+
- Save runs to local storage
|
|
48
|
+
- Load, list, and delete saved runs
|
|
49
|
+
|
|
50
|
+
## Development
|
|
51
|
+
|
|
52
|
+
Install from source with development dependencies:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install -e ".[dev]"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Run the test suite:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pytest
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT
|
mllogs-0.1.3/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# mllogs
|
|
2
|
+
|
|
3
|
+
Local experiment logging for machine learning.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install mllogs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from mllogs import MLLogsClient
|
|
15
|
+
|
|
16
|
+
client = MLLogsClient()
|
|
17
|
+
|
|
18
|
+
client.start_run(
|
|
19
|
+
name="baseline",
|
|
20
|
+
run_type="training",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
client.log_param("learning_rate", 0.01)
|
|
24
|
+
client.log_metric("accuracy", 0.92)
|
|
25
|
+
client.set_tag("model", "logistic_regression")
|
|
26
|
+
|
|
27
|
+
client.end_run()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- Start and end experiment runs
|
|
33
|
+
- Log parameters, metrics, and tags
|
|
34
|
+
- Save runs to local storage
|
|
35
|
+
- Load, list, and delete saved runs
|
|
36
|
+
|
|
37
|
+
## Development
|
|
38
|
+
|
|
39
|
+
Install from source with development dependencies:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -e ".[dev]"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Run the test suite:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pytest
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[tool.setuptools.packages.find]
|
|
6
|
+
where = ["src"]
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "mllogs"
|
|
10
|
+
version = "0.1.3"
|
|
11
|
+
description = "Local experiment logging for machine learning"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.11"
|
|
14
|
+
license = "MIT"
|
|
15
|
+
authors = [
|
|
16
|
+
{ name = "Finn Walsh" }
|
|
17
|
+
]
|
|
18
|
+
dependencies = []
|
|
19
|
+
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
dev = [
|
|
22
|
+
"pytest>=8.0",
|
|
23
|
+
]
|
mllogs-0.1.3/setup.cfg
ADDED
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
from datetime import datetime, UTC
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
|
|
5
|
+
from .run import Run, RunStatus
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MLLogsClient:
|
|
9
|
+
def __init__(self):
|
|
10
|
+
self._active_run: Run | None = None
|
|
11
|
+
|
|
12
|
+
def start_run(
|
|
13
|
+
self,
|
|
14
|
+
name: str | None = None,
|
|
15
|
+
run_type: str | None = None,
|
|
16
|
+
) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Start a new MLLogs run.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
name: Optional name for the run.
|
|
22
|
+
run_type: Optional type used to categorize the run.
|
|
23
|
+
"""
|
|
24
|
+
# generate run id
|
|
25
|
+
started_at = datetime.now(UTC)
|
|
26
|
+
timestamp = started_at.strftime("%Y%m%d%H%M%S")
|
|
27
|
+
random_suffix = uuid4().hex[:8]
|
|
28
|
+
run_id = f"{timestamp}-{random_suffix}"
|
|
29
|
+
|
|
30
|
+
self._active_run = Run(
|
|
31
|
+
id=run_id,
|
|
32
|
+
name=name,
|
|
33
|
+
run_type=run_type,
|
|
34
|
+
status = RunStatus.RUNNING,
|
|
35
|
+
started_at=started_at,
|
|
36
|
+
)
|
|
37
|
+
# END
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def log_param(self, key: str, value: Any) -> None:
|
|
41
|
+
self._active_run.params[key] = value
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def log_metric(self, key: str, value: float) -> None:
|
|
45
|
+
self._active_run.metrics[key] = value
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def set_tag(self, key: str, value: str) -> None:
|
|
49
|
+
self._active_run.tags[key] = value
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def end_run(self) -> None:
|
|
53
|
+
self._active_run.ended_at = datetime.now(UTC)
|
|
54
|
+
|
|
55
|
+
self._active_run.status = RunStatus.COMPLETE
|
|
56
|
+
|
|
57
|
+
# clear run
|
|
58
|
+
self._active_run = None
|
|
59
|
+
# END
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import Any
|
|
4
|
+
from enum import Enum
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class RunStatus(Enum):
|
|
8
|
+
RUNNING = "running"
|
|
9
|
+
COMPLETE = "complete"
|
|
10
|
+
FAILED = "failed"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class Artifact:
|
|
15
|
+
name: str
|
|
16
|
+
uri: str
|
|
17
|
+
artifact_type: str
|
|
18
|
+
|
|
19
|
+
def to_dict(self) -> dict[str, str]:
|
|
20
|
+
return {
|
|
21
|
+
"name": self.name,
|
|
22
|
+
"uri": self.uri,
|
|
23
|
+
"artifact_type": self.artifact_type,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@classmethod
|
|
28
|
+
def from_dict(cls, d: dict[str, str]) -> "Artifact":
|
|
29
|
+
return cls(
|
|
30
|
+
name = d["name"],
|
|
31
|
+
uri = d["uri"],
|
|
32
|
+
artifact_type = d["artifact_type"],
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class Run:
|
|
38
|
+
id: str
|
|
39
|
+
started_at: datetime
|
|
40
|
+
status: RunStatus
|
|
41
|
+
|
|
42
|
+
name: str | None = None
|
|
43
|
+
run_type: str | None = None
|
|
44
|
+
ended_at: datetime | None = None
|
|
45
|
+
|
|
46
|
+
params: dict[str, Any] = field(default_factory=dict)
|
|
47
|
+
metrics: dict[str, float] = field(default_factory=dict)
|
|
48
|
+
tags: dict[str, str] = field(default_factory=dict)
|
|
49
|
+
artifacts: list[Artifact] = field(default_factory=list)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def to_dict(self) -> dict[str, Any]:
|
|
53
|
+
return {
|
|
54
|
+
"id": self.id,
|
|
55
|
+
"started_at": self.started_at.isoformat(),
|
|
56
|
+
"status": self.status.value,
|
|
57
|
+
"name": self.name,
|
|
58
|
+
"run_type": self.run_type,
|
|
59
|
+
"ended_at": (
|
|
60
|
+
self.ended_at.isoformat()
|
|
61
|
+
if self.ended_at is not None
|
|
62
|
+
else None
|
|
63
|
+
),
|
|
64
|
+
"params": self.params,
|
|
65
|
+
"metrics": self.metrics,
|
|
66
|
+
"tags": self.tags,
|
|
67
|
+
"artifacts": [a.to_dict() for a in self.artifacts],
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def from_dict(cls, d: dict[str, Any]) -> "Run":
|
|
73
|
+
return cls(
|
|
74
|
+
id = d["id"],
|
|
75
|
+
started_at = datetime.fromisoformat(d["started_at"]),
|
|
76
|
+
status = RunStatus(d["status"]),
|
|
77
|
+
name = d["name"],
|
|
78
|
+
run_type = d["run_type"],
|
|
79
|
+
ended_at = (
|
|
80
|
+
datetime.fromisoformat(d["ended_at"])
|
|
81
|
+
if d["ended_at"] is not None
|
|
82
|
+
else None
|
|
83
|
+
),
|
|
84
|
+
params = d["params"],
|
|
85
|
+
metrics = d["metrics"],
|
|
86
|
+
tags = d["tags"],
|
|
87
|
+
artifacts = [Artifact.from_dict(a) for a in d["artifacts"]],
|
|
88
|
+
)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
from .run import Run
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class LocalFileStore:
|
|
8
|
+
def __init__(self, root_dir: str | Path = ".mllogs") -> None:
|
|
9
|
+
"""
|
|
10
|
+
Initializes LocalFileStore and creates runs directory if it
|
|
11
|
+
does not already exist.
|
|
12
|
+
"""
|
|
13
|
+
self._root_dir = Path(root_dir)
|
|
14
|
+
self._runs_dir = self._root_dir / "runs"
|
|
15
|
+
|
|
16
|
+
self._runs_dir.mkdir(parents=True, exist_ok=True)
|
|
17
|
+
|
|
18
|
+
def save_run(self, run: Run) -> None:
|
|
19
|
+
"""
|
|
20
|
+
Writes Run to storage as JSON file.
|
|
21
|
+
"""
|
|
22
|
+
path = self._runs_dir / f"{run.id}.json"
|
|
23
|
+
|
|
24
|
+
with path.open("w") as f:
|
|
25
|
+
json.dump(run.to_dict(), f, indent=4)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def load_run(self, run_id: str) -> Run:
|
|
29
|
+
"""
|
|
30
|
+
Reads JSON run file from storage and returns a Run.
|
|
31
|
+
"""
|
|
32
|
+
path = self._runs_dir / f"{run_id}.json"
|
|
33
|
+
|
|
34
|
+
with path.open("r") as f:
|
|
35
|
+
run_dict = json.load(f)
|
|
36
|
+
|
|
37
|
+
return Run.from_dict(run_dict)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def list_runs(self, limit: int | None = None) -> list[Run]:
|
|
41
|
+
"""
|
|
42
|
+
Returns the most recent runs.
|
|
43
|
+
|
|
44
|
+
If limit is None, returns all runs.
|
|
45
|
+
"""
|
|
46
|
+
if limit is not None and limit <= 0:
|
|
47
|
+
raise ValueError("limit must be greater than 0")
|
|
48
|
+
|
|
49
|
+
paths = sorted(
|
|
50
|
+
self._runs_dir.glob("*.json"),
|
|
51
|
+
reverse=True, # latest first
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
if limit is not None:
|
|
55
|
+
paths = paths[:limit]
|
|
56
|
+
|
|
57
|
+
runs = []
|
|
58
|
+
|
|
59
|
+
for path in paths:
|
|
60
|
+
run = self.load_run(path.stem)
|
|
61
|
+
runs.append(run)
|
|
62
|
+
|
|
63
|
+
return runs
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def delete_run(self, run_id: str) -> None:
|
|
67
|
+
"""
|
|
68
|
+
Deletes a run from storage by run ID.
|
|
69
|
+
"""
|
|
70
|
+
path = self._runs_dir / f"{run_id}.json"
|
|
71
|
+
|
|
72
|
+
path.unlink()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mllogs
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Local experiment logging for machine learning
|
|
5
|
+
Author: Finn Walsh
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# mllogs
|
|
15
|
+
|
|
16
|
+
Local experiment logging for machine learning.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install mllogs
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from mllogs import MLLogsClient
|
|
28
|
+
|
|
29
|
+
client = MLLogsClient()
|
|
30
|
+
|
|
31
|
+
client.start_run(
|
|
32
|
+
name="baseline",
|
|
33
|
+
run_type="training",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
client.log_param("learning_rate", 0.01)
|
|
37
|
+
client.log_metric("accuracy", 0.92)
|
|
38
|
+
client.set_tag("model", "logistic_regression")
|
|
39
|
+
|
|
40
|
+
client.end_run()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- Start and end experiment runs
|
|
46
|
+
- Log parameters, metrics, and tags
|
|
47
|
+
- Save runs to local storage
|
|
48
|
+
- Load, list, and delete saved runs
|
|
49
|
+
|
|
50
|
+
## Development
|
|
51
|
+
|
|
52
|
+
Install from source with development dependencies:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install -e ".[dev]"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Run the test suite:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pytest
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/mllogs/__init__.py
|
|
5
|
+
src/mllogs/client.py
|
|
6
|
+
src/mllogs/run.py
|
|
7
|
+
src/mllogs/storage.py
|
|
8
|
+
src/mllogs.egg-info/PKG-INFO
|
|
9
|
+
src/mllogs.egg-info/SOURCES.txt
|
|
10
|
+
src/mllogs.egg-info/dependency_links.txt
|
|
11
|
+
src/mllogs.egg-info/requires.txt
|
|
12
|
+
src/mllogs.egg-info/top_level.txt
|
|
13
|
+
tests/test_client.py
|
|
14
|
+
tests/test_run.py
|
|
15
|
+
tests/test_storage.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mllogs
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from mllogs.run import RunStatus
|
|
2
|
+
from mllogs.client import MLLogsClient
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_start_run() -> None:
|
|
6
|
+
client = MLLogsClient()
|
|
7
|
+
client.start_run(
|
|
8
|
+
name="run1",
|
|
9
|
+
run_type="training",
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
run = client._active_run
|
|
13
|
+
|
|
14
|
+
# assert active run is generated
|
|
15
|
+
assert run is not None
|
|
16
|
+
|
|
17
|
+
# assert necessary fields are generated / populated
|
|
18
|
+
assert run.started_at is not None
|
|
19
|
+
assert run.id is not None
|
|
20
|
+
assert run.status == RunStatus.RUNNING
|
|
21
|
+
|
|
22
|
+
# assert passed parameters populate designated fields
|
|
23
|
+
assert run.name == "run1"
|
|
24
|
+
assert run.run_type == "training"
|
|
25
|
+
|
|
26
|
+
# assert no additional fields are populated
|
|
27
|
+
assert run.ended_at is None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_end_run() -> None:
|
|
31
|
+
client = MLLogsClient()
|
|
32
|
+
|
|
33
|
+
client.start_run()
|
|
34
|
+
client.end_run()
|
|
35
|
+
|
|
36
|
+
assert client._active_run is None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_mutate_params() -> None:
|
|
40
|
+
client = MLLogsClient()
|
|
41
|
+
|
|
42
|
+
client.start_run()
|
|
43
|
+
|
|
44
|
+
# log param
|
|
45
|
+
client.log_param("alpha", 0.1)
|
|
46
|
+
assert "alpha" in client._active_run.params.keys()
|
|
47
|
+
assert client._active_run.params["alpha"] == 0.1
|
|
48
|
+
|
|
49
|
+
# log metric
|
|
50
|
+
client.log_metric("RMSE", 0.01)
|
|
51
|
+
assert "RMSE" in client._active_run.metrics.keys()
|
|
52
|
+
assert client._active_run.metrics["RMSE"] == 0.01
|
|
53
|
+
|
|
54
|
+
# set tag
|
|
55
|
+
client.set_tag("ml_model", "ridge")
|
|
56
|
+
assert "ml_model" in client._active_run.tags.keys()
|
|
57
|
+
assert client._active_run.tags["ml_model"] == "ridge"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from datetime import datetime, UTC
|
|
2
|
+
|
|
3
|
+
from mllogs.run import Run, RunStatus
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_run_defaults():
|
|
7
|
+
started_at = datetime(2000, 1, 1, 0, 0, tzinfo=UTC)
|
|
8
|
+
run = Run(
|
|
9
|
+
id="run-123",
|
|
10
|
+
status=RunStatus.RUNNING,
|
|
11
|
+
started_at=started_at,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
assert run.name is None
|
|
15
|
+
assert run.run_type is None
|
|
16
|
+
assert run.ended_at is None
|
|
17
|
+
assert run.params == {}
|
|
18
|
+
assert run.metrics == {}
|
|
19
|
+
assert run.tags == {}
|
|
20
|
+
assert run.artifacts == []
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_to_dict():
|
|
24
|
+
started_at = datetime(2000, 1, 1, 0, 0, tzinfo=UTC)
|
|
25
|
+
run = Run(
|
|
26
|
+
id="run-123",
|
|
27
|
+
status=RunStatus.RUNNING,
|
|
28
|
+
started_at=started_at,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
d = run.to_dict()
|
|
32
|
+
|
|
33
|
+
assert d["id"] == "run-123"
|
|
34
|
+
assert d["status"] == "running"
|
|
35
|
+
assert d["started_at"] == "2000-01-01T00:00:00+00:00"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_from_dict():
|
|
39
|
+
d = {
|
|
40
|
+
"id": "run-123",
|
|
41
|
+
"status": "running",
|
|
42
|
+
"started_at": "2000-01-01T00:00:00+00:00",
|
|
43
|
+
"name": None,
|
|
44
|
+
"run_type": None,
|
|
45
|
+
"ended_at": None,
|
|
46
|
+
"params": {},
|
|
47
|
+
"metrics": {},
|
|
48
|
+
"tags": {},
|
|
49
|
+
"artifacts": [],
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
run = Run.from_dict(d)
|
|
53
|
+
|
|
54
|
+
assert run.started_at == datetime(2000, 1, 1, 0, 0, tzinfo=UTC)
|
|
55
|
+
assert run.status == RunStatus.RUNNING
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_serialization_round_trip():
|
|
59
|
+
started_at = datetime(2000, 1, 1, 0, 0, tzinfo=UTC)
|
|
60
|
+
|
|
61
|
+
before = Run(
|
|
62
|
+
id="run-123",
|
|
63
|
+
status=RunStatus.RUNNING,
|
|
64
|
+
started_at=started_at,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
after = Run.from_dict(before.to_dict())
|
|
68
|
+
|
|
69
|
+
assert before == after
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from datetime import datetime, UTC
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from mllogs.run import Run, RunStatus
|
|
6
|
+
from mllogs.storage import LocalFileStore
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_persistence_round_trip(tmp_path: Path) -> None:
|
|
10
|
+
storage = LocalFileStore(root_dir=tmp_path)
|
|
11
|
+
|
|
12
|
+
run = Run(
|
|
13
|
+
id="run123",
|
|
14
|
+
status=RunStatus.RUNNING,
|
|
15
|
+
started_at=datetime.now(UTC),
|
|
16
|
+
)
|
|
17
|
+
run_path = storage._runs_dir / f"{run.id}.json"
|
|
18
|
+
|
|
19
|
+
# save
|
|
20
|
+
storage.save_run(run)
|
|
21
|
+
assert run_path.is_file()
|
|
22
|
+
|
|
23
|
+
# load
|
|
24
|
+
run_after = storage.load_run(run.id)
|
|
25
|
+
assert run == run_after
|
|
26
|
+
|
|
27
|
+
# delete
|
|
28
|
+
storage.delete_run(run.id)
|
|
29
|
+
assert not run_path.exists()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_list_runs(tmp_path: Path) -> None:
|
|
33
|
+
storage = LocalFileStore(root_dir=tmp_path)
|
|
34
|
+
|
|
35
|
+
for run_id in ["001", "002", "003"]:
|
|
36
|
+
storage.save_run(Run(
|
|
37
|
+
id=run_id,
|
|
38
|
+
status=RunStatus.RUNNING,
|
|
39
|
+
started_at=datetime.now(UTC),
|
|
40
|
+
))
|
|
41
|
+
|
|
42
|
+
runs = storage.list_runs()
|
|
43
|
+
|
|
44
|
+
assert [run.id for run in runs] == ["003", "002", "001"]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_list_runs_with_limit(tmp_path: Path) -> None:
|
|
48
|
+
storage = LocalFileStore(root_dir=tmp_path)
|
|
49
|
+
|
|
50
|
+
for run_id in ["001", "002", "003"]:
|
|
51
|
+
storage.save_run(Run(
|
|
52
|
+
id=run_id,
|
|
53
|
+
status=RunStatus.RUNNING,
|
|
54
|
+
started_at=datetime.now(UTC),
|
|
55
|
+
))
|
|
56
|
+
|
|
57
|
+
runs = storage.list_runs(limit=2)
|
|
58
|
+
|
|
59
|
+
assert [run.id for run in runs] == ["003", "002"]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_runs_with_invalid_limit(tmp_path: Path) -> None:
|
|
63
|
+
storage = LocalFileStore(root_dir=tmp_path)
|
|
64
|
+
|
|
65
|
+
with pytest.raises(ValueError):
|
|
66
|
+
storage.list_runs(limit=0)
|