mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
exp: add support for --no-hydra flag (#10866)
This commit is contained in:
@@ -26,8 +26,9 @@ def test_modify_params(params_repo, dvc, changes, expected):
|
||||
("conf", "bar"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("no_hydra", [True, False])
|
||||
def test_hydra_compose_and_dump(
|
||||
tmp_dir, params_repo, dvc, hydra_enabled, config_dir, config_name
|
||||
tmp_dir, params_repo, dvc, hydra_enabled, config_dir, config_name, no_hydra
|
||||
):
|
||||
hydra_setup(
|
||||
tmp_dir,
|
||||
@@ -50,14 +51,14 @@ def test_hydra_compose_and_dump(
|
||||
if config_name is not None:
|
||||
conf["hydra"]["config_name"] = config_name
|
||||
|
||||
dvc.experiments.run()
|
||||
dvc.experiments.run(no_hydra=no_hydra)
|
||||
|
||||
if hydra_enabled:
|
||||
if hydra_enabled and not no_hydra:
|
||||
assert (tmp_dir / "params.yaml").parse() == {
|
||||
"db": {"driver": "mysql", "user": "omry", "pass": "secret"},
|
||||
}
|
||||
|
||||
dvc.experiments.run(params=["db=postgresql"])
|
||||
dvc.experiments.run(params=["db=postgresql"], no_hydra=no_hydra)
|
||||
assert (tmp_dir / "params.yaml").parse() == {
|
||||
"db": {
|
||||
"driver": "postgresql",
|
||||
@@ -117,6 +118,7 @@ def test_hydra_sweep(
|
||||
targets=None,
|
||||
copy_paths=None,
|
||||
message=None,
|
||||
no_hydra=False,
|
||||
)
|
||||
|
||||
|
||||
@@ -137,3 +139,76 @@ def test_hydra_sweep_prefix_name(tmp_dir, params_repo, dvc):
|
||||
exp_names = [entry.name for entry in dvc.experiments.celery_queue.iter_queued()]
|
||||
for name, expected in zip(exp_names, expected_names):
|
||||
assert name == expected
|
||||
|
||||
|
||||
def test_mixing_no_hydra_and_params_flags(tmp_dir, params_repo, dvc):
|
||||
# Passing no_hydra should not prevent user from
|
||||
# using --set-param on unmodified params.yaml
|
||||
hydra_setup(
|
||||
tmp_dir,
|
||||
config_dir="conf",
|
||||
config_name="config",
|
||||
)
|
||||
|
||||
with dvc.config.edit() as conf:
|
||||
conf["hydra"]["enabled"] = True
|
||||
conf["hydra"]["config_dir"] = "conf"
|
||||
conf["hydra"]["config_name"] = "config"
|
||||
|
||||
dvc.experiments.run(no_hydra=True, params=["goo.bag=10.0"])
|
||||
|
||||
assert (tmp_dir / "params.yaml").parse() == {
|
||||
"foo": [{"bar": 1}, {"baz": 2}],
|
||||
"goo": {"bag": 10.0},
|
||||
"lorem": False,
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hydra_enabled,overrides,expected",
|
||||
[
|
||||
(
|
||||
True,
|
||||
["db=mysql,postgresql"],
|
||||
[
|
||||
{"params.yaml": ["db=mysql"]},
|
||||
{"params.yaml": ["db=postgresql"]},
|
||||
],
|
||||
),
|
||||
(
|
||||
False,
|
||||
["foo=bar,baz"],
|
||||
[{"params.yaml": ["foo=bar"]}, {"params.yaml": ["foo=baz"]}],
|
||||
),
|
||||
(
|
||||
False,
|
||||
[],
|
||||
[{}],
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("no_hydra", [True, False])
|
||||
def test_mixing_no_hydra_and_sweeps(
|
||||
tmp_dir, params_repo, dvc, mocker, hydra_enabled, overrides, expected, no_hydra
|
||||
):
|
||||
# Passing no_hydra should not prevent user from
|
||||
# queuing sweeps with --set-param and --queue
|
||||
patched = mocker.patch.object(dvc.experiments, "queue_one")
|
||||
|
||||
if hydra_enabled:
|
||||
hydra_setup(tmp_dir, config_dir="conf", config_name="config")
|
||||
with dvc.config.edit() as conf:
|
||||
conf["hydra"]["enabled"] = True
|
||||
|
||||
dvc.experiments.run(params=overrides, queue=True, no_hydra=no_hydra)
|
||||
|
||||
assert patched.call_count == len(expected)
|
||||
for e in expected:
|
||||
patched.assert_any_call(
|
||||
mocker.ANY,
|
||||
params=e,
|
||||
targets=None,
|
||||
copy_paths=None,
|
||||
message=None,
|
||||
no_hydra=no_hydra,
|
||||
)
|
||||
|
||||
@@ -130,6 +130,7 @@ def test_experiments_run(dvc, scm, mocker):
|
||||
"tmp_dir": False,
|
||||
"copy_paths": [],
|
||||
"message": None,
|
||||
"no_hydra": False,
|
||||
}
|
||||
default_arguments.update(repro_arguments)
|
||||
|
||||
@@ -151,6 +152,7 @@ def test_experiments_run_message(dvc, scm, mocker, flag):
|
||||
"tmp_dir": False,
|
||||
"copy_paths": [],
|
||||
"message": "mymessage",
|
||||
"no_hydra": False,
|
||||
}
|
||||
default_arguments.update(repro_arguments)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user