Skip to content

dvc run -m/-M: inconsistent behavior with dirs #3930

@nik123

Description

@nik123

dvc run with -M flag doesn't accept directories as metrics whereas dvc run with -m flag does. This behavior should be unified.

DVC version:

  • 0.94 (snap package)

Additional Information :

Steps to reproduce

  1. Initialize git and dvc

  2. Create evaluate.py:

import argparse
import os
import json

parser = argparse.ArgumentParser()
parser.add_argument("--metrics_dir", required=True)
args = parser.parse_args()
metrics_dir = args.metrics_dir

if not os.path.exists(metrics_dir):
    os.makedirs(metrics_dir)

with open(os.path.join(metrics_dir, "metrics1.json"), "w") as f:
    json.dump({"acc": 1.0}, f)

with open(os.path.join(metrics_dir, "metric2.json"), "w") as f:
    json.dump({"acc": 0.5}, f)
  1. Create new stage with directory as cached metrics output:
$ dvc run -f metrics_cached.dvc -d evaluate.py -m metrics_cached  python3 evaluate.py --metrics_dir metrics_cached
Running command:
        python3 evaluate.py --metrics_dir metrics_cached

To track the changes with git, run:

        git add metrics_cached.dvc .gitignore
  1. Create new stage with directory as not cached metrics output:
$ dvc run -f metrics_not_cached.dvc -d evaluate.py -M metrics_not_cached  python3 evaluate.py --metrics_dir metrics_not_cached
Running command:
        python3 evaluate.py --metrics_dir metrics_not_cached
ERROR: failed to run command - directory 'metrics_not_cached' cannot be used as metrics.

Both commands should either accept directories as metrics either discard them

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDid we break something?p1-importantImportant, aka current backlog of things to do

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions