Skip to content

Commit 0152331

Browse files
universuenabidlabs
andauthored
bugfix for issue #125 (#126)
* bugfix * changes * added test --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
1 parent 925d519 commit 0152331

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

Binary file not shown.

tests/e2e/test_basic_logging.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,21 @@ def test_basic_logging(temp_db):
1818
assert results[1]["step"] == 1
1919
assert "timestamp" in results[0]
2020
assert "timestamp" in results[1]
21+
22+
23+
def test_basic_logging_with_step(temp_db):
24+
trackio.init(project="test_project", name="test_run")
25+
trackio.log(metrics={"loss": 0.1}, step=0)
26+
trackio.log(metrics={"loss": 0.2, "acc": 0.9}, step=2)
27+
trackio.finish()
28+
29+
results = SQLiteStorage.get_metrics(project="test_project", run="test_run")
30+
assert len(results) == 2
31+
assert results[0]["loss"] == 0.1
32+
assert results[0]["step"] == 0
33+
34+
assert results[1]["loss"] == 0.2
35+
assert results[1]["acc"] == 0.9
36+
assert results[1]["step"] == 2
37+
assert "timestamp" in results[0]
38+
assert "timestamp" in results[1]

trackio/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ def log(metrics: dict, step: int | None = None) -> None:
129129
"""
130130
run = context_vars.current_run.get()
131131
if run is None:
132-
raise RuntimeError("Call trackio.init() before log().")
133-
run.log(metrics)
132+
raise RuntimeError("Call trackio.init() before trackio.log().")
133+
run.log(
134+
metrics=metrics,
135+
step=step,
136+
)
134137

135138

136139
def finish():
@@ -139,7 +142,7 @@ def finish():
139142
"""
140143
run = context_vars.current_run.get()
141144
if run is None:
142-
raise RuntimeError("Call trackio.init() before finish().")
145+
raise RuntimeError("Call trackio.init() before trackio.finish().")
143146
run.finish()
144147

145148

trackio/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.2
1+
0.2.3

0 commit comments

Comments
 (0)