Skip to content

Commit

Permalink
Fix step param in dvclive.log method (#130)
Browse files Browse the repository at this point in the history
* Modify conditional expression checking if step param value can be use as step.

Now only None value is prohibited.

* Expand custom steps test cases.

Crucial thing is modify internal state before perform log call with 0 as step value.

* Revert previous commit and create separate test for logging when reset step to 0 scenario.
  • Loading branch information
naibatsuteki committed Aug 2, 2021
1 parent b24fda7 commit 06b7660
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dvclive/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def log(self, name: str, val: Union[int, float], step: int = None):
)
)

if step:
if step is not None:
self._step = step

metric_history_path = os.path.join(self.history_path, name + ".tsv")
Expand Down
11 changes: 11 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ def test_custom_steps(tmp_dir):
assert read_history("logs", "m") == (steps, metrics)


def test_log_reset_with_step_0(tmp_dir):
for i in range(3):
dvclive.log("train_m", 1, step=i)

for i in range(3):
dvclive.log("val_m", 1, step=i)

assert read_history("dvclive", "train_m") == ([0, 1, 2], [1, 1, 1])
assert read_history("dvclive", "val_m") == ([0, 1, 2], [1, 1, 1])


@pytest.mark.parametrize("html", [True, False])
@pytest.mark.parametrize("summary", [True, False])
def test_init_from_env(tmp_dir, summary, html, monkeypatch):
Expand Down

0 comments on commit 06b7660

Please sign in to comment.